使用的关键函数:
void cvCanny(const CvArr* img,CvArr* edges,double lowthreshold,double highthreshold,int apertureSize=3);
需要注意的是输入图像必须是灰度图像
放上实验代码:
#include
#include
#include
#include
using namespace cv;
IplImage *img = cvLoadImage("lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
IplImage *dst = cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels);
void on_track(int threshold)
{
cvCanny(img,dst,threshold,threshold*3);
cvShowImage("lena",dst);
}
int main()
{
int nthreshold = 1;
cvNamedWindow("lena");
cvNamedWindow("src");
cvCreateTrackbar("aaa","lena",&nthreshold,100,on_track);
cvShowImage("src",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&dst);
cvDestroyAllWindows();
}