def draw_sections(self, width, height, scale):
        t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
        pixel_to_time_fac = height / (t1 - t0)
        with gl_utils.Coord_System(t0, t1, height, 0):
            gl.glTranslatef(0, 0.001 + scale * self.timeline_line_height / 2, 0)
            for s in self.sections:
                cal_slc = slice(*s['calibration_range'])
                map_slc = slice(*s['mapping_range'])
                cal_ts = self.g_pool.timestamps[cal_slc]
                map_ts = self.g_pool.timestamps[map_slc]

                color = cygl_utils.RGBA(*s['color'][:3], 1.)
                if len(cal_ts):
                    cygl_utils.draw_rounded_rect((cal_ts[0], -4 * scale),
                                      (cal_ts[-1] - cal_ts[0], 8 * scale),
                                      corner_radius=0,
                                      color=color,
                                      sharpness=1.)
                if len(map_ts):
                    cygl_utils.draw_rounded_rect((map_ts[0], -scale),
                                      (map_ts[-1] - map_ts[0], 2 * scale),
                                      corner_radius=0,
                                      color=color,
                                      sharpness=1.)

                color = cygl_utils.RGBA(1., 1., 1., .5)
                if s['calibration_method'] == "natural_features":
                    cygl_utils.draw_x([(m['timestamp'], 0) for m in self.manual_ref_positions],
                           height=12 * scale, width=3 * pixel_to_time_fac / scale, thickness=scale, color=color)
                else:
                    cygl_utils.draw_bars([(m['timestamp'], 0) for m in self.circle_marker_positions],
                              height=12 * scale, thickness=scale, color=color)

                gl.glTranslatef(0, scale * self.timeline_line_height, 0)
예제 #2
0
    def gl_display(self):

        if self.output_q.empty():
            pass
        else:
            data = self.output_q.get()
            rect_points = data['rect_points']
            class_names = data['class_names']
            class_colors = data['class_colors']

            height, width, _ = self.frame.shape
            dist_list = []

            for point, name, color in zip(rect_points, class_names,
                                          class_colors):
                #define vertices necessary for drawing bounding boxes
                bottom_left, bottom_right = [
                    point['xmin'], 1 - point['ymax']
                ], [point['xmax'], 1 - point['ymax']]
                top_left, top_right = [point['xmin'], 1 - point['ymin']
                                       ], [point['xmax'], 1 - point['ymin']]
                top_left_label, top_right_label = top_left, [
                    point['xmin'] + len(name[0]) * 14 / width,
                    1 - point['ymin']
                ]
                bottom_left_label, bottom_right_label = [
                    point['xmin'], 1 - (point['ymin'] + 30 / height)
                ], [
                    point['xmin'] + len(name[0]) * 14 / width,
                    1 - (point['ymin'] + 30 / height)
                ]

                center_bb = [(point['xmax'] + point['xmin']) / 2.0,
                             ((1 - point['ymax']) + (1 - point['ymin'])) / 2.0]

                # Distance between gaze point and center of bounding box (center_bb)
                # for pt,a in self.pupil_display_list:
                #     dist = math.hypot(center_bb[0]-pt[0], center_bb[1]-pt[1])
                #     # dist_list.append([dist, top_left[0]*width, (1-top_left[1])*height]) #for drawing text on detected object
                #     dist_list.append([dist, [center_bb[0]*width, (1-center_bb[1])*height], name[0]])

                # Distance between fixation point and center of bounding box (center_bb)
                if self.fixation_norm_pos:
                    dist = math.hypot(center_bb[0] - self.fixation_norm_pos[0],
                                      center_bb[1] - self.fixation_norm_pos[1])
                    dist_list.append([
                        dist,
                        [center_bb[0] * width, (1 - center_bb[1]) * height],
                        name[0]
                    ])

                # Draw bounding box, label box, write label
                verts_label = [
                    top_left_label, top_right_label, bottom_right_label,
                    bottom_left_label, top_left_label
                ]
                verts = [
                    top_left, top_right, bottom_right, bottom_left, top_left
                ]
                draw_polyline_norm(verts,
                                   thickness=5,
                                   color=RGBA(color[2] / 255, color[1] / 255,
                                              color[0] / 255, 1.0))
                draw_polyline_norm(verts_label,
                                   thickness=5,
                                   color=RGBA(color[2] / 255, color[1] / 255,
                                              color[0] / 255, 1.0))

                self.glfont.set_color_float((1.0, 1.0, 1.0, 1.0))
                self.glfont.draw_text(top_left[0] * width,
                                      (1 - top_left[1]) * height, name[0])
                self.glfont.set_align_string(v_align='left', h_align='top')

            # Draw an x on the detected_object closest to the fixation or gaze
            if dist_list:
                draw_x([sorted(dist_list)[0][1]],
                       size=50,
                       thickness=5,
                       color=RGBA(color[2] / 255, color[1] / 255,
                                  color[0] / 255, .5))
                self.label = sorted(dist_list)[0][2]
                label_q.put(self.label)