// cannyDetection.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
IplImage* doCanny(IplImage* in,double lowThresh,double highThresh,double aperture)
{
if(in->nChannels!=1) return 0;
IplImage* out=cvCreateImage(cvSize(in->width,in->height),IPL_DEPTH_8U,1);
cvCanny(in,out,lowThresh,highThresh,aperture);
return(out);
}
int _tmain(int argc, _TCHAR* argv[])
{
char* image="E:\\lenna.png";//图像名字注意更改
IplImage* in=cvLoadImage(image);
cvShowImage("Example6_in",in);
IplImage* out,* gray;//由于gray和in的内存空间不一样,所以需要单独重新分配
gray = cvCreateImage( cvSize( in->width,in->height ), in->depth, 1);
//把3通道图转化为单通道的灰度图
cvCvtColor(in, gray ,CV_BGR2GRAY);//把载入图像转换为灰度图
cvShowImage("Example6_gray",gray);
cvNamedWindow("Example6_in");
cvNamedWindow("Example6_gray");
cvNamedWindow("Example6_out");
out=doCanny(gray,0,255,3);
cvShowImage("Example6_out",out);
cvWaitKey(0);
cvReleaseImage(&in);
cvReleaseImage(&gray);
cvReleaseImage(&out);
cvDestroyWindow("Example6_in");
cvDestroyWindow("Example6_gray");
cvDestroyWindow("Example6_out");
return 0;
}
//
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
IplImage* doCanny(IplImage* in,double lowThresh,double highThresh,double aperture)
{
if(in->nChannels!=1) return 0;
IplImage* out=cvCreateImage(cvSize(in->width,in->height),IPL_DEPTH_8U,1);
cvCanny(in,out,lowThresh,highThresh,aperture);
return(out);
}
int _tmain(int argc, _TCHAR* argv[])
{
char* image="E:\\lenna.png";//图像名字注意更改
IplImage* in=cvLoadImage(image);
cvShowImage("Example6_in",in);
IplImage* out,* gray;//由于gray和in的内存空间不一样,所以需要单独重新分配
gray = cvCreateImage( cvSize( in->width,in->height ), in->depth, 1);
//把3通道图转化为单通道的灰度图
cvCvtColor(in, gray ,CV_BGR2GRAY);//把载入图像转换为灰度图
cvShowImage("Example6_gray",gray);
cvNamedWindow("Example6_in");
cvNamedWindow("Example6_gray");
cvNamedWindow("Example6_out");
out=doCanny(gray,0,255,3);
cvShowImage("Example6_out",out);
cvWaitKey(0);
cvReleaseImage(&in);
cvReleaseImage(&gray);
cvReleaseImage(&out);
cvDestroyWindow("Example6_in");
cvDestroyWindow("Example6_gray");
cvDestroyWindow("Example6_out");
return 0;
}