def main(args): global debugSurface if len(args) > 1: camNum = int(args[1]) print "Using cam %s" % (camNum,) else: camNum = 0 capture, dims = initializeCapture(cam=camNum, dims=CAPSIZE00) changeExposure(camNum, value=100) sketchSurface = GTKGui(dims=GTKGUISIZE) sketchWindow = gtk.Window(type=gtk.WINDOW_TOPLEVEL) sketchWindow.add(sketchSurface) sketchWindow.connect("destroy", gtk.main_quit) sketchWindow.show_all() sketchSurface.registerKeyCallback('C', lambda: displayCalibrationPattern(sketchSurface)) calibArea = CalibrationArea(capture, dims, sketchSurface) calibArea.registerKeyCallback('+', lambda x: changeExposure(camNum, 100)) calibArea.registerKeyCallback('-', lambda x: changeExposure(camNum, -100)) calibWindow = gtk.Window(type=gtk.WINDOW_TOPLEVEL) calibWindow.add(calibArea) calibWindow.connect("destroy", lambda x: calibWindow.destroy()) calibWindow.show_all() debugSurface = DebugWindow() debugWindow = gtk.Window(type=gtk.WINDOW_TOPLEVEL) debugWindow.add(debugSurface) # debugWindow.show_all() sketchSurface.grab_focus() gtk.main() print "gtkMain exits"
def switchCamera(self, camNumber): """Switch the camera used to capture""" log.debug("Trying to use camera %s" % (camNumber,)) self.currentCamera = camNumber self.warpCorners = [] #DEFAULT_CORNERS self.targetWarpCorners = CamArea.RAWIMAGECORNERS self.capture, self.captureDims = \ initializeCapture(self.currentCamera, self.dimensions) self.setDisplayDims(self.displayDims)
def main(args): global DEBUG DEBUG = True if len(args) > 1: camNum = int(args[1]) print "Using cam %s" % (camNum,) else: camNum = 0 capture, dims = initializeCapture(cam=camNum, dims=CAPSIZE00) changeExposure(camNum, value=300) dispScale = 0.4 warpCorners = [] targetCorners = [(0, 0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])] def onMouseClick(event, x, y, flags, param): if event == cv.CV_EVENT_LBUTTONUP: if len(warpCorners) != 4: warpCorners.append((x / dispScale, y / dispScale,)) if len(warpCorners) == 4: print warpCorners fgFilter.setBackground(image) cv.NamedWindow("Foreground Filter") cv.SetMouseCallback("Foreground Filter", onMouseClick) fgFilter = ForegroundFilter() while True: image = captureImage(capture) if len(warpCorners) == 4: image = warpFrame(image, warpCorners, targetCorners) fgFilter.updateBackground(image) dispImage = fgFilter.getBackgroundImage() showResized("Foreground Filter", dispImage, dispScale) key = cv.WaitKey(10) if key != -1: key = chr(key % 256) if key == 'q': break if key == 'r': fgFilter.setBackground(image) if key == 'R': warpCorners = [] fgFilter.setBackground(image) if key in ('+', '='): changeExposure(camNum, 100) elif key in ('-', '_'): changeExposure(camNum, -100) cv.DestroyAllWindows()
def __init__(self, cam=0, dims=MAXCAPSIZE, displayDims = (1366, 1024)): # Create a new window CamArea.RAWIMAGECORNERS = [(0,0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])] CamArea.CHESSBOARDCORNERS = [(5*dims[0]/16.0, 5*dims[1]/16.0), (11*dims[0]/16.0, 5*dims[1]/16.0), (11*dims[0]/16.0, 11*dims[1]/16.0), (5*dims[0]/16.0, 11*dims[1]/16.0),] ImageArea.__init__(self) #GUI Data self.shouldUpdate = True self.imageScale = 0.5 self.prevImage = None self.isCalibrating = True #Camera Data self.currentCamera = cam self.dimensions = dims self.warpCorners = [] #DEFAULT_CORNERS self.targetWarpCorners = CamArea.RAWIMAGECORNERS self.capture, self.captureDims = \ initializeCapture(self.currentCamera, dims) self.displayDims = displayDims self.imageScale = None self.setDisplayDims(displayDims) self.boardCapture = BoardChangeWatcher() #Event hooks gobject.idle_add(self.idleUpdateImage) self.set_property("can-focus", True) #So we can capture keyboard events self.connect("button_press_event", self.onMouseDown) #self.connect("visibility_notify_event", self.onVisibilityChange) #self.connect("motion_notify_event", self.onMouseMove) self.connect("button_release_event", self.onMouseUp) self.connect("key_press_event", self.onKeyPress) self.set_events(gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.KEY_PRESS_MASK | gtk.gdk.VISIBILITY_NOTIFY_MASK | gtk.gdk.POINTER_MOTION_MASK ) if DEBUG: self.debugVideoWriter = None self.callBacks = {}
def main(args): global DEBUG DEBUG = True if len(args) > 1: camNum = int(args[1]) print "Using cam %s" % (camNum,) else: camNum = 0 capture, dims = initializeCapture(cam=camNum, dims=CAPSIZE00) changeExposure(camNum, value=100) dispScale = 0.5 warpCorners = [] targetCorners = [(0, 0), (dims[0], 0), (dims[0], dims[1]), (0, dims[1])] def onMouseClick(event, x, y, flags, param): if event == cv.CV_EVENT_LBUTTONUP: if len(warpCorners) != 4: warpCorners.append((int(x / dispScale), int(y / dispScale),)) if len(warpCorners) == 4: print warpCorners cv.NamedWindow("Output") cv.SetMouseCallback("Output", onMouseClick) bcWatcher = BoardChangeWatcher() dispImage = captureImage(capture) # dispImage = warpFrame(dispImage, warpCorners, targetCorners) isPaused = False while True: image = captureImage(capture) if not isPaused: if len(warpCorners) == 4: bcWatcher.setBoardCorners(warpCorners) bcWatcher.updateBoardImage(image) showResized("FGFilter", bcWatcher._fgFilter.getBackgroundImage(), 0.4) if bcWatcher.isCaptureReady: (darker, lighter) = bcWatcher.captureBoardDifferences() showResized("Darker", darker, 0.3) showResized("Lighter", lighter, 0.3) dispImage = bcWatcher.acceptCurrentImage() for corner in warpCorners: cv.Circle(dispImage, corner, 3, (255, 200, 0)) showResized("Output", dispImage, dispScale) key = cv.WaitKey(50) if key != -1: key = chr(key % 256) if key == 'q': break if key == 'p': isPaused = not isPaused if isPaused: print "Paused" else: print "Unpaused" if key == 'r': bcWatcher.setBoardImage(image) dispImage = image if key == 'R': warpCorners = [] if key in ('+', '='): changeExposure(camNum, 100) elif key in ('-', '_'): changeExposure(camNum, -100) cv.DestroyAllWindows()