def OnWebcam(self,event): print "This should start up the webcam..." res = (640,480) fps = 15.0 webcamLoop = True # Delete image if it is there if self.bitmap is not None: self.bitmap.Destroy() window_list = self.panel.GetChildren() camera = highgui.cvCreateCameraCapture(0) def get_image(): im = highgui.cvQueryFrame(camera) #convert Ipl image to PIL image return opencv.adaptors.Ipl2PIL(im) pygame.init() window = pygame.display.set_mode(res) pygame.display.set_caption("Fractal Webcam") screen = pygame.display.get_surface() while webcamLoop: events = pygame.event.get() for event in events: if event.type == QUIT: webcamLoop = False im = get_image() pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode) screen.blit(pg_img, (0,0)) pygame.display.flip() pygame.time.delay(int(1000 * 1.0/fps)) if not(webcamLoop): highgui.cvDestroyAllWindows() pygame.quit() self.Destroy()
def main(args): global capture global hmax, hmin highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Satuation', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE) highgui.cvMoveWindow('Camera', 0, 10) highgui.cvMoveWindow('Hue', 0, 350) highgui.cvMoveWindow('Satuation', 360, 10) highgui.cvMoveWindow('Value', 360, 350) highgui.cvMoveWindow('Laser', 700, 40) highgui.cvCreateTrackbar("Brightness Trackbar", "Camera", 0, 255, change_brightness) highgui.cvCreateTrackbar("hmin Trackbar", "Hue", hmin, 180, change_hmin) highgui.cvCreateTrackbar("hmax Trackbar", "Hue", hmax, 180, change_hmax) highgui.cvCreateTrackbar("smin Trackbar", "Satuation", smin, 255, change_smin) highgui.cvCreateTrackbar("smax Trackbar", "Satuation", smax, 255, change_smax) highgui.cvCreateTrackbar("vmin Trackbar", "Value", vmin, 255, change_vmin) highgui.cvCreateTrackbar("vmax Trackbar", "Value", vmax, 255, change_vmax) print "grabbing camera" capture = highgui.cvCreateCameraCapture(0) print "found camera" highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH, 320) highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 240) frame = highgui.cvQueryFrame(capture) frameSize = cv.cvGetSize(frame) hsv = cv.cvCreateImage(frameSize, 8, 3) mask = cv.cvCreateImage(frameSize, 8, 1) hue = cv.cvCreateImage(frameSize, 8, 1) satuation = cv.cvCreateImage(frameSize, 8, 1) value = cv.cvCreateImage(frameSize, 8, 1) laser = cv.cvCreateImage(frameSize, 8, 1) while 1: frame = highgui.cvQueryFrame(capture) cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV) #cv.cvInRangeS(hsv,hsv_min,hsv_max,mask) cv.cvSplit(hsv, hue, satuation, value, None) cv.cvInRangeS(hue, hmin, hmax, hue) cv.cvInRangeS(satuation, smin, smax, satuation) cv.cvInRangeS(value, vmin, vmax, value) #cv.cvInRangeS(hue,0,180,hue) cv.cvAnd(hue, value, laser) #cv.cvAnd(laser, value, laser) cenX, cenY = averageWhitePoints(laser) #print cenX,cenY draw_target(frame, cenX, cenY) #draw_target(frame,200,1) highgui.cvShowImage('Camera', frame) highgui.cvShowImage('Hue', hue) highgui.cvShowImage('Satuation', satuation) highgui.cvShowImage('Value', value) highgui.cvShowImage('Laser', laser) k = highgui.cvWaitKey(10) if k == " ": highgui.cvDestroyAllWindows() highgui.cvReleaseCapture(capture) sys.exit()
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() highgui.cvReleaseCapture(capture) pygame.quit() #sys.exit() break keyinput = pygame.key.get_pressed() #print "key pressed: ", keyinput if keyinput[K_SPACE]: #frame = highgui.cvQueryFrame (capture) #frame = highgui.cvGrabFrame (capture) img = highgui.cvQueryFrame(capture) img = highgui.cvRetrieveFrame(capture) if frame is None: # no image captured... end the processing
#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() highgui.cvReleaseCapture (capture) pygame.quit() #sys.exit() break keyinput = pygame.key.get_pressed() #print "key pressed: ", keyinput if keyinput[K_SPACE]: #frame = highgui.cvQueryFrame (capture) #frame = highgui.cvGrabFrame (capture) img = highgui.cvQueryFrame (capture) img = highgui.cvRetrieveFrame (capture) if frame is None: # no image captured... end the processing
def main(args): global capture global hmax, hmin highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Satuation', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Value', highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow('Laser', highgui.CV_WINDOW_AUTOSIZE) highgui.cvMoveWindow('Camera', 0, 10) highgui.cvMoveWindow('Hue', 0, 350) highgui.cvMoveWindow('Satuation', 360, 10) highgui.cvMoveWindow('Value', 360, 350) highgui.cvMoveWindow('Laser', 700, 40) highgui.cvCreateTrackbar("Brightness Trackbar","Camera",0,255, change_brightness); highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin); highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax); highgui.cvCreateTrackbar("smin Trackbar","Satuation",smin,255, change_smin); highgui.cvCreateTrackbar("smax Trackbar","Satuation",smax,255, change_smax); highgui.cvCreateTrackbar("vmin Trackbar","Value",vmin,255, change_vmin); highgui.cvCreateTrackbar("vmax Trackbar","Value",vmax,255, change_vmax); print "grabbing camera" capture = highgui.cvCreateCameraCapture(0) print "found camera" highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, 320) highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, 240) frame = highgui.cvQueryFrame(capture) frameSize = cv.cvGetSize(frame) hsv = cv.cvCreateImage(frameSize,8,3) mask = cv.cvCreateImage(frameSize,8,1) hue = cv.cvCreateImage(frameSize,8,1) satuation = cv.cvCreateImage(frameSize,8,1) value = cv.cvCreateImage(frameSize,8,1) laser = cv.cvCreateImage(frameSize,8,1) while 1: frame = highgui.cvQueryFrame(capture) cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV) #cv.cvInRangeS(hsv,hsv_min,hsv_max,mask) cv.cvSplit(hsv,hue,satuation,value,None) cv.cvInRangeS(hue,hmin,hmax,hue) cv.cvInRangeS(satuation,smin,smax,satuation) cv.cvInRangeS(value,vmin,vmax,value) #cv.cvInRangeS(hue,0,180,hue) cv.cvAnd(hue, value, laser) #cv.cvAnd(laser, value, laser) cenX,cenY = averageWhitePoints(laser) #print cenX,cenY draw_target(frame,cenX,cenY) #draw_target(frame,200,1) highgui.cvShowImage('Camera',frame) highgui.cvShowImage('Hue',hue) highgui.cvShowImage('Satuation',satuation) highgui.cvShowImage('Value',value) highgui.cvShowImage('Laser',laser) k = highgui.cvWaitKey(10) if k == " ": highgui.cvDestroyAllWindows() highgui.cvReleaseCapture (capture) sys.exit()