3

I am new to OpenCV and trying to capture video from my laptop camera using

VideoCapture cap(0); // open the video camera no. 0

I am following the tutorial capturing-images-videos

I tried VideoCapture cap(0); with different parameters (0,1,2) but its not working for me. Also I have checked device manager my cam is working fine (also with skype, it working). I am able to play video using other constructor of VideoCapture. Iam using Windows 7 (64-bit) and my laptop is HP ProBook 4530s. Also I am using OpenCV OpenCV2.4.5 Any help will be greatly appreciated.

Ali Kazmi
  • 1,460
  • 9
  • 22
  • 2
    This [question](http://stackoverflow.com/questions/4749498/cant-access-webcam-with-opencv) seems similar, have you tried the solution proposed there? – Adrien Descamps Jan 12 '15 at 19:33
  • 1
    Adrien's link seems like a good solution, otherwise try a different brand of webcam to see if the problem is in the camera or your software configuration. – diip_thomas Jan 13 '15 at 08:42
  • I am using Visual Studio; can you please guide me how to recompile opencv_highgui and change the "Preprocesser Definitions". I am not familiar with CMake and I used only solution files for rebuilding the libs – Ali Kazmi Jan 13 '15 at 17:48

1 Answers1

3

The code is correct, and I am able to create window to display image captured by camera. The problem was I was using Visual Studio in my VM now I am using it on Host OS (Windows 7). Can anyone please mention if there is any problem in accessing Camera in VM? thanks @Adrein and @diip for your time

Ali Kazmi
  • 1,460
  • 9
  • 22