3

I use WinPython to write my python programs. I need to solve the task of detecting faces in a video stream. I have installed opencv-python to WinPython using this command:

pip install opencv-python==3.4.0.12

When I run the following code, I get a False:

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
ret, img = cap.read()
print(ret)

example

What I am doing wrong?

1 Answer 1

3

Seems like legit function result. As you can see, from documentation VideoCapture::read function returns retval and image, in case there was image to return. Apparently, "False" value of the ret variable in your code means that there was no image.

Edit:

I looked up documentation and here's what i've found:

"If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer."

Sign up to request clarification or add additional context in comments.

4 Comments

Hi! This code only should to capture image from camera and it shouldn't detecting faces
Sorry, I've misread documentation. I've edited comment, so it will be more helpful.
I suggest, you try to run your code not with the device, but with video file(.avi, for example), to make sure that the code is working properly.
Thank you! I can read .mp4 file. I think it's my web cam error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.