opencv實現邊緣提取方法總結__影像處理

來源:互聯網
上載者:User

分別用Canny運算元、sobel運算元和Laplace運算元實現邊緣提取,代碼如下:

// 邊緣提取.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <cv.h>#include <cxcore.h>#include <highgui.h>#include <cmath>using namespace std;using namespace cv;int main(int argc ,char ** argv){#if 0//canny運算元IplImage *src =cvLoadImage("E:\\picture\\lena.bmp");IplImage *gray=cvCreateImage(cvGetSize(src),IPL_DEPTH_8U,1);cvCvtColor(src,gray,CV_RGB2GRAY);IplImage * pCannyImg=cvCreateImage(cvGetSize(gray),IPL_DEPTH_8U,1);cvCanny(gray,pCannyImg,50,150,3);        //建立視窗        cvNamedWindow("src", 1);        cvNamedWindow("canny",1);        //顯示映像        cvShowImage( "src", src );        cvShowImage( "canny", pCannyImg );        cvWaitKey(0); //等待按鍵        //銷毀視窗        cvDestroyWindow( "src" );        cvDestroyWindow( "canny" );        //釋放映像        cvReleaseImage( &src );         cvReleaseImage( &pCannyImg );#endif#if 0//Sobel運算元Mat src=imread("e:\\picture\\lena.bmp");Mat dst_x,dst_y,dst;Sobel(src,dst_x,src.depth(),1,0);Sobel(src,dst_y,src.depth(),0,1);convertScaleAbs(dst_x, dst_x);  //使用線性變換轉換輸入數組元素成8位無符號整型        convertScaleAbs(dst_y, dst_y); addWeighted( dst_x, 0.5, dst_y, 0.5, 0, dst); imshow("dst",dst);imwrite("Sobel_lena.bmp",dst);namedWindow("src");imshow("src",src);waitKey(0);#endif#if 1//LapLace 拉普拉斯運算元Mat src=imread("e:\\picture\\lena.bmp");Mat dst;Laplacian(src,dst,src.depth(),3);convertScaleAbs(dst,dst);namedWindow("src");namedWindow("dst");imshow("src",src);imshow("dst",dst);waitKey(0);#endif    return 0;}

原圖lena.bmp


Canny運算元實現結果:


sobel運算元實現結果:


Laplace運算元實現結果:




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.