Exemplo n.º 1
0
    def retrival(self):

        ###########UI###########
        size = bimpy.Vec2(500, 750)
        bimpy.set_next_window_size(size, bimpy.Condition.Once)

        if bimpy.begin_popup_modal('{}: {}'.format(LANG.retrieve, self.select_label)) \
                and self.select_label != '' and self.first_init:

            for idx, file in enumerate(
                    self.r.label2pic[self.select_label.lower()]):
                if idx != 0:
                    bimpy.separator()

                img = self.r.get_thumbnail(file)
                bimpy.text(file)
                bimpy.image(img)

            bimpy.separator()

            if bimpy.button(LANG.retrieve_close):
                bimpy.clode_current_popup()
            bimpy.end_popup()
        ########################

        t = {
            'x': bimpy.get_window_pos().x,
            'y': bimpy.get_window_pos().y,
            'w': bimpy.get_window_size().x,
            'h': bimpy.get_window_size().y,
            'self': self,
        }

        return t
Exemplo n.º 2
0
def draw_window_drawing(ctx, w, h, name, points):

	bimpy.set_next_window_pos(bimpy.Vec2(w + 20, h + 20), bimpy.Condition.Once)
	bimpy.set_next_window_size(bimpy.Vec2(w, h), bimpy.Condition.Once)
	bimpy.begin(name)
	
	window_zero = bimpy.get_window_pos() + bimpy.Vec2(100 + temp_separation_test.value, 100 + temp_separation_test.value)
	window_one = bimpy.get_window_pos() + bimpy.Vec2(w - 100 - temp_separation_test.value, h - 100 - temp_separation_test.value)
	
	bimpy.add_circle_filled(window_zero, 5.0, 0xFF000000 + 0xc88200, 100)
	bimpy.add_circle_filled(window_one, 5.0, 0xFF000000 + 0x4bb43c, 100)

	for x,y in points:
		point = bimpy.get_window_pos() + bimpy.Vec2(x, y)
		bimpy.add_circle_filled(point, 5.0, 0xFF000000 + 0x4bb43c, 100)


	bimpy.slider_float("separation", temp_separation_test, 0.0, 100.0)

	bimpy.end()
Exemplo n.º 3
0
        x = np.matmul(x, scale)
        x = np.matmul(x, rotation)
        x += position
        datapoints.append((x, rotation, position, scale))


axis = x = np.array([[-1, 0], [1, 0], [0, -1], [0, 1]])

