Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: black image captured from usb camera

Tags:

opencv

camera

usb

I am trying to capture an image frame from a USB camera using opencv. However I am always getting a black frame. I have read many posts with this issue and tried all the suggestions but nothing worked for me.

I started using the code discussed here: http://opencv-users.1802565.n2.nabble.com/Using-USB-Camera-td6786148.html

I have tried including the method cvWaitKey(1000) after many 'critical' sentences. As you can see the waiting value is very high (1000).

I have also tried to save the image frame and, equally, it is a black image.

I am using the following system:

  • OpenCV 2.2.0
  • Windows 7, 32 bits
  • Visual Studio 2010 (C++)
  • a board usb camera (which I do not know the manufacturer)

The usb camera works well with AMCAP.EXE 1.00.

Could it be because of the camera drivers being used by Windows? Could I change to other drivers that work better for OpenCV 2.2.0?

Thanks

like image 428
jaiserpe Avatar asked Feb 18 '14 09:02

jaiserpe


1 Answers

Ok. As I promised to your request in the comments, and sorry to keep you waiting, really been busy. Barely had time to post this answer too. But here it is:

This is me simulating that opencv is capturing black image. On the output window, which I had asked you in the comments about what it says, shows that there is an error.

enter image description here

After investigating, I realised that it is due to the camera's available format: enter image description here

Of cuz, this is a lousier camera. If you have a better camera like the logitech one, you can see that the format available is so much more. enter image description here

There are lots of methods, you can try some thing like

capture.set(CV_CAP_PROP_FRAME_WIDTH , 640); 
capture.set(CV_CAP_PROP_FRAME_HEIGHT , 480); 
capture.set (CV_CAP_PROP_FOURCC, CV_FOURCC('B', 'G', 'R', '3'));//diff from mine, using as example

then the webcam will be able to snap. This webcam is bit faulty, hence the image snapped is not that beautiful.enter image description here

Hope this is your problem. but it may not be the case too. I like debugging problems, but I can't put down all the possible causes that this happen for you as I am really busy, as you asked for an example, this is one of them. Cheers. If you could tell me what you output window error says, I probably can help more.

EDIT(to answer more in your comments):

Ok, I want you to try a few things:

1)First, instead of using cvQueryFrame, or similar capturing methods, I want you to try use that webcam to capture a video instead. Wait up to maybe say 10 secs to see if it's successful. Reason being, some cameras(lower quality ones) take quite a while to warm up and the first few frames they capture may be an empty one.

2) If the step one doesn't work, try typing

cout << cv::getBuildInformation() << endl;

and paste the results for media I/O and Video I/O? I want to see the results. I would suspect your library dependencies too, but since you said it works with a logitech camera, I doubt that's the case. Of course, there's always a chance it's due to that the camera is not compatible to OpenCV. Does the camera have any brands by the way?

3) Alternatively, just search for usb drivers online and install it, I had a friend who did this for a similar problem, but not sure the process of that.

like image 151
rockinfresh Avatar answered Sep 28 '22 07:09

rockinfresh