Acquiring video from webcam problems. [closed]
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?
You use c++, but code c-style. Is there a special reason? http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture
Some other errors I see. Frame2 and frame are exactly the buffer you get from the camera. You are working on it and trying to manipulate it. Thats not a good idea in general. This probably wont help with the issue though.
no well is just a code i downloaded from the web to test the camera..
i actually found out that if i try to test video for Linux 2 (v4l2) in Multimedia system selector.. it fails..the problme maybe is here somewhere
Were you using CTRL-C to close the camera? This can cause problems, see this post for a workaround: http://lawlorcode.wordpress.com/2014/04/08/opencv-fix-for-v4l-vidioc_s_crop-error/