while not ctx.should_close():
    ctx.new_frame()

    bimpy.set_next_window_pos(bimpy.Vec2(20, 20), bimpy.Condition.Once)
    bimpy.set_next_window_size(bimpy.Vec2(800, 600), bimpy.Condition.Once)
    bimpy.begin("Drawings")

    window_pos = bimpy.get_window_pos()

    center = bimpy.Vec2(100, 100) + window_pos
    m = 100.0
    for i in range(len(datapoints)):
        (x, R, P, S) = datapoints[i]

        for j in range(x.shape[0]):
            point = bimpy.Vec2(x[j, 0], x[j, 1])
            bimpy.add_circle_filled(point * m + center, 5,
                                    0xAF000000 + colors[i], 100)

        axis_ = np.matmul(axis, S * 2.0)
        axis_ = np.matmul(axis_, R) + P

        bimpy.add_line(center + bimpy.Vec2(axis_[0, 0], axis_[0, 1]) * m,
Exemplo n.º 4
0
            is_autoplay.value = False
        bimpy.same_line()
        if bimpy.button(" Next > (x) ") or bimpy.is_key_released(
                ord('X')) or is_autoplay.value:
            b_i.value += 1

        if display_frame != b_i.value:
            simulate_to_frame(b_i.value)

        bimpy.combo('Label used for annotation', current_label_idx, all_labels)

        img_display_w = bimpy.get_window_content_region_width()
        img_display_h = img_display_w * video_h / video_w

        # Get the zero coordinate of the actual image rendering
        img_display_zero = bimpy.get_cursor_pos() + bimpy.get_window_pos()
        bimpy.image(img_view, bimpy.Vec2(img_display_w, img_display_h))

        # Logic for deleting rects. Click an active rect to make inactive, click to delete.
        delete_rect = None
        for key, r in rect_db[display_frame].items():
            color = 0xFF00FF00 if is_rect_active(r) else 0xFFFFFF00
            x1, y1, x2, y2 = ui_get_screen_rect(r.x1, r.y1, r.x2, r.y2)
            if bimpy.is_mouse_hovering_rect(bimpy.Vec2(x1, y1),
                                            bimpy.Vec2(x2, y2), 0):
                color = 0xFFFFFF00 if is_rect_active(r) else 0xFF0000FF
                is_placing_rect = False
                bimpy.begin_tooltip()
                bimpy.text(r.label)
                bimpy.text('Idx: %d' % r.idx)
                bimpy.end_tooltip()
    def render(self, ctx, windows_info):

        pos = bimpy.Vec2(conf.margin, conf.margin)
        size_min = bimpy.Vec2(conf.min_file_browser_width,
                              ctx.height() - 2 * conf.margin)
        size_max = bimpy.Vec2(conf.max_file_browser_width,
                              ctx.height() - 2 * conf.margin)

        bimpy.set_next_window_pos(pos, bimpy.Condition.Once)
        bimpy.set_next_window_size_constraints(size_min, size_max)

        bimpy.begin(LANG.file_brewswer_ui_title, bimpy.Bool(True),
                    bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.NoMove)

        ###########UI###########
        if bimpy.button(LANG.file_brewswer_ui_refresh) == True:
            self.fb.refresh_file_list()

        bimpy.same_line()
        if bimpy.button(LANG.about) == True:
            bimpy.open_popup(LANG.about)

        # call render about ui
        # print(dir(windows_info['about_ui']))
        windows_info['about_ui']['self'].about()

        for idx, f_name in enumerate(self.fb.file_list):
            # print(self.selected.value)
            if bimpy.selectable(
                    f_name.split('\\')[-1], self.selected.value == idx):
                self.selected.value = idx

                if self.selected.value != -1 and self.selected.value != self.preidx:
                    self.preidx = self.selected.value
                    windows_info['image_shower_ui']['self'].update_pic(f_name)
                    windows_info['meta_info_ui']['self'].update_meta_info(
                        f_name)

        # progress bar
        if not self.fb.q.empty():
            self.process = self.fb.q.get()

            f, d = self.process[-2], self.process[-1]
            # update if new
            if d != {}:
                self.fb.pp.yolo_res[f] = d

            self.process = (self.process[0] + 1, self.process[1])

            if self.process[0] == self.process[1]:
                with open('yolo_res', 'wb') as f:
                    pickle.dump(self.fb.pp.yolo_res, f)

                # build retrieval index
                windows_info['retrival_ui']['self'].init = False

        sz = bimpy.get_window_size()
        bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, sz.y - conf.margin * 2))
        bimpy.push_item_width(sz.x - conf.margin * 3 - 60)

        process = self.process
        bimpy.progress_bar(process[0] / float(process[1]),
                           bimpy.Vec2(0.0, 0.0),
                           "{}/{}".format(process[0], process[1]))

        bimpy.same_line()
        if bimpy.button(LANG.reindex) == True and process[0] == process[1]:
            self.fb.refresh()

        ########################

        t = {
            'x': bimpy.get_window_pos().x,
            'y': bimpy.get_window_pos().y,
            'w': bimpy.get_window_size().x,
            'h': bimpy.get_window_size().y,
            'self': self,
        }

        bimpy.end()

        return t
    def render(self, ctx, windows_info):
        # calculate autoly
        pos = bimpy.Vec2(
            windows_info['file_brewswer_ui']['x'] +
            windows_info['file_brewswer_ui']['w'] + conf.margin,
            windows_info['image_shower_ui']['y'] +
            windows_info['image_shower_ui']['h'] + conf.margin)

        size = bimpy.Vec2(ctx.width() - pos.x - conf.margin,
                          conf.meta_info_height)

        bimpy.set_next_window_pos(pos, bimpy.Condition.Always)
        bimpy.set_next_window_size(size, bimpy.Condition.Always)

        bimpy.begin(
            "", bimpy.Bool(True), bimpy.WindowFlags.NoCollapse
            | bimpy.WindowFlags.NoMove | bimpy.WindowFlags.NoResize
            | bimpy.WindowFlags.NoTitleBar | bimpy.WindowFlags.NoScrollbar)

        ###########UI###########

        if self.meta_info is not None:
            ####LINE1####
            self.meta_info.setdefault('ImageWidth', '')
            self.meta_info.setdefault('ImageLength', '')
            bimpy.text('{}:{}x{}'.format(LANG.meta_size,
                                         self.meta_info['ImageWidth'],
                                         self.meta_info['ImageLength']))
            bimpy.same_line(size.x / 3)

            self.meta_info.setdefault('DateTimeOriginal', '')
            bimpy.text('{}:{}'.format(LANG.meta_date,
                                      self.meta_info['DateTimeOriginal']))
            bimpy.same_line(size.x / 3 * 2)

            self.meta_info.setdefault('Make', '')
            self.meta_info.setdefault('Model', '')
            bimpy.text('{}:{} {}'.format(LANG.meta_device,
                                         self.meta_info['Make'],
                                         self.meta_info['Model']))

            ####LINE2####
            self.meta_info.setdefault('FocalLength', '')
            bimpy.text('{}:{}'.format(LANG.meta_focal_length,
                                      self.meta_info['FocalLength']))
            bimpy.same_line(size.x / 3)

            self.meta_info.setdefault('ExposureTime', '')
            # truncate too high number
            try:
                x, y = self.meta_info['ExposureTime']
                self.meta_info['ExposureTime'] = (x % 1000, y % 1000)
            except:
                pass

            bimpy.text('{}:{}'.format(LANG.meta_exposure_time,
                                      self.meta_info['ExposureTime']))
            bimpy.same_line(size.x / 3 * 2)

            self.meta_info.setdefault('ISOSpeedRatings', '')
            bimpy.text('{}:{}'.format(LANG.meta_ISO_speed_ratings,
                                      self.meta_info['ISOSpeedRatings']))

            ####LINE3####
            bimpy.text('{}:({},{})'.format(LANG.meta_GPS, round(self.lat, 1),
                                           round(self.lon, 1)))
            bimpy.same_line(size.x / 3)

            bimpy.text('{}:{}'.format(LANG.meta_location, self.location))
        ########################

        t = {
            'x': bimpy.get_window_pos().x,
            'y': bimpy.get_window_pos().y,
            'w': bimpy.get_window_size().x,
            'h': bimpy.get_window_size().y,
            'self': self,
        }

        bimpy.end()

        return t
    def render(self, ctx, windows_info):
        # calculate autoly
        self.pos = bimpy.Vec2(
            windows_info['file_brewswer_ui']['x'] +
            windows_info['file_brewswer_ui']['w'] + conf.margin, conf.margin)

        self.size = bimpy.Vec2(
            ctx.width() - self.pos.x - conf.margin,
            ctx.height() - 3 * conf.margin - conf.meta_info_height)

        bimpy.set_next_window_pos(self.pos, bimpy.Condition.Always)
        bimpy.set_next_window_size(self.size, bimpy.Condition.Always)

        bimpy.begin(
            LANG.image_shower_ui_title, bimpy.Bool(True),
            bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.NoMove
            | bimpy.WindowFlags.NoResize
            | bimpy.WindowFlags.HorizontalScrollbar)

        ###########UI###########
        # modal part

        if self.im is not None:
            bimpy.set_cursor_pos(bimpy.Vec2(0.0, conf.margin * 3))
            bimpy.image(self.im)

            # if image is loaded
            if self.labels is not None:
                for i, label in enumerate(self.labels):
                    color = self.COLORS[self.classes.index(label)]

                    # print((self.bbox[i][0], self.bbox[i][1] - 10))

                    # show on the left bottom of the picture
                    bimpy.set_cursor_pos(
                        bimpy.Vec2(self.bbox[i][0] + 10, self.bbox[i][3] + 10))

                    # set style
                    bimpy.push_id_int(i)

                    if conf.show_yolo_confience:
                        bimpy.button(
                            label + ' ' +
                            str(format(self.confidence[i] * 100, '.2f')) + '%')
                    else:
                        bimpy.button(label)

                    if bimpy.is_item_hovered(i):
                        s = "{} ({})\n{}"

                        label = label[0].upper() + label[1:]

                        s = s.format(
                            label,
                            str(format(self.confidence[i] * 100, '.2f')) + '%',
                            LANG.click_to_view_more)

                        bimpy.set_tooltip(s)

                    if bimpy.is_item_active():
                        self.select_label = label

                    bimpy.pop_id()

            # bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, self.size.y - conf.margin * 2))
            bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, conf.margin * 1.5))
            if bimpy.button(LANG.smart_analyse) == True:
                self.object_detection()

            bimpy.same_line()
            bimpy.checkbox(LANG.auto, self.auto)

            ### Resize ###
            bimpy.same_line()
            bimpy.push_item_width(150)
            bimpy.drag_float(LANG.drag, self.scale, 1.0, 10, 1000)
            bimpy.pop_item_width()

            if abs(self.last_scale - self.scale.value) > 4.:
                xx = self.size.x * self.scale.value / 100.
                yy = (self.size.y - 45 - 40) * self.scale.value / 100.

                im = self.i_s.resize(self.raw_im, xx, yy)
                self.now_im = im
                self.set_im(im)

                # set to save computation
                self.last_scale = self.scale.value

        # if selected obj
        if self.select_label != '':
            # print(self.select_label)
            windows_info['retrival_ui'][
                'self'].select_label = self.select_label
            bimpy.open_popup('{}: {}'.format(LANG.retrieve, self.select_label))

            # reset
            self.select_label = ''

        windows_info['retrival_ui']['self'].retrival()

        ########################

        t = {
            'x': bimpy.get_window_pos().x,
            'y': bimpy.get_window_pos().y,
            'w': bimpy.get_window_size().x,
            'h': bimpy.get_window_size().y,
            'self': self,
        }

        bimpy.end()

        return t