04 邊緣(Canny)

04 邊緣(Canny)

screen-shot-2016-11-14-at-12-58-39-am

找邊緣(Canny)

Canny邊緣檢測,在抗雜訊和精確定位間有不錯的效果,OpenCV提供Canny()函式,來進行Canny邊緣檢測,以下為流程,OpenCV已將步驟封裝好,使用時只要呼叫Canny()即可。

#include <iostream>
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>

using namespace cv ;
using namespace std ;

int main() {
    cv::Mat src = cv::imread("/Users/powenko/Desktop/1.png");
    if(src.data!=NULL){
        
        
        GaussianBlur(src, src, Size(3,3), 0, 0);
        Mat dst1, dst2;
        Canny(src, dst1, 50, 150, 3);
        threshold(dst1, dst2, 128, 255, THRESH_BINARY_INV);  //反轉影像
        cv::namedWindow("Image") ;
        cv::imshow("Image", src) ;
        cv::imshow("Powenko.com  result 1", dst1) ;
        cv::imshow("Powenko.com  result 2", dst2) ;
        cv::waitKey() ;
    }
    return 0;
}

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)