Unable to capture Video from Laptop Webcam using OpenCV

642 Views Asked by At

I wrote some code to generate a live feed from my laptop webcam. I'm using the openCV library for Python 3.7 with Pycharm.

This is my code:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while True:
    #capture frame by frame
    ret, img = cap.read()
#    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('test', img)

cv2.waitKey(0) & 0xFF
cv2.destroyAllWindows()
cap.release()

This is the error message that I got:

Traceback (most recent call last): File "D:/Python Programs/OpenCV/VideoCapture.py", line 10, in cv2.imshow('test', img) 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

0

There are 0 best solutions below