requinard
requinard

Reputation: 971

OpenCV's video capture not returning an image

So I'm trying to get started with image detection in OpenCV. I'm programming in Python.

I started out with the face-detect example for openCV2. However, even though a camera device is opened, no images will be returned.

The offending code:

cam = cv2.VideoCapture(0)
print cam.isOpened()
while True:
    ret, img = cam.read()
    print img
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)

when used, the print statement will say that my camera is opened. However, when cam.read() is called it will return False, NoneType.

So obviously it won't be able to convert a non-existing image to grayscale. Does anyone have any pointers on how to do this?

I'm using my embedded webcam, hence the "0" for webcam.

Upvotes: 3

Views: 3868

Answers (1)

theangrylama
theangrylama

Reputation: 216

I faced the same issue.

Sometimes video/webcam driver is a problem and it returns invalid first few frames. Check the return value of the to handle the error condition. Also restart your kernel and it should work.

And may be due to some previous error conditions, your cap.release() was not called.

Upvotes: 0

Related Questions