Python – WinPython and OpenCV

WinPython and OpenCV… here is a solution to the problem.

WinPython and OpenCV

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

pip install opencv-python==3.4.0.12

When I run the following code, I get an error:

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

example

What am I doing wrong?

Solution

Seems to be a legitimate function result. As you can see, from the The documentation VideoCapture::read function returns retval and an image in case an image is returned. Obviously, the “False” value of the ret variable in the code means that there is no image.

Edit:

I

looked at the docs and here’s what I found :

“If no frames are captured (the camera is disconnected, or there are no more frames in the video file), the method returns false and the function returns a NULL pointer.”

Related Problems and Solutions