OpenCV: black image captured from usb camera

后端 未结 4 944
旧巷少年郎
旧巷少年郎 2021-01-12 16:04

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 sug

相关标签:
4条回答
  • 2021-01-12 16:35

    The first thing, I would suggest is, visit this link and check your camera is working or not

    http://www.youronlinemirror.com/

    if yes, then go through below link to get started with things, you ll also find a good opencv c++ code out there, the code which you are using is of opencv1 api's c code, I would rather encourage you to go for c++ than the old version of opencv.

    http://opencv-srf.blogspot.in/2011/09/capturing-images-videos.html

    if you want an answer for your code, then, its simple, as you are saying its giving a black screen, which happened in my case when i started things out with opencv, it isnt able to take the data from device, so, try this, it might work, as it did for me.

    add

    cvQueryFrame( capture ); 
    

    before

    IplImage* frame = cvQueryFrame( capture ); 
    
    0 讨论(0)
  • 2021-01-12 16:39

    I went through the same problem as yours. Then I just changed the version from 3.1.0 to 2.4.13, then my webcam works! No more black images. I guess the 3 version is not compatible with the vs15. Thinking you may have already solved the problem long ago. But just post to let others know if they happen to have the same issue.

    0 讨论(0)
  • 2021-01-12 16:42

    Even I faced the same black screen problem while running OpenCV-related programs. So instead of using USB cam I used mobile camera which worked perfectly fine. Use Google apps such as DroidCam (install DroidCam on mobile as well as on laptop/PC) to connect your mobile camera to laptop through Wi-Fi.

    0 讨论(0)
  • 2021-01-12 16:47

    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.

    0 讨论(0)
提交回复
热议问题