4.canny边缘检测

    xiaoxiao2025-06-15  10

    from:http://www.cnblogs.com/huhuuu/p/3538850.html

    代码:

    //#include "stdafx.h" #include "cv.h" #include "highgui.h" IplImage *g_pSrcImage, *g_pCannyImg; const char *pstrWindowsCannyTitle = "边缘检测图"; //cvCreateTrackbar的回调函数 void on_trackbar(int threshold) { //canny边缘检测 cvCanny(g_pSrcImage, g_pCannyImg, threshold, threshold * 3, 3); cvShowImage(pstrWindowsCannyTitle, g_pCannyImg); } int main() { const char *pstrImageName = "2.jpg"; const char *pstrWindowsSrcTitle = "原图"; const char *pstrWindowsToolBar = "滑动条"; //从文件中载入图像的灰度图CV_LOAD_IMAGE_GRAYSCALE - 灰度图 g_pSrcImage = cvLoadImage(pstrImageName, CV_LOAD_IMAGE_GRAYSCALE); g_pCannyImg = cvCreateImage(cvGetSize(g_pSrcImage), IPL_DEPTH_8U, 1); //创建窗口 cvNamedWindow(pstrWindowsSrcTitle, CV_WINDOW_AUTOSIZE); cvNamedWindow(pstrWindowsCannyTitle, CV_WINDOW_AUTOSIZE); //创建滑动条 int nThresholdEdge = 1; cvCreateTrackbar(pstrWindowsToolBar, pstrWindowsCannyTitle, &nThresholdEdge, 200, on_trackbar); //在指定窗口中显示图像 cvShowImage(pstrWindowsSrcTitle, g_pSrcImage); on_trackbar(1); //等待按键事件 cvWaitKey(); cvDestroyWindow(pstrWindowsSrcTitle); cvDestroyWindow(pstrWindowsCannyTitle); cvReleaseImage(&g_pSrcImage); cvReleaseImage(&g_pCannyImg); return 0; }

    运行结果:

    转载请注明原文地址: https://ju.6miu.com/read-1299972.html
    最新回复(0)