with following code:
import cv cv.namedwindow("w1", cv.cv_window_autosize) camera_index = 0 capture = cv.capturefromcam(camera_index) def repeat(): global capture #declare globals since assigning them global camera_index frame = cv.queryframe(capture) cv.showimage("w1", frame) c = highgui.cvwaitkey(10) if(c=="n"): #in "n" key pressed while popup window in focus camera_index += 1 #try next camera index capture = cv.capturefromcam(camera_index) if not capture: #if next camera index didn't work, reset 0. camera_index = 0 capture = cv.capturefromcam(camera_index) while true: repeat()
traceback (most recent call last): file "pycam.py", line 21, in repeat() file "pycam.py", line 12, in repeat c = highgui.cvwaitkey(10) nameerror: global name 'highgui' not defined cleaned camera.
there have been quite few changes in new api. following work:
import cv cv.namedwindow("w1", cv.cv_window_autosize) camera_index = 0 capture = cv.capturefromcam(camera_index) def repeat(): global capture #declare globals since assigning them global camera_index frame = cv.queryframe(capture) cv.showimage("w1", frame) c = cv.waitkey(10) if(c=="n"): #in "n" key pressed while popup window in focus camera_index += 1 #try next camera index capture = cv.capturefromcam(camera_index) if not capture: #if next camera index didn't work, reset 0. camera_index = 0 capture = cv.capturefromcam(camera_index) while true: repeat()
it simpler, cleaner syntax!
Comments
Post a Comment