Ask Your Question
0

cvCaptureFromCAM() returns 0.

asked 2013-11-25 09:01:26 -0600

cedric100 gravatar image

updated 2013-11-25 09:10:15 -0600

berak gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-11-25 13:31:41 -0600

Peter Borkuti gravatar image

updated 2013-11-25 14:10:30 -0600

Hi, (I assume, that you are on Windows)

I should tell you that I had some issues on windows with OpenCV until I compile OpenCV with a similar tutorial like this:

http://nenadbulatovic.blogspot.hu/2013/07/configuring-opencv-245-eclipse-cdt-juno.html

So I suggest you to build OpenCV on windows first, then try the samples, then write your own first simple program.

edit flag offensive delete link more

Comments

Hi, Thank you for the response, and sorry for the late reply. Yes, the webcam works without OpenCV. I can use it on Skype. But, now, the problem is fixed. I run it on Ubuntu now, and from the terminal. It works just fine.

cedric100 gravatar imagecedric100 ( 2014-02-22 11:05:44 -0600 )edit
0

answered 2013-11-27 15:36:21 -0600

cedric100 gravatar image

updated 2013-11-27 16:07:41 -0600

Thank you for the answers.

I just tried with the simple program you gave me. The same problem occurs: Unhandled exception at 0x01122a3b in Tracker_1.exe: 0xC0000096: Privileged instruction.

They ask me to break or continue.

I can make video calls with my included webcam through Skype if that is the question of if I tried it with other programs.

I am thinking of learning to program on the terminal, so that that problem would be more easily controlled and at list, I would know exactely what is going on.. Do you think it is a good idea? But I still do not give up using Visual C++.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-25 09:01:26 -0600

Seen: 7,904 times

Last updated: Nov 27 '13