Displaying webcam feed using opencv and python
Posted
by Mitch
on Stack Overflow
See other posts from Stack Overflow
or by Mitch
Published on 2010-04-08T15:30:14Z
Indexed on
2010/04/08
15:33 UTC
Read the original article
Hit count: 446
Hi
ive been trying to create a simple program with python which utilises opencv to get a video feed from my webcam and display it on the screen. I know im partly there because the window is created and the light on my webcam flicks on, but it just doesnt seem to show anything in the window. hopefully someone can explain what im doing wrong.
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)
def repeat():
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
while True:
repeat()
on an unrelated note, i have noticed that my webcam sometimes changes its index number in cv.CaptureFromCAM and sometimes i need to put in 0, 1 or 2 even though i only have one camera connected and i havnt unplugged it (i know because the light doesnt come on unless i change the index). is there a way to get python to determine the correct index?
thanks
Mitch
© Stack Overflow or respective owner