def run(self):
        """Initialize the basic board model first, then continually
        update the image and add new ink to the board"""
        global debugSurface
        print "Board Watcher Started: pid %s" % (self.pid,)
        try:
            import pydevd
            pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
        except:
            pass
        rawImage = None
        while self.keepGoing.is_set() and rawImage is None:
            try:
                rawImage = deserializeImage(self.imageQueue.get(True, 1))
            except EmptyException:
                pass
        if not self.keepGoing.is_set():
            print "Board watcher stopping"
            return

        saveimg(rawImage, name="Initial_Board_Image")
        self.boardWatcher.setBoardImage(rawImage)
        self.boardWatcher.setBoardCorners(self.warpCorners, self.targetCorners)
        boardWidth = self.board.getDimensions()[0]
        warpImage = warpFrame(rawImage, self.warpCorners, self.targetCorners)
        warpImage = resizeImage(warpImage, dims=GTKGUISIZE)
        strokeList = ISC.cvimgToStrokes(flipMat(warpImage), targetWidth=boardWidth)['strokes']

        for stk in strokeList:
            self.board.addStroke(stk)
        while self.keepGoing.is_set():
            rawImage = deserializeImage(self.imageQueue.get(block=True))
            self.boardWatcher.updateBoardImage(rawImage)
            if self.boardWatcher.isCaptureReady:
                saveimg(rawImage, name="Raw Image")
                saveimg(self.boardWatcher._fgFilter.getBackgroundImage(), name="BG_Image")
                (newInk, newErase) = self.boardWatcher.captureBoardDifferences()
                newInk = warpFrame(newInk, self.warpCorners, self.targetCorners)
                newInk = resizeImage(newInk, dims=GTKGUISIZE)
                newErase = warpFrame(newErase, self.warpCorners, self.targetCorners)
                newErase = resizeImage(newErase, dims=GTKGUISIZE)
                saveimg(newInk, name="NewInk")
                saveimg(newErase, name="NewErase")
                cv.AddWeighted(newInk, -1, newInk, 0, 255, newInk)

                acceptedImage = self.boardWatcher.acceptCurrentImage()
                saveimg(acceptedImage, name="AcceptedImage")
                strokeList = ISC.cvimgToStrokes(flipMat(newInk), targetWidth=boardWidth)['strokes']
                for stk in strokeList:
                    self.board.addStroke(stk)
        print "Board watcher stopping"
Exemple #2
0
def processImage(image, strokeQueue, scaleDims):
    """This function will extract strokes
    from an image file. It will add the extracted strokes from
    the image to strokeQueue, scaled according to scaleDims"""
    pruneLen = 10
    width, height = scaleDims
    log.debug("Process spawned")
    try:
        strokeDict = ImageStrokeConverter.cvimgToStrokes(image)
    except Exception as e:
        raise

    strokes = strokeDict['strokes']
    w,h = strokeDict['dims']
    scale_x = width / float(w)
    scale_y = height / float(h)
    log.debug( "Got %s Strokes" % (len(strokes)) )
    for s in strokes:
        if len(s.Points) > pruneLen:
            pointList = []
            for x,y in s.Points:
                newPoint = Point(scale_x * x, height - (scale_y *y))
                pointList.append(newPoint)
            newStroke = Stroke(pointList)
            strokeQueue.put(newStroke)
Exemple #3
0
    def LoadStrokesFromImage(self, image = None):
        global WIDTH, HEIGHT
        pruneLen = 10
        if image != None:
            try:
                strokeDict = ImageStrokeConverter.cvimgToStrokes(image)
            except:
                logger.error("Error importing strokes from frame")
                raise
        else:
            fname = askopenfilename(initialdir='/home/jbrowne/src/photos/')
            if fname == "":
               return

            try:
               logger.debug( "Loading strokes...")
               strokeDict = ImageStrokeConverter.imageToStrokes(fname)
               logger.debug( "Loaded %s strokes from '%s'" % 
                   (len(strokeDict['strokes']), fname))
            except Exception as e:
               logger.debug( "Error importing strokes from image '%s':\n %s" % 
                   (fname, e))
               raise

        strokes = strokeDict['strokes']
        w,h = strokeDict['dims']
        scale_x = WIDTH / float(w)
        scale_y = HEIGHT / float(h)
        for s in strokes:
           if len(s.points) > pruneLen:
               pointList = []
               for x,y in s.points:
                  newPoint = Point(scale_x * x, HEIGHT - (scale_y *y))
                  pointList.append(newPoint)
               newStroke = Stroke(pointList)
               self.AddStroke(newStroke)