Ejemplo n.º 1
0
 def _draw_indicator(self,
                     src,
                     center,
                     color=(255, 0, 0),
                     shape='circle',
                     size=4,
                     thickness=-1):
     """
         convenience function for drawing indicators
     """
     if isinstance(center, tuple):
         center = new_point(*center)
     r = size
     if shape == 'rect':
         draw_rectangle(src,
                        center.x - r / 2.,
                        center.y - r / 2.,
                        r,
                        r,
                        color=color,
                        thickness=thickness)
     elif shape == 'crosshairs':
         draw_lines(src, [[(center.x - size, center.y),
                           (center.x + size, center.y)],
                          [(center.x, center.y - size),
                           (center.x, center.y + size)]],
                    color=color,
                    thickness=1)
     else:
         draw_circle(src, center, r, color=color, thickness=thickness)
Ejemplo n.º 2
0
    def _circle_minimization(self, src, target, dim):
        """
            find cx,cy of a circle with r radius using the arc center method

            only preform if target has high convexity
            convexity is simply defined as ratio of area to convex hull area

        """
        tol = 0.8
        if target.convexity > tol:
            self.info('doing circle minimization radius={}'.format(dim))
            tx, ty = self._get_frame_center(src)
            pts = target.poly_points
            pts[:, 1] = pts[:, 1] - ty
            pts[:, 0] = pts[:, 0] - tx
            dx, dy = approximate_polygon_center(pts, dim)
            cx, cy = dx + tx, dy + ty
            dy = -dy

            self._draw_indicator(src, (cx, cy),
                                 color=(255, 0, 128),
                                 shape='crosshairs')
            draw_circle(src, (cx, cy), int(dim), color=(255, 0, 128))

        else:
            dx, dy = self._calculate_error([target])

        return dx, dy
Ejemplo n.º 3
0
    def _draw_targets(self, src, targets, dim):
        '''
            draw a crosshairs indicator
        '''

        wh = get_size(src)
        for ta in targets:
            pt = new_point(*ta.centroid)
            self._draw_indicator(src,
                                 pt,
                                 color=(0, 255, 0),
                                 size=10,
                                 shape='crosshairs')
            draw_circle(
                src,
                pt,
                radius=int(dim)
                #                         color=color,
                #                         thickness=1
            )
            #             im = zeros(wh)
            #             points = asarray(ta.poly_points)
            #
            #             rr, cc = polygon(*points.T)
            #             im[cc, rr] = 255
            #
            #             cx, cy = center_of_mass(im)
            #             pt = new_point(cy, cx)
            #             self._draw_indicator(pychron, pt,
            #                                  color=(0, 255, 255),
            #                                  size=10,
            #                                  shape='crosshairs')
            draw_polygons(src, [ta.poly_points])
Ejemplo n.º 4
0
    def _circle_minimization(self, src, target, dim):
        """
            find cx,cy of a circle with r radius using the arc center method

            only preform if target has high convexity
            convexity is simply defined as ratio of area to convex hull area

        """
        tol = 0.8
        if target.convexity > tol:
            self.info('doing circle minimization radius={}'.format(dim))
            tx, ty = self._get_frame_center(src)
            pts = target.poly_points
            pts[:, 1] = pts[:, 1] - ty
            pts[:, 0] = pts[:, 0] - tx
            dx, dy = approximate_polygon_center(pts, dim)
            cx, cy = dx + tx, dy + ty
            dy = -dy

            self._draw_indicator(src, (cx, cy), color=(255, 0, 128),
                                 shape='crosshairs')
            draw_circle(src, (cx, cy), int(dim), color=(255, 0, 128))

        else:
            dx, dy = self._calculate_error([target])

        return dx, dy
Ejemplo n.º 5
0
    def _draw_targets(self, src, targets, dim):
        '''
            draw a crosshairs indicator
        '''

        wh = get_size(src)
        for ta in targets:
            pt = new_point(*ta.centroid)
            self._draw_indicator(src, pt,
                                 color=(0, 255, 0),
                                 size=10,
                                 shape='crosshairs')
            draw_circle(src, pt,
                        radius=int(dim)
#                         color=color,
#                         thickness=1
                        )
#             im = zeros(wh)
#             points = asarray(ta.poly_points)
#
#             rr, cc = polygon(*points.T)
#             im[cc, rr] = 255
#
#             cx, cy = center_of_mass(im)
#             pt = new_point(cy, cx)
#             self._draw_indicator(pychron, pt,
#                                  color=(0, 255, 255),
#                                  size=10,
#                                  shape='crosshairs')
            draw_polygons(src, [ta.poly_points])
Ejemplo n.º 6
0
    def _draw_center_indicator(self, src, color=(0, 0, 255), shape='crosshairs',
                               size=10, radius=1):
        """
            draw indicator at center of frame
        """
        cpt = self._get_frame_center(src)
        self._draw_indicator(src, new_point(*cpt),
                             #                             shape='crosshairs',
                             shape=shape,
                             color=color,
                             size=size)

        draw_circle(src, cpt, radius, color=color, thickness=1)
Ejemplo n.º 7
0
    def _draw_center_indicator(self,
                               src,
                               color=(0, 0, 255),
                               shape='crosshairs',
                               size=10,
                               radius=1):
        """
            draw indicator at center of frame
        """
        cpt = self._get_frame_center(src)
        self._draw_indicator(
            src,
            new_point(*cpt),
            #                             shape='crosshairs',
            shape=shape,
            color=color,
            size=size)

        draw_circle(src, cpt, radius, color=color, thickness=1)
Ejemplo n.º 8
0
 def _draw_indicator(self, src, center, color=(255, 0, 0), shape='circle', size=4, thickness=-1):
     '''
         convenience function for drawing indicators
     '''
     if isinstance(center, tuple):
         center = new_point(*center)
     r = size
     if shape == 'rect':
         draw_rectangle(src, center.x - r / 2., center.y - r / 2., r, r,
                        color=color,
                        thickness=thickness)
     elif shape == 'crosshairs':
         draw_lines(src,
                [[(center.x - size, center.y),
                 (center.x + size, center.y)],
                 [(center.x, center.y - size),
                  (center.x, center.y + size)]],
                    color=color,
                    thickness=1
                )
     else:
         draw_circle(src, center, r, color=color, thickness=thickness)