예제 #1
0
 def __init__(self):
     Drawing.__init__(self)
     self.previous_direction = None
     self.drawing_mode = LineDrawingMode
     self.radius_for_circle = 5.0
     self.circle_mode = ThreePointsCircleMode
     self.save_drawing_mode = []
예제 #2
0
class Listener(Leap.Listener):

    def on_connect(self, controller):
        print "Connected"
        self.drawing = Drawing()
        self.prev_pot = 400
        self.prev_button = 1
        # controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);

    def on_frame(self, controller):
        frame = controller.frame()

        #print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % (
          #frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures()))
        if len(frame.tools) > 0:
            pen = frame.tools[0]
            reading = ser.readline()
            #print reading
            try:
                pot = int(reading.split(' ')[0])
                button = int(reading.split(' ')[1][0])
                self.prev_pot = pot
                self.prev_button = button
                #print (pot, button)
            except:
                pot = self.prev_pot
                button = self.prev_button
                print 'Invalid reading'
            radius = float(pot-low_pot)/(high_pot-low_pot)*(high_radius-low_radius) + low_radius
            if True:
                print ('position: ' + str(pen.tip_position), 'radius: ' + str(radius))
                self.drawing.add_sphere(Sphere(pen.tip_position, radius))
예제 #3
0
파일: GameField.py 프로젝트: Kanol/Checkers
class GameField:
    def __init__(self):
        self.width = 10
        self.height = 10
        self.checkers_count = 20
        self.back_field = Drawing(self.width, self.height, 30)

        self.checkers_field = []
        self.fill_checkers_field()
        print(self.checkers_field[0].x + self.checkers_field[0].y)
        self.back_field.draw_checkers(self.checkers_field)
        self.back_field.main()

    def fill_checkers_field(self):
        white_checkers = self.checkers_count
        black_checkers = self.checkers_count
        for x in range(self.width):
            for y in range(self.height):
                if black_checkers == 0:
                    break
                if not (x + y) % 2 == 0:
                    self.checkers_field.append(Checker(y, x, "blue"))
                    black_checkers -= 1

        for x in range(self.width - 1, -1, -1):
            for y in range(self.height - 1, -1, -1):
                if white_checkers == 0:
                    break
                if not (x + y) % 2 == 0:
                    self.checkers_field.append(Checker(y, x, "green"))
                    white_checkers -= 1
예제 #4
0
파일: GameField.py 프로젝트: Kanol/Checkers
    def __init__(self):
        self.width = 10
        self.height = 10
        self.checkers_count = 20
        self.back_field = Drawing(self.width, self.height, 30)

        self.checkers_field = []
        self.fill_checkers_field()
        print(self.checkers_field[0].x + self.checkers_field[0].y)
        self.back_field.draw_checkers(self.checkers_field)
        self.back_field.main()
예제 #5
0
 def __init__(self, people, main, influence, ad, recommendation, graph, env, res = (1920,1080), current = 0):
     Drawing.__init__(self, res)
     self.graph = people
     self.mainConfig = main
     self.influenceConfig = influence
     self.adConfig = ad
     self.recommendationConfig = recommendation
     self.graphConfig = graph
     self.envConfig = env
     self.transitions = []
     self.go = True
     self.current = current
     self.key = 1
 def create_drawing(path, orig_data=True, stroke_size=None):
     """
     :param path: path to the data file (.txt)
     :return: Drawing object.
     """
     data = Analyzer.get_data_file(path)
     if orig_data:
         pic_path = Analyzer.get_pic_path(path)
     else:
         pic_path = None
         return Drawing(Analyzer.get_strokes(data), pic_path, stroke_size)
     if pic_path is not None:
         return Drawing(Analyzer.get_strokes(data), pic_path, stroke_size)
     else:
         print("Error: missing data")
예제 #7
0
 def AddPoint(self, d):
     if (self.drawing_mode == LineDrawingMode) or (self.drawing_mode
                                                   == ArcDrawingMode):
         # edit the end of the previous item to be the start of the arc
         # this only happens if we are drawing tangents to other objects
         # really need to fill the gap with whatever we are tangent around
         # ellipse,arc,spline or whatever
         if (self.TempObject() != None) and (self.prev_object != None):
             if (self.prev_object != None):
                 spos = self.TempObject().GetStartPoint()
                 epos = self.prev_object.GetEndPoint()
                 tanobject = self.start_pos.GetObject1()
                 if self.start_pos.type == cad.DigitizeType.DIGITIZE_TANGENT_TYPE and (
                         tanobject != None):
                     if tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_LINE:
                         #((HLine*)prev_object)->B = p;
                         pass
                     elif tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_ARC:
                         tanobject.A = geom.Point3D(spos)
                         tanobject.B = geom.Point3D(epos)
                         self.AddToTempObjects(tanobject)
                     elif tanobject.GetType() == cad.OBJECT_TYPE_CIRCLE:
                         arc = cad.NewArc(spos, epos, tanobject.axis,
                                          tanobject.C)
                         arc.A = geom.Point3D(spos)
                         arc.B = geom.Point3D(epos)
                         self.AddToTempObjects(arc)
     Drawing.AddPoint(self, d)
예제 #8
0
 def OnStart(self):
     # on start of drawing mode
     Drawing.OnStart(self)
     if self.container:
         self.container = None
     self.prev_object = None
     self.previous_direction = None
예제 #9
0
 def GetTools(self):
     tools = Drawing.GetTools(self)
     self.arc_drawing_tool = ToolBarTool.CadToolBarTool(
         'Arc Drawing',
         'arc' if self.drawing_mode == ArcDrawingMode else 'line',
         self.SetArcDrawing)
     tools.append(self.arc_drawing_tool)
     return tools
예제 #10
0
 def GetProperties(self):
     properties = []
     if self.drawing_mode == CircleDrawingMode:
         if self.circle_mode == CentreAndRadiusCircleMode:
             wx.GetApp().AddInputProperty(
                 properties, PyProperty("radius", 'radius_for_circle',
                                        self))
     properties += Drawing.GetProperties(self)
     return properties
예제 #11
0
 def OnKeyDown(self, key_code):
     if key_code == ord('A'):
         if self.drawing_mode == ArcDrawingMode:
             # switch back to previous drawing mode
             if len(self.save_drawing_mode) > 0:
                 self.drawing_mode = self.save_drawing_mode[-1]
                 self.save_drawing_mode.pop()
         else:
             # switch to arc drawing mode until a is released
             self.save_drawing_mode.append(self.drawing_mode)
             self.drawing_mode = ArcDrawingMode
         wx.GetApp().frame.input_mode_canvas.UpdateTitleProperty()
         return True
     return Drawing.OnKeyDown(self, key_code)
예제 #12
0
def run():
    filesets = [
        ("data/Notre Dame/1_o.jpg", "data/Notre Dame/1_o-featuresmat.mat"),
        ("data/Notre Dame/2_o.jpg", "data/Notre Dame/2_o-featuresmat.mat"),
        # ("data/duda/img_20170130_162706.jpg", "data/duda/img_20170130_162706-featuresmat.mat"),
        # ("data/duda/c3bxl_zweaywcbm.jpg", "data/duda/c3bxl_zweaywcbm-featuresmat.mat"),
        # ("data/fountain/0000.png", "data/fountain/0000-featuresmat.mat"),
        # ("data/fountain/0001.png", "data/fountain/0001-featuresmat.mat"),
        # ("data/Mount Rushmore/9021235130_7c2acd9554_o.jpg", "data/Mount Rushmore/9021235130_7c2acd9554_o-featuresmat.mat"),
        # ("data/Mount Rushmore/9318872612_a255c874fb_o.jpg","data/Mount Rushmore/9318872612_a255c874fb_o-featuresmat.mat"),
        # ("data/Episcopal Gaudi/3743214471_1b5bbfda98_o.jpg", "data/Episcopal Gaudi/3743214471_1b5bbfda98_o-featuresmat.mat"),
        # ("data/Episcopal Gaudi/4386465943_8cf9776378_o.jpg", "data/Episcopal Gaudi/4386465943_8cf9776378_o-featuresmat.mat"),
    ]

    for fileset in filesets:
        print("=== Files: (%s, %s)" % fileset)
        (imageFilename, featureFilename) = fileset
        basePath, extPath = os.path.splitext(imageFilename)
        sourceImage = sc.ndimage.imread(imageFilename, flatten=True)

        drawing = Drawing()

        # featuresWithOrientation = siftDescriptor(fileset)
        oa = OrientationAssignment()
        (featuresWithOrientation2,
         featuresWithOrientationToDraw) = oa.compute(sourceImage,
                                                     featureFilename)
        drawing.drawFeaturesWithOrientations(imageFilename,
                                             basePath + "-with-features.jpg",
                                             featuresWithOrientationToDraw)

        # Descripting
        fd = FeatureDescripting()
        featuresWithDescriptors = fd.compute(sourceImage,
                                             featuresWithOrientation2)
        fd.saveFeatureDescriptors(basePath + "-features.mat",
                                  featuresWithDescriptors)
