コード例 #1
0
    def draw(self, app, cr):
        utils.draw_rectangle(
            cr, self._rect, self._fill_color, self._outline_color)

        node_data = [
            # Nodes, input, offset, text align
            (self._component.inputs, True,
             (NODE_RADIUS+2, 0), utils.TextHAlign.LEFT),
            (self._component.outputs, False,
             (-NODE_RADIUS-2, 0), utils.TextHAlign.RIGHT),
        ]

        for nodes, is_input, offset, text_align in node_data:
            for i, node in enumerate(nodes):
                position = self.node_pos(is_input, i)
                connected = node.is_connected()
                fill_color = _node_color(node.value, connected)
                utils.draw_circle(cr, position, NODE_RADIUS, fill_color, BLACK)
                utils.draw_text(
                    cr, node.label, position + offset, size=10,
                    bold=True, h_align=text_align)

        name = self._component.name
        if name:
            position = self.center - (0, self._rect.height/2+8)
            utils.draw_text(cr, name, position, bold=True)

        self._component.on_draw(app, cr)
コード例 #2
0
    def Activate(self, actor, current_map, cursor, actors):
        self.font = pygame.font.Font(None, 18)
        self.actor = actor
        self.actors = actors
        self.actor_positions = []
        for a in actors:
            self.actor_positions.append(a.pos)
        self.cursors = [cursor]
        if actor.character.e_weapon.attack_range == 1:
            self.openList, self.ancestry = utils.draw_circle(
                actor, current_map, actors, 2, 1)
            closedList = []
        else:
            self.openList, self.ancestry = utils.draw_circle(
                actor, current_map, actors,
                actor.character.e_weapon.attack_range[1], 1)
            closedList, c_ancestry = utils.draw_circle(
                actor, current_map, actors,
                actor.character.e_weapon.attack_range[0], 1)
        for spot in range(1, len(self.openList)):
            if not (self.openList[spot] in closedList):
                cursor = map_structs.Red_Cursor(80, 2, [])
                [cursor.pos[0], cursor.pos[1]] = self.openList[spot]
                self.cursors.insert(0, cursor)

        self.active = 1
コード例 #3
0
ファイル: wire_tool.py プロジェクト: kjohns19/circuits
    def draw(self, app, cr, mouse_pos):
        if self._input is None:
            return

        display = self._input.component.display
        node_pos = display.node_pos(input=True, idx=self._input.index)
        end_pos = app.snap_position(mouse_pos)

        positions = [node_pos] + self._wire_positions + [end_pos]
        color = (0, 0, 0)
        utils.draw_lines(cr, positions, color)
        for pos in self._wire_positions:
            utils.draw_circle(cr, pos, 2, color, color)
コード例 #4
0
    def draw(self):
        super().draw()
        if self.waffle is not None:
            self.waffle.draw()
            utils.draw_circle(self.center()[0],
                              self.center()[1],
                              radius=(constants.CENTER_RADIUS * self.width) //
                              2,
                              color=colors.yellow)
            utils.draw_circle(self.center()[0],
                              self.center()[1],
                              radius=(constants.MIDDLE_RADIUS * self.width) //
                              2,
                              color=colors.yellow)

        for topping in self.toppings:
            topping.draw()
コード例 #5
0
    def draw_input_wires(self, app, cr):
        inputs = self._component.inputs

        for input_idx, input in enumerate(inputs):
            output = input.connected_output
            if output is None:
                continue

            component = output.component
            output_idx = output.index

            input_pos = self.node_pos(True, input_idx)
            output_pos = component.display.node_pos(False, output_idx)
            positions = [input_pos] + input.wire_positions + [output_pos]

            color = _wire_color(input.new_value)
            utils.draw_lines(cr, positions, color)
            for pos in input.wire_positions:
                utils.draw_circle(cr, pos, 2, color, color)
