Video capture in openCV 3.1 not working with python3

677 Views Asked by At

I have installed openCV 3.1.0 with python3.5 every thing seemed to work fine during installation however when I am trying to execute even the following simple program, it doesn't work. OpenCV doesn't detect the camera.

isOpened() function always returning false

I checked, and the webcam has the id 0, I also tried other values (1,2,-1) but none of them seems to work, it always shows false. I have gone through similar questions on stack overflow, but none of the solutions seems to work. I have also tried re-installing openCV multiple times, it doesn't help either.

Please help.

1

There are 1 best solutions below

1
On

You should change default camera to video to test. e.g.

import cv2
cap = cv2.VideoCapture(r'E:/test.mp4')
if cap.isOpened():
    print('OK')
else:
    print('error')

If the result is 'OK',then modify "cap = cv2.VideoCapture(r'E:/test.mp4')" to "cap = cv2.VideoCapture(0)",if the result is 'error',I think there is something wrong with your camera.