def LoadStrokesFromImage(self): fname = askopenfilename(initialdir='./') if fname == "": return try: logger.debug( "Loading strokes...") strokes = ImageStrokeConverter.imageToStrokes(fname) except Exception as e: logger.debug( "Error importing strokes from image '%s':\n %s" % (fname, e)) return logger.debug( "Loaded %s strokes from '%s'" % (len(strokes), fname)) for s in strokes: newStroke = Stroke() for x,y in s.points: scale = WIDTH / float(1280) newPoint = Point(scale * x,HEIGHT - scale * y) newStroke.addPoint(newPoint) #self.Board.AddStroke(newStroke) self.StrokeList.append(newStroke)
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)
def drawStroke(self, *args, **kargs): op = partial(TkSketchFrame.do_drawStroke, self, *args, **kargs) self.OpQueue.put(op) if __name__ == "__main__": if len(sys.argv) > 1: #Do something with the CLI arguments fname = sys.argv[1] board = Board() _initializeBoard(board) stkLoader = StrokeStorage(fname+".dat") stkDict = ImageStrokeConverter.imageToStrokes(fname) stks = stkDict['strokes'] WIDTH, HEIGHT = stkDict['dims'] strokeList = [] for s in stks: pointList = [] for x,y in s.points: newPoint = Point(x, HEIGHT - y) pointList.append(newPoint) strokeList.append(Stroke(pointList)) board.AddStroke(Stroke(pointList)) stkLoader.saveStrokes(strokeList) #fout = open("standalone.xml", "w") #print >> fout, ET.tostring(board.xml(WIDTH, HEIGHT)) #fout.close()