コード例 #1
0
 def run(self):
     while True:
         image = StringIO.StringIO(self.img_queue.get())
         logger.debug("Processing net image")
         stks = imageBufferToStrokes(image)
         logger.debug("Processed net image, converting strokes")
         for stk in stks:
             newStroke = Stroke()
             for x,y in stk.points:
                scale = WIDTH / float(1280)
                newPoint = Point(scale * x,HEIGHT - scale * y)
                newStroke.addPoint(newPoint)
             self.stk_queue.put(newStroke)
コード例 #2
0
    def LoadStrokesFromImage(self):
        fname = askopenfilename(initialdir='/home/jbrowne/src/sketchvision/images/')
        if fname == "":
           return

        try:
           print "Loading strokes..."
           strokes = imageToStrokes(fname)
        except Exception as e:
           print "Error importing strokes from image '%s':\n %s" % (fname, e)
           return
        print "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)
コード例 #3
0
 def loadStrokes(self):
    fd = open(self._fname, "r")
    curStroke = None
    for line in fd.readlines():
       if line.startswith("#STROKE"):
          curStroke = Stroke()
       elif line.startswith("#ENDSTROKE"):
          logger.debug("Loaded Stroke with %s points" % (len(curStroke.Points)) )
          yield curStroke
          curStroke = None
       else:
          fields = line.split()
          assert len(fields) <= 3 and len(fields) > 1, "Error: ill-formed point"
          if len(fields) == 2:
             x, y = fields
             t = 0.0
          elif len(fields) == 3:
             x, y, t = fields
             
          curStroke.addPoint ( Point(float(x), float(y), float(t)) )
    fd.close()
コード例 #4
0
ファイル: RubineTrainer.py プロジェクト: jbrowne/UCSBsketch
    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)
コード例 #5
0
    def drawAnno( self, a ):
        edge_label_size = 15
        tape_label_size = 20
        active_color = "#BF5252"
        active_width = 7.0
        state_graph = a.state_graph_anno
        for from_node, connection_list in state_graph.connectMap.items():
            if from_node is not None:
                nodeColor = "#FFFFFF"
                if from_node == a.active_state:
                    nodeColor = active_color
                x, y = ( from_node.center.X, from_node.center.Y )
                self.getBoard().getGUI().drawCircle (x, y, radius=(from_node.radius / 2.0), color=nodeColor, width=3.0)

            #GeomUtils.strokeSmooth(edge.tailstroke, width = len(edge.tailstroke.Points) / 3).drawMyself()
            for edge, to_node in connection_list:
                if edge == a.leading_edge['edge']:
                    edgeColor = active_color
                else:
                    edgeColor = "#FFFFFF"
                if to_node is not None:
                    nodeColor = "#FFFFFF"
                    nodeWidth = 3.0
                    if to_node == a.active_state:
                        nodeColor = active_color
                        nodeWidth = active_width
                    x, y = ( to_node.center.X, to_node.center.Y )
                    self.getBoard().getGUI().drawCircle (x, y, radius=(to_node.radius / 2.0), color=nodeColor, fill="", width=nodeWidth)
                #Draw the smoothed tail
                if from_node is not None:
                    if edge.direction == "tail2head": #Connect the tail more closely to the edge
                        smooth_tail = Stroke([from_node.center] + edge.tailstroke.Points + [edge.tip])
                    else:
                        smooth_tail = Stroke([edge.tip] + edge.tailstroke.Points + [from_node.center])
                else:
                    smooth_tail = edge.tailstroke
                smooth_tail = GeomUtils.strokeSmooth(smooth_tail, width = len(edge.tailstroke.Points) / 3, preserveEnds = True)
                smooth_tail.drawMyself(color=edgeColor)

                #Draw the smoothed head
                ep1, ep2 = ( edge.headstroke.Points[0], edge.headstroke.Points[-1] )
                smooth_head = Stroke([ep1, edge.tip, ep2])
                smooth_head.drawMyself(color = edgeColor)

                if edge in a.edge2labels_map:
                    #Determine label offset
                     
                    for label in a.edge2labels_map[edge]:
                        textColor = "#FFFFFF"
                        if label == a.leading_edge['label']:
                            tm_logger.debug("Drawing leading label: %s" % (label.text))
                            textColor = active_color
                        tl, br = GeomUtils.strokelistBoundingBox(label.Strokes)

                        label_point = Point ((tl.X + br.X) / 2.0, br.Y)
                        label_point.X -= edge_label_size
                        label_point.Y -= edge_label_size
                        #label_point = smooth_tail.Points[len(smooth_tail.Points)/2]
                        self.getBoard().getGUI().drawText (label_point.X, label_point.Y, InText=label.text, size=edge_label_size, color=textColor)
                    #endfor
                #endif
            #end for edge
        #end for from_node

        #Draw the tape string
        tl, br = GeomUtils.strokelistBoundingBox(a.Strokes)
        tape_label_pt = Point( \
            ((tl.X + br.X) / 2.0) - (len(a.tape_string) + 2) * tape_label_size / 2.0 , \
            br.Y - tape_label_size)

        for curIdx, tapeChar in enumerate(['-'] + a.tape_string + ['-']):
            curPt = Point(tape_label_pt.X + curIdx * tape_label_size, tape_label_pt.Y)
            charColor = "#FFFFFF"
            if curIdx - 1== a.tape_idx:
                charColor = active_color
            self.getBoard().getGUI().drawText (curPt.X, curPt.Y, InText=tapeChar, size=tape_label_size, color=charColor)