コード例 #6
0
 def Activate(self, actor, current_map, cursor, actors):
     self.cursors = [cursor]
     self.openList, self.ancestry = utils.draw_circle(
         actor, current_map, actors, actor.character.speed)
     for spot in self.openList:
         cursor = map_structs.Blue_Cursor(80, 2, [])
         [cursor.pos[0], cursor.pos[1]] = spot
         self.cursors.insert(0, cursor)
     self.active = 1
     self.actor = actor
     self.actors = actors
コード例 #7
0
def main():
    args = parse_args()

    image = utils.load_image(args.file)
    output_image, lines_eq, lines_points, lines_class = detect_lines(
        image, use_original=True)

    rectangles = Rectangle_finder.search(lines_eq, lines_points, lines_class)
    print(rectangles)
    for points in rectangles:
        print()
        output_image = utils.draw_circle(output_image, *points)

    utils.show_image(output_image)
コード例 #8
0
def demo_test(text_model, image_model, label_dict, label_dict_en):
    """
    获取验证码图片、模型识别、提交
    :return:
    """
    image_path = utils.download_captcha()
    raw_texts, raw_images = utils.process_raw_images(
        image_path, (image_shape[0], image_shape[1]))
    utils.save_name(raw_texts[0], demo_path, 'text')
    for i, img in enumerate(raw_images):
        utils.save_name(raw_images[i], demo_path, i)

    shutil.copy(image_path, os.path.join(demo_path, 'demo.png'))

    images = np.array([np.asarray(image) for image in raw_images])
    image_predict = image_model.predict(images)
    image_result = np.argmax(image_predict, 1)
    image_prob = np.max(image_predict, 1)

    image_label = [label_dict[r].replace("\xa0", "") for r in image_result]
    image_label_en = [label_dict_en[r] for r in image_result]
    text_label = GoogleLens.get_target_text(image_path)

    print(text_label)
    print(image_label)
    print(image_label_en)

    ids = set()
    for id, r2 in enumerate(image_label):
        if text_label == r2:
            ids.add(id)

    if len(ids) == 0:
        txt, score = process.extractOne(text_label, image_label)
        print(text_label, txt)
        text_label = txt
        for id, r2 in enumerate(image_label):
            if txt == r2:
                ids.add(id)

    result = utils.submit_captcha(ids)
    utils.draw_circle(ids, demo_path, 'demo.png')

    label = {}
    for i, l in enumerate(image_label):
        label[i] = {}
        label[i]['cn'] = l
        label[i]['en'] = image_label_en[i]

    dict = {}
    dict['text_label'] = text_label
    dict['text_label_en'] = utils.find_en_word(image_label, image_label_en,
                                               text_label)
    #     translate.translate(text_label)
    dict['label'] = label
    if "成功" in result:
        dict['result'] = True
    else:
        dict['result'] = False
    with open(os.path.join(demo_path, 'file.txt'), 'w') as file:
        file.write(json.dumps(dict, indent=4, ensure_ascii=False))
コード例 #9
0
            cy = im.size[1]/2
            for box in boxes:
                x1 = int(box[0])
                y1 = int(box[1])
                x2 = int(box[2])
                y2 = int(box[3])
                le_x = int(box[5])
                le_y = int(box[6])
                re_x = int(box[7])
                re_y = int(box[8])
                n_x = int(box[9])
                n_y = int(box[10])
                lm_x = int(box[11])
                lm_y = int(box[12])
                rm_x = int(box[13])
                rm_y = int(box[14])
                print((x1, y1, x2, y2))
                print("conf:",box[4])
                #draw bounding boxes and landmark
                imDraw.rectangle((x1, y1, x2, y2), outline='red')
                imDraw.ellipse((utils.draw_circle(le_x, le_y)), fill='red')
                imDraw.ellipse((utils.draw_circle(re_x, re_y)), fill='red')
                imDraw.ellipse((utils.draw_circle(n_x, n_y)), fill='blue')
                imDraw.ellipse((utils.draw_circle(lm_x, lm_y)), fill='green')
                imDraw.ellipse((utils.draw_circle(rm_x, rm_y)), fill='green')

            im.save(os.path.join(output_path,i))