Skip to content

Instantly share code, notes, and snippets.

@candycode
Created September 16, 2012 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candycode/3732772 to your computer and use it in GitHub Desktop.
Save candycode/3732772 to your computer and use it in GitHub Desktop.
Python - OpenCV: Grab frame from webcam
#if opencv was installed through home-brew on mac
#sys.path.append('/usr/local/lib/python2.7/site-packages')
import cv2
#open window "Window"
cam = cv2.VideoCapture(0)
while True:
img = cam.read()[1]
cv2.imshow("Window",img)
if cv2.waitKey(5) == 32:
break
@Zaniyar
Copy link

Zaniyar commented Aug 1, 2020

Traceback (most recent call last):
File "/Users/you/PycharmProjects/openCV/webcam.py", line 10, in
cv2.imshow("Window",img)
cv2.error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment