Ask Your Question
0

cv2.VideoCapture() works on python 2 but not on 3, ubuntu 16.04, opencv v3.2.0

asked 2017-02-26 12:59:20 -0500

Tarhann gravatar image

updated 2017-02-26 13:05:16 -0500

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 :)

edit retag flag offensive close merge delete

Comments

Just tried and I don't have such problem (Ubuntu 16.04, OpenCV 3.2.0):

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cap = cv2.VideoCapture(0)
>>> cap.isOpened()
True

Are you sure your camera is not busy? Did you use GCC 5.4.0 to compile OpenCV?

mshabunin gravatar imagemshabunin ( 2017-02-27 07:33:37 -0500 )edit

Did you ever find a solution? I have the exact same issue @Tarhann

ovg gravatar imageovg ( 2017-10-27 06:43:29 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
-2

answered 2017-08-18 21:33:35 -0500

supra56 gravatar image

updated 2017-08-18 21:35:00 -0500

Change this:

cv2.imshow('frame', gray)

to

cv2.imshow('frame', frame)
edit flag offensive delete link more

Comments

no answer to question

berak gravatar imageberak ( 2017-08-19 01:00:00 -0500 )edit
Login/Signup to Answer

Question Tools

4 followers

Stats

Asked: 2017-02-26 12:59:20 -0500

Seen: 5,969 times

Last updated: Aug 18 '17