1 | initial version |
first of all, you should no more use the venerable c-api in 2014.
opencv switched to a c++ api in 2010 already, and so should you.
you will get rid of the serious memleaks in your code above, also it will also be only half of it to look at and maintain:
#include <iostream>
using namespace std;
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
using namespace cv;
int main()
{
VideoCapture cap(0); // get 1st cam
if( ! cap.isOpened() )
{
cerr << "no capture." << endl;
return -1;
}
Mat frame;
if ( ! cap.read(frame) )
{
cerr << "no image." << endl;
return -1;
}
imshow("In_image",frame);
// Do smoothing
Mat blurred; // leave empty, the api will take care of the allocation.
blur(frame, blurred, Size(11,11));
imshow("Smooth_out_image",blurred);
// pyramid
Mat pyr;
pyrDown(frame,pyr);
imshow("Pyramid downsampled",pyr);
// Do Edge Detection
Mat gray, can;
cvtColor(frame, gray, CV_BGR2GRAY);
Canny(gray, can, 10, 100, 3);
imshow("CannyEdge_out_image", can);
waitKey();
return 0;
}