예제 #13
0
    def training(self):
        filename = path + '\Corpus\{0}_ya.txt'.format(self.target_word)
        # ----- loading Wiktionary data -----
        self.worddata = WiktionaryData(self.target_word, self.language)

        # ---- loading corpus -----
        self.corpus = Corpus()
        self.corpus.load_corpus(filename, self.language, self.target_word)
        count = len(self.corpus.paragraphes)
        corpus_paragraphes_count = count

        # ----- add definitions and examples to corpus
        for d in self.worddata.definitions:
            paragraph = Paragraph(count)
            d['parnmb'] = count
            s = Sentence(d['sent'].fulltext, self.language, self.target_word)
            if 'ex' in d:
                for exmpl in d['ex']:
                    s.stemmed_tokens += exmpl.stemmed_tokens
                    s.tokens += exmpl.tokens
            paragraph.add_sentence(s)
            paragraph.add_definition(d)
            self.corpus.add_paragraph(paragraph)
            count += 1
        rng = numpy.array(range(corpus_paragraphes_count, len(self.corpus.paragraphes)))

        # ---- creating tf-idf matrix -----
        self.corpus.create_tf_idf_matrix()

        # ----- draw -----
        draw2d = Drawing(2, self.corpus.tf_idf_matrix, len(self.worddata.definitions), rng)
        draw2d.draw()
        draw3d = Drawing(3, self.corpus.tf_idf_matrix, len(self.worddata.definitions), rng)
        draw3d.draw()
        del(draw2d)
        del(draw3d)

        # ----- matrix reduction -----
        if self.reduction_mode == 'SVD':
            self.pca_object = myPCA(0.95, 2)
            self.pca_object.count_number_of_principal_components(self.corpus.tf_idf_matrix)
            new_X = self.pca_object.reduce_matrix_dimension(self.corpus.tf_idf_matrix)
        else:
            new_X = self.corpus.tf_idf_matrix

        # ----- clustering -----
        self.cluster_object = Cluster('K-means', len(self.worddata.definitions), new_X, rng)
        self.cluster_object.clustering()
        self.cluster_object.make_word_clusters(self.corpus)
        print('Trainig is done')
예제 #14
0
 def __init__(self):
     Drawing.__init__(self)
예제 #15
0
 def __init__(self):
     Drawing.__init__(self)
     self.profile = None
예제 #16
0
 def is_a_draw_level(self, level):
     if (self.drawing_mode == SplineDrawingMode) and (self.spline_mode == RationalSplineMode):
         return level >= 3
     if self.drawing_mode == EllipseDrawingMode:
         return level >= 1
     return Drawing.is_a_draw_level(self, level)
예제 #17
0
 def __init__(self, graph, config, res = (1920, 1080)):
     Drawing.__init__(self, res = (1920, 1080))
     self.graph = graph
     self.config = config
예제 #18
0
'''
Created on 31 ott 2018

@author: marco
'''

from Drawing import Drawing
from Structure import Structure

dwg = Drawing("panel.dwg")

l = 900
h = 1500

bplst = Structure(dwg, 900, 2100)

bplst.baseStructure()
bplst.basePanel()

dwg.save()

if __name__ == '__main__':
    pass
예제 #19
0
 def __init__(self):
     Drawing.__init__(self)
     self.spline_points = []
     self.drawing_mode = EllipseDrawingMode
     self.spline_mode = CubicSplineMode
