Canny Edge Detector in Videos

cvCanny Implements the Canny algorithm for edge detection.

void cvCanny(const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture size=3 );

Parameters of functions are as :

edges Single-channel image to store the edges found by the function.
threshold1 The first threshold.
threshold2 The second threshold.
aperture size Aperture parameter for the Sobel operator.

The function finds the edges on the input image image and marks them in the output image edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking, the largest value is used to find the initial segments of strong edges.

Example

#include <cv.h>
#include <highgui.h>

using namespace std;
using namespace cv;

int main(int, char**)
{
	cvNamedWindow("Edges", CV_WINDOW_AUTOSIZE); 
	CvCapture* capture = cvCreateFileCapture("Megamind.avi");
	IplImage* out;
	IplImage* gray_out;
	IplImage* canny_out;

	IplImage* frame;
	while(1) {
		frame = cvQueryFrame( capture );
		if( !frame ) break;

		out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 3 );
		gray_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
		canny_out = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
		cvSmooth( frame, out, CV_GAUSSIAN, 3, 3 );
		// Converts Image from RGB Gray
		cvCvtColor(out , gray_out, CV_RGB2GRAY);
		cvCanny( gray_out, canny_out, 10, 110, 3 );

		cvShowImage( "Edge", canny_out );
		char c = cvWaitKey(33);
		if( c == 27 ) break;
	}
	cvReleaseCapture( &capture );
	cvDestroyWindow( "Edge" );
	return 0;
}