(1) 从视频文件读入数据;
(2) 将读入数据转换为灰度图;
(3) 做Canny边缘检测。
将三个过程的处理结果显示到不同的窗口中,每个窗口根据其内容合理命名
#include <cv.h>
#include <highgui.h>
int main()
{
cvNamedWindow("Video", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Gray", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Canny", CV_WINDOW_AUTOSIZE);
CvCapture *capture = cvCreateFileCapture("D:\\OpenCV_Test.avi");
IplImage *frame;
IplImage *frame_gray;
IplImage *frame_canny;
frame = cvQueryFrame(capture);
frame_gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
frame_canny = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
while(1)
{
if(!frame)
{
break;
}
cvConvertImage(frame, frame_gray, 1);
cvCanny(frame_gray, frame_canny, 10, 100, 3);
cvShowImage("Video", frame);
cvShowImage("Gray", frame_gray);
cvShowImage("Canny", frame_canny);
char c = cvWaitKey(33);
if (c == 27)
{
break;
}
frame = cvQueryFrame(capture);
}
cvReleaseCapture(&capture);
cvDestroyAllWindows();
return 0;
}