newbie: lookin for process realtime camera capture image processing
Plz let me know the error in this code: Its not working when I capture image from camera but works when a still image from disk is taken
#include<stdio.h>
#include<cv.h>
#include<highgui.h>
//Defining Method
IplImage* doCanny(IplImage*,double,double,double);
IplImage* doPyrDown(IplImage*,int);
int main(){
// open next line if image is from the system
// IplImage* img=cvLoadImage("lena512color.tiff",0); // 1 for color 0 for gray scale
// open next 2 lines of code if image is live webcam
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); // 0 is i.d of camera connected to your system
IplImage* img = cvQueryFrame(capture); //Create image from capture
cvNamedWindow("In_image",CV_WINDOW_AUTOSIZE); // same as figure command in matlab
cvNamedWindow("Smooth_out_image",CV_WINDOW_AUTOSIZE);
cvNamedWindow("CannyEdge_in_image",CV_WINDOW_AUTOSIZE);
cvNamedWindow("CannyEdge_out_image",CV_WINDOW_AUTOSIZE);
//create a window to show input image
cvShowImage("In_image",img);
//create a image to hold the output image
IplImage* out = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
//Do smoothing
cvSmooth(img,out,CV_GAUSSIAN,11,11);
//show the smoothed output image
cvShowImage("Smooth_out_image",out);
// Do Edge Detection
out = doCanny(out,10,100,3);
//Display
cvShowImage("CannyEdge_out_image",out);
// Do Edge Detection
out = doCanny(img,10,100,3);
// Display
cvShowImage("CannyEdge_in_image",out);
// Downsample Image
out = doPyrDown(img,IPL_GAUSSIAN_5x5);
cvShowImage("Pyramid_Downsampled_by_2",out);
//Release allocated memory
cvReleaseCapture(&capture); //Release capture
cvReleaseImage(&out);
//clean up windows
cvWaitKey(0);
cvDestroyAllWindows();
}
//Canny Edge Detection Method
IplImage* doCanny(IplImage* in,double lowThresh,double highThresh,double aperture){
if(in->nChannels!=1)
return(0); // for gray scale image only
IplImage* out = cvCreateImage(CvSize(cvGetSize(in)),IPL_DEPTH_8U,1);
cvCanny(in,out,lowThresh,highThresh,aperture);
return(out);
}
// Pyramid image Down Method
IplImage* doPyrDown(IplImage* in,int filter=IPL_GAUSSIAN_5x5){
//Make Sure image size divisible by 2
assert(in->width%2 == 0 && in->height%2 == 0);
IplImage* out = cvCreateImage(cvSize(in->width/2,in->height/2),in->depth,in->nChannels);
cvPyrDown(in,out,filter);
return(out);
}
The c-code is outdated for several years now and should not be used anymore. Please check the c++-Version that uses cv::Mat.
Please avoid not-smart pointers and please avoid returning a pointer from a function, it very easily to get in undefined behaviour. You can also pass to C++.
(I know this is not an answer helping with your problem, but:) I would strongly recommend to use the new C++ interface - especially when you are a newby! The new Interface does not have IplImage and cvXYZ, but cv::XYZ !
Where is the variable CV_CAP_ANY defined? This is the number of the webcam. It can range from 0 to... Try with a value of 0, if it doesn't work, try with 1, etc.