Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Acquiring video from webcam problems.

Hi , i am trying to acquire a video from my webcam, this is the code i am using

> #include <opencv2/objdetect/objdetect.hpp>
> #include <opencv2/highgui/highgui.hpp>
> #include <opencv2/imgproc/imgproc.hpp>
> #include <opencv2/core/core.hpp>
> #include <stdlib.h>
> #include <stdio.h>
> #include <iostream>
> #include <stdio.h>
> #include <iostream>
> 
> 
> using namespace std; using namespace
> cv;
> 
> char key;
> 
> 
> 
> 
> using namespace std;
> 
> int main() {
>       //Create window      namedWindow("Camera_output", 1);
>   CvCapture* capture =
> cvCaptureFromCAM(1);  //Capture using
> any camera connected to your system
> 
>   while(1){ //Create infinte loop for
> live streaming
> 
>         IplImage* frame = cvQueryFrame(capture); //Create image
> frames from capture
>         Mat frame2=frame;
>         cvtColor( frame2, frame2, CV_BGR2GRAY );
>         imshow("pepper_noise padded", frame2);
> 
>         key = cvWaitKey(10);     //Capture Keyboard stroke
>         if (char(key) == 27){
>             break;      //If you hit ESC key loop will break.
>         }
> 
>     }
>     cvReleaseCapture(&capture); //Release capture.
>     cvDestroyWindow("Camera_Output"); //Destroy Window
>     return 0; }

after the first iteration the camera works fine but i get this output:

> VIDIOC_QUERYMENU: Invalid argument
> VIDIOC_QUERYMENU: Invalid argument
> VIDIOC_QUERYMENU: Invalid argument

if then i try to compile it again it does not work and i get this error:

libv4l2: error turning on stream: Invalid argument
VIDIOC_STREAMON: Invalid argument

any idea? i also tried to use an usb cam but does not work either.. I am using a laptop with Nvidia optimus but u actually deleted the Nvidia Drivers, so i am using the intel graphic card, can this be a problem?

click to hide/show revision 2
retagged

updated 2014-02-24 04:17:23 -0600

berak gravatar image

Acquiring video from webcam problems.

Hi , i am trying to acquire a video from my webcam, this is the code i am using

> #include <opencv2/objdetect/objdetect.hpp>
> #include <opencv2/highgui/highgui.hpp>
> #include <opencv2/imgproc/imgproc.hpp>
> #include <opencv2/core/core.hpp>
> #include <stdlib.h>
> #include <stdio.h>
> #include <iostream>
> #include <stdio.h>
> #include <iostream>
> 
> 
> using namespace std; using namespace
> cv;
> 
> char key;
> 
> 
> 
> 
> using namespace std;
> 
> int main() {
>       //Create window      namedWindow("Camera_output", 1);
>   CvCapture* capture =
> cvCaptureFromCAM(1);  //Capture using
> any camera connected to your system
> 
>   while(1){ //Create infinte loop for
> live streaming
> 
>         IplImage* frame = cvQueryFrame(capture); //Create image
> frames from capture
>         Mat frame2=frame;
>         cvtColor( frame2, frame2, CV_BGR2GRAY );
>         imshow("pepper_noise padded", frame2);
> 
>         key = cvWaitKey(10);     //Capture Keyboard stroke
>         if (char(key) == 27){
>             break;      //If you hit ESC key loop will break.
>         }
> 
>     }
>     cvReleaseCapture(&capture); //Release capture.
>     cvDestroyWindow("Camera_Output"); //Destroy Window
>     return 0; }

after the first iteration the camera works fine but i get this output:

> VIDIOC_QUERYMENU: Invalid argument
> VIDIOC_QUERYMENU: Invalid argument
> VIDIOC_QUERYMENU: Invalid argument

if then i try to compile it again it does not work and i get this error:

libv4l2: error turning on stream: Invalid argument
VIDIOC_STREAMON: Invalid argument

any idea? i also tried to use an usb cam but does not work either.. I am using a laptop with Nvidia optimus but u actually deleted the Nvidia Drivers, so i am using the intel graphic card, can this be a problem?