OpenCV 2.2 + Webcam + Windows not working

Hey there…

it has been a while since my last post… but I’m here again, although I’ll not stay long =P. This will be a short post… another quick and dirty tip. I’ve been very busy and without the time to post something really substantial. However, I think this can be helpful, so…

These days I had a problem using my webcam with OpenCV 2.2 in Windows. Most of the time I use Linux and never had any problem like this, but last week I needed to use OpenCV 2.2 + Windows for a Computer Vision project and figured out that my webcam simply do not work in this configuration: when I try to create a capture object, a window opens requiring I select the device. However, it does not succeed, even if I select the device correctly.

Oddly, this does not occur with OpenCV 2.1 + Windows. Thus, I concluded it’s a bug in OpenCV 2.2, specifically in the highgui package. Apparently, this version of OpenCV is using a back-end for cameras different from DirectShow, despite OpenCV supports it and, as I know, this is the recommended way of accessing cameras in Windows.

A solution is to force OpenCV to use DirectShow, what can be done by defining the macros HAVE_VIDEOINPUT and HAVE_DSHOW during the building configuration. Just edit the flag CMAKE_C_COMPILER adding the proper options. For example, if you’re building OpenCV using Visual Studio, append “/DHAVE_DSHOW /DHAVE_VIDEOINPUT” to that flag.

Well, this worked for me… I hope it can be helpful to you =).

PS: As a matter of fact, this is a bug in the setup of the OpenCV building, not a bug in OpenCV itself.

Posted on June 5, 2011, in OpenCV and tagged , , , . Bookmark the permalink. 27 Comments.

  1. so what can we do solve this problem?

    • Rafael Barreto

      Hi, sorry the delay in the answer. I think it’s clear in the text. You have to rebuild OpenCV with the macros HAVE_VIDEOINPUT and HAVE_DSHOW defined.

  2. Can u please tell me the way to edit these macros in step by step manner

    • Right now I don’t have access to a Windows machine, so I can’t show pictures. Anyway, it’s not difficult. Follow the OpenCV install guide (http://opencv.willowgarage.com/wiki/InstallGuide). When configuring the build through CMake options, you’ll see the flag CMAKE_C_COMPILER. This stores the options passed to the C compiler. So, you can define the macros HAVE_VIDEOINPUT and HAVE_DSHOW here. How do you do this? It depends on your compiler. For Visual Studio this can be done adding “/DHAVE_DSHOW /DHAVE_VIDEOINPUT” to CMAKE_C_COMPILER flag. For MinGW, you must add “-DHAVE_DSHOW -DHAVE_VIDEOINPUT”. For any other compiler, you must figure out the correct syntax.

      I hope it helps…

  3. i cant find the CMAKE_C_COMPILER flag in the CMake options, what do i do to fix this??? And how exactly do i add macros to it afterwards??

  4. I feel one of your current ads caused my web browser to resize, you may well need to get that on your blacklist.

  5. Wanted to drop a remark and let you know your Rss feed is not functioning today. I tried adding it to my Yahoo reader account and got nothing.

  6. A cool post there mate . Thanks for the post .

  7. rather useful stuff, in general I imagine this is worthy of a book mark, thanks

  8. Whenever I at first left a comment I clicked on the Notify me any time new comments are added checkbox and now each and every time a comment is added I receive 4 messages with the identical comment.

  9. Have you considered adding several social bookmarking buttons to these blogs. At least for flickr.

  10. You need to really moderate the comments here

  11. How do you make your site look this cool!? Email me if you get the chance and share your wisdom. .

  12. You should really moderate the comments at this site

  13. Could you email me with some hints on how you made this blog site look this cool, Id appreciate it!

  14. You need to really control the responses on this website

  15. This blog has lots of extremely helpful info on it. Cheers for helping me!

  16. Can you message me with some pointers on how you made your site look this awesome , I would be appreciative!

  17. I have got 1 suggestion for your blog site. It looks like at this time there are a few cascading stylesheet issues while opening a selection of webpages inside google chrome and firefox. It is working okay in internet explorer. Perhaps you can double check that.

  18. Just to let you know your web site looks a little bit strange on Safari on my computer using Linux .

  19. This site has got some very helpful information on it. Thanks for helping me.

  20. It looks to me that this website doesnt download in a Motorola Droid. Are other people getting the exact same problem? I enjoy this website and dont want to have to skip it whenever Im gone from my computer.

  21. This is often a excellent site, could you be interested in working on an interview about just how you created it? If so e-mail me personally!

  22. Wanted to drop a comment and let you know your Feed isnt functioning today. I tried adding it to my Google reader account but got nothing.

  23. I tried looking at your website with my blackberry and the layout doesnt seem to be right. Might wanna check it out on WAP as well as it seems most mobile phone layouts are not working with your web page.

  24. Wow! This blog is amazing! How did you make it look this good !?

Leave a comment