Save frame from webcam to disk with opencv python bindings -


i'm trying use opencv save frames webcam jpgs or pngs or whatever. it's proving more difficult i'd thought, despite having examples 1 here: capturing single image webcam in java or python

i trying this:

if __name__ == "__main__": print "press esc exit ..." # create windows cv.namedwindow('raw', cv.cv_window_autosize) cv.namedwindow('processed', cv.cv_window_autosize) # create capture device device = 0 # assume want first device capture = cv.capturefromcam(0) cv.setcaptureproperty(capture, cv.cv_cap_prop_frame_width, 640) cv.setcaptureproperty(capture, cv.cv_cap_prop_frame_height, 480) # check if capture device ok if not capture: print "error opening capture device" sys.exit(1) while 1: # forever # capture current frame frame = cv.queryframe(capture) if frame none: break # mirror cv.flip(frame, none, 1) # face detection detect(frame) # display webcam image cv.showimage('raw', frame) # handle events k = cv.waitkey(10) if k == 0x1b: # esc print 'esc pressed. exiting ...' break if k == 0x63 or k == 0x43: print 'capturing!' s, img = capture.read() if s: cv.saveimage("r'c:\test.jpg", img) 

as can see i've tried make capture image when press letter c, using modification of code suggested froyo in other question. doesn't work , can't find documentation make work.

please help! lot, alex

change saving section follows :

if k == 0x63 or k == 0x43: print 'capturing!' cv.saveimage("test.jpg",frame) 

it works me. since have captured frame detection, need capture again save this.

also cv.capturefromcam() , cv.videocapture() different. not mixed up.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -