Using Python & OpenCV to control WebCam, black window: problem and troubleshooting in a single code line


I recently involved in a project to capture images with webcam. I soon found that OpenCV seems to be the best solutions to program in Python.

For how to install Python and OpenCV, refer to the link here. However, I found that a black window pops and the captured images does not show up.

opencv

I googled, and a number of solutions do exist, some are funny, but do not work. Finally I found that editing a single line will troubleshoot the problem:

captured

The solution is to “import cv2.cv”, instead of “import cv”, The code shown in http://luugiathuy.com/2011/02/setup-opencv-for-python/ then works like a charm.

opencv2

Cheers and happy coding

5 thoughts on “Using Python & OpenCV to control WebCam, black window: problem and troubleshooting in a single code line

  1. Ales

    i’m using Win 7 64 bit with py 2.7 and open cv2 …
    But the image from webcam is alway black!

    i’m becoming crazy…

  2. Pingback: » Python:Displaying a webcam feed using OpenCV and Python

  3. Pingback: Displaying a webcam feed using OpenCV and Python - iZZiSwift

Leave a comment