예제 #20
0
 def initDrawing(self):
     Drawing.canvas = self.canvas
     Drawing.init()
예제 #21
0
 def on_connect(self, controller):
     print "Connected"
     self.drawing = Drawing()
     self.prev_pot = 400
     self.prev_button = 1
예제 #22
0
from PolygonParser import PolygonParser
from Drawing import Drawing

from Gooey import Gooey
from DrawingWindow import DrawingWindow

d = Drawing()
p = PolygonParser("tricky_polygon.svg", d)

g = Gooey()
dw = DrawingWindow(d)
dw.zoom = 1.0
g.show(dw)

g.start()

예제 #23
0
    def main():
        print("Composite pattern Shapes..")
        cir1 = Circle()
        cir1.draw("red")
        cir2 = Circle()
        cir2.draw("blue")
        tri1 = Triangle()
        tri1.draw("green")

        drawing = Drawing()
        drawing.add(cir1)
        drawing.add(tri1)
        drawing.draw("yellow")

        drawing.add(cir2)
        drawing.draw("orange")

        drawing.remove(tri1)
        drawing.draw("orange")
예제 #24
0
def run():
    COMPUTE_ORIENTATION = False
    COMPUTE_DESCRIPTION = False
    COMPUTE_MATCHING = True
    for fileset in filesets:
        print("=== Files: (%s, %s)" % (fileset[0][0], fileset[1][0]))
        # Loading first image
        (imageFilename1, featureFilename1) = fileset[0]
        basePath1 = os.path.splitext(imageFilename1)[0]
        sourceImage1 = sc.ndimage.imread(imageFilename1, flatten=True)

        # Loading second image
        (imageFilename2, featureFilename2) = fileset[1]
        basePath2 = os.path.splitext(imageFilename2)[0]
        sourceImage2 = sc.ndimage.imread(imageFilename2, flatten=True)

        drawing = Drawing()

        # Orientation assignment of first image
        if COMPUTE_ORIENTATION:
            oa1 = OrientationAssignment()
            (featuresWithOrientation1,
             featuresWithOrientationToDraw1) = oa1.compute(
                 sourceImage1, featureFilename1)
            drawing.drawFeaturesWithOrientations(
                imageFilename1, basePath1 + "-with-features.jpg",
                featuresWithOrientationToDraw1)

        # Orientation assignment of second image
        if COMPUTE_ORIENTATION:
            oa2 = OrientationAssignment()
            (featuresWithOrientation2,
             featuresWithOrientationToDraw2) = oa2.compute(
                 sourceImage2, featureFilename2)
            drawing.drawFeaturesWithOrientations(
                imageFilename2, basePath2 + "-with-features.jpg",
                featuresWithOrientationToDraw2)

        # Descripting - 1st img
        featuresPath1 = basePath1 + "-features.mat"
        if COMPUTE_DESCRIPTION:
            fd1 = FeatureDescripting()
            featuresWithDescriptors1 = fd1.compute(sourceImage1,
                                                   featuresWithOrientation1)
            fd1.saveFeatureDescriptors(featuresPath1, featuresWithDescriptors1)

        # Descripting - 2nd img
        featuresPath2 = basePath2 + "-features.mat"
        if COMPUTE_DESCRIPTION:
            fd2 = FeatureDescripting()
            featuresWithDescriptors2 = fd2.compute(sourceImage2,
                                                   featuresWithOrientation2)
            fd2.saveFeatureDescriptors(featuresPath2, featuresWithDescriptors2)

        # Matching
        if COMPUTE_MATCHING:
            fm = FeatureMatching()
            fm.compute(fileset[0][0], fileset[1][0], featuresPath1,
                       featuresPath2)
            fm.drawTopMatches(basePath1 + "-matches.jpg", amount=60)
            if fileset[2]:
                fm.verify(fileset[2])
예제 #25
0
def accuracy_plot():
    """Rysuje wykres pokazujący stopień dokładności przewidywań sieci"""
    drawing = Drawing()
    drawing.draw_accuracy_plot()
예제 #26
0
def loss_plot():
    drawing = Drawing()
    drawing.draw_loss_plot()