Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.VideoCapture() works on python 2 but nor 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 :)

cv2.VideoCapture() works on python 2 but nor 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 :)