I'm trying to connect to my laptop camera as live streaming but it doesn't work. cv2.imshow() provokes an error. I'm using Python 3.6 and OpenCV 4.1.0 on windows 10.
I've tried to rebuild the library GTK+ 2.x but nothing changed.
import cv2
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
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()
Here's the error:
Traceback (most recent call last):
File "C:/Users/hiba/PycharmProjects/Python for CV/12-Connecting_to_Camera.py", line 21, in <module>
cv2.imshow('frame', gray)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:627: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
[ WARN:0] terminating async callback
Process finished with exit code 1