Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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); }

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>

#include<stdio.h>
#include<cv.h>
#include<highgui.h>
//Defining Method
IplImage* doCanny(IplImage,double,double,double);
IplImage doCanny(IplImage*,double,double,double);
IplImage* doPyrDown(IplImage*,int);
int main(){

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); }

click to hide/show revision 3
make it more visible

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); }

}