def frame(self): if self.framepos == -1: raise Exception('call next before the first frame!') format = self.format img = hg.cvRetrieveFrame(self.cap) nchannels = 1 if format == FORMAT_GRAY else 3 shape = \ (img.height, img.width) if nchannels == 1 else \ (img.height, img.width, nchannels) if format == FORMAT_BGR: # default format frame = np.ndarray(shape = shape, dtype = np.uint8, buffer = img.imageData) if self.own_data: frame = frame.copy() return frame size = cv.cvSize(img.width, img.height) img2 = cv.cvCreateImage(size, 8, nchannels) cvt_type = -1 if format == FORMAT_GRAY: cvt_type = cv.CV_BGR2GRAY elif format == FORMAT_RGB: cvt_type = cv.CV_BGR2RGB elif format == FORMAT_HSV: cvt_type = cv.CV_BGR2HSV else: assert(0) cv.cvCvtColor(img, img2, cvt_type) frame = np.ndarray(shape = shape, dtype = np.uint8, buffer = img2.imageData) if self.own_data: frame = frame.copy() return frame
print "frames per sec = ", fps # create the writer #writer = highgui.cvCreateVideoWriter ("captured.mpg", MPEG1VIDEO, # fps, frame_size, True) # check the writer is OK #if not writer: # print "Error opening writer" # sys.exit (1) print "starting loop" while 1: # do forever # 1. capture the current image frame = highgui.cvQueryFrame(capture) frame = highgui.cvRetrieveFrame(capture) #frame = highgui.cvGrabFrame (capture) #img = highgui.cvRetrieveFrame (capture) #cvGrabFrame(capture); // capture a frame #img=cvRetrieveFrame(capture); // retrieve the captured frame #cvWriteFrame(writer,img); // add the frame to the file highgui.cvShowImage('Camera', frame) # handle events #k = highgui.cvWaitKey () #print for event in pygame.event.get(): if event.type == pygame.QUIT: highgui.cvReleaseVideoWriter(writer) highgui.cvDestroyAllWindows()
ymatch = 0 def mousecb(e,x,y,f,p): global xmatch, ymatch if highgui.CV_EVENT_LBUTTONDOWN == e: xmatch = x ymatch = y highgui.cvSetMouseCallback("depthmatch - left", mousecb) cleft = highgui.cvCreateCameraCapture(2) cright = highgui.cvCreateCameraCapture(1) size = cv.cvGetSize(highgui.cvQueryFrame(cleft)) xmatch = size.width / 2 + 1 ymatch = size.height / 2 + 1 while True: highgui.cvGrabFrame(cleft) highgui.cvGrabFrame(cright) left = highgui.cvRetrieveFrame(cleft) right = highgui.cvRetrieveFrame(cright) depthmatch(xmatch, ymatch, left, right, buf=50, debug=True) highgui.cvWaitKey(10) """ IMGW = 1280 # 640 IMGH = 1024 # 480 stereostate_bm = cv.cvCreateStereoBMState(cv.CV_STEREO_BM_BASIC, 0) stereostate_gc = cv.cvCreateStereoGCState(16, 3) if not from_file: cap0 = highgui.cvCreateCameraCapture(1) highgui.cvSetCaptureProperty(cap0, highgui.CV_CAP_PROP_FRAME_WIDTH, IMGW) highgui.cvSetCaptureProperty(cap0, highgui.CV_CAP_PROP_FRAME_HEIGHT, IMGH) cap1 = highgui.cvCreateCameraCapture(2) highgui.cvSetCaptureProperty(cap1, highgui.CV_CAP_PROP_FRAME_WIDTH, IMGW)
print "frames per sec = ", fps # create the writer #writer = highgui.cvCreateVideoWriter ("captured.mpg", MPEG1VIDEO, # fps, frame_size, True) # check the writer is OK #if not writer: # print "Error opening writer" # sys.exit (1) print "starting loop" while 1: # do forever # 1. capture the current image frame = highgui.cvQueryFrame (capture) frame = highgui.cvRetrieveFrame (capture) #frame = highgui.cvGrabFrame (capture) #img = highgui.cvRetrieveFrame (capture) #cvGrabFrame(capture); // capture a frame #img=cvRetrieveFrame(capture); // retrieve the captured frame #cvWriteFrame(writer,img); // add the frame to the file highgui.cvShowImage ('Camera', frame) # handle events #k = highgui.cvWaitKey () #print for event in pygame.event.get(): if event.type == pygame.QUIT: highgui.cvReleaseVideoWriter (writer)