- #include <highgui.h>
- #include <cv.h>
- int main(int argc, char **argv)
- {
- IplImage *doCanny(IplImage*, double, double, double);
- CvCapture *capture;
- if (argc != 2)
- return -1;
- capture = cvCreateFileCapture(argv[1]);
- assert(capture != NULL);
- double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
- IplImage *frame;
- cvNamedWindow("before processed", CV_WINDOW_AUTOSIZE);
- cvNamedWindow("gray", CV_WINDOW_AUTOSIZE);
- cvNamedWindow("canny", CV_WINDOW_AUTOSIZE);
- while (1) {
- frame = cvQueryFrame(capture);
- if (!frame) break;
- IplImage *gray = cvCreateImage(cvGetSize(frame), frame->depth, 1);
- cvCvtColor(frame, gray, CV_BGR2GRAY);
- IplImage *canny = doCanny(gray, 10, 100, 3);
- cvShowImage("before processed", frame);
- cvShowImage("gray", gray);
- cvShowImage("canny", canny);
- char c = cvWaitKey(fps);
- if (c == 27) {
- cvReleaseImage(&gray);
- cvReleaseImage(&canny);
- break;
- }
- }
- cvReleaseCapture(&capture);
- cvReleaseImage(&frame);
- cvDestroyAllWindows();
- return 0;
- }
- IplImage *doCanny(
- IplImage *in,
- double lowThresh,
- double highThresh,
- double aperture
- )
- {
- if (in->nChannels != 1)
- return NULL; // Canny only handles gray scale images
- IplImage *out = cvCreateImage(
- cvSize(in->width, in->height),
- IPL_DEPTH_8U,
- 1
- );
- cvCanny(in, out, lowThresh, highThresh, aperture);
- return out;
- }
- //该片段来自于http://www.codesnippet.cn/detail/090520149500.html
来源: http://www.codesnippet.cn/detail/090520149500.html