cvCaptureFromCAM() returns 0.
Hi, I have copied the following link program.
https://www.youtube.com/watch?v=2i2bt-YSlYQ&feature=youtube_gdata_player
It is supposed to at least display on a window what the webcam sees. Unfortunately, it does not,the webcam does not even work and the message "Error: capture is NULL" on the console. as it is supposed to do in the program when cvCaptureFromCAM returns 0 Bellow is the full program.
// Tracker_1.cpp
include<opencv cvaux.h="">
include<opencv highgui.h="">
include<opencv cxcore.h="">
include<stdio.h>
include<stdlib.h>
/////////////////////////////: int main(int argc, char* argv[]) { CvSize size640x480 = cvSize(640, 480); // use a 640 x 480 size for all windows =, also make sure your webcam is set to 640x480 !!
CvCapture* p_capWebcam; // we will assign our web cam videostream to this later . . .
IplImage* p_imgOriginal; // pointer to an image structure, this will be the input image from webcam.
IplImage* p_imgProcessed; // pointer to an image structure, this will be the processed image.
/* IPL is short for Intel Image Processing Librart, this is the structure used in OpenCV.1.x to work with images */
CvMemStorage* p_strStorage; // Necessary storage variable to pass into cvHoughCircles()
CvSeq* p_seqCircles; // Pointer to an OpenCV sequence, will be returned by cvHoughCircles() and will contain all circles.
// Call cvGetSeqElem(p_seqCircles, i) will return a 3 element array of the ith circle (see next variable).
float* p_fltXYRadius; // Pointer to a 3 element array floats.
// [0] => x position of detected object.
// [1] => y position of detected object.
// [2] => Radius of detected object.
int i; // Loop counter.
char charCheckForEscKey; // Char for checking key press (Esc exits program).
p_capWebcam = cvCaptureFromCAM(0); // 0 => use lst webcam, may have to change to a different number if you have multiple cameras.
if(p_capWebcam == NULL) // If capture was not successful . . .
{
printf("Error: capture is NULL \n"); // Error message to standard out . . .
getchar(); // getchar() to pause for user see message.
return(-1); // Exit program.
}
// Declare 2 windows.
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE); // Original image from webcam.
cvNamedWindow("Processed", CV_WINDOW_AUTOSIZE); // The processed image we will use dor detectiing circles.
p_imgProcessed = cvCreateImage(size640x480, // 640 x 480 pixels (CvSize struct from earlier)
IPL_DEPTH_8U, // 8-bit color depth.
1); // 1 channel (grayscale), if this was a color image, use 3
while(1) // For each frame . . .
{
p_imgOriginal = cvQueryFrame(p_capWebcam); // Get fram from webcam.
if(p_imgOriginal == NULL) // If frame was not captures succesfully . . .
{
printf("Error: frame is NULL \n"); // Error message to std out.
getchar();
break;
}
cvInRangeS(p_imgOriginal, // function input.
CV_RGB(175, 0, 0), // min filtering value (if color is greater thar or equal to this)
CV_RGB(256, 100, 100), // max filtering value (if color is less than this)
p_imgProcessed); // function output.
// Smooth the processed image, this will make it easier for the next function to pick out the circles.
cvSmooth(p_imgProcessed, // Function input.
p_imgProcessed, // Function output.
CV_GAUSSIAN, // Use Gaussian filter (average nearby pixels, with the closest pixels weighted more).
9, // Smoothing filter window width.
9); // Smoothing filter window height.
// Fill sequential structure with all circles in processed image.
p_seqCircles = cvHoughCircles(p_imgProcessed, // Input image, nothe that this has to be ...