Ask Your Question

Tarhann's profile - activity

2018-12-01 19:02:24 -0600 received badge  Famous Question (source)
2017-09-13 03:02:08 -0600 received badge  Notable Question (source)
2017-08-18 21:31:36 -0600 received badge  Popular Question (source)
2017-02-26 13:05:16 -0600 received badge  Editor (source)
2017-02-26 13:01:45 -0600 asked a question cv2.VideoCapture() works on python 2 but not on 3, ubuntu 16.04, opencv v3.2.0

I got a OpenCV 3.2.0 on an Ubuntu 16.04. When this code is executed with Python 2.7.12 it works like a charm. In exactly the same code with Python 3.5.2, cv2.VideoCapture() returns FALSE.

import cv2

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release()
cv2.destroyAllWindows()

Most likely there is just a library or binding missing in the Python 3 environment. Also pip freeze and pip3 freeze return the same libs installed ... Could really need a hint.

Thanks in advance :)