Example #1
0
 def speed(self, *args):
     """Return movement speed in pixel/s."""
     # TODO: Allow for a calibration of the field of view of cameras
     try:
         return geom.distance(self.pos_hist[-2], self.pos_hist[-1])*30.0 if len(self.pos_hist) >= 2 else None
     except TypeError:
         return None
Example #2
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()

        # Draw the numpy array onto the GL frame
        if self.frame is not None and self.frame.img is not None:
            shape = self.frame.img.shape
            # TODO: Flags for horizontal/vertical flipping
            GL.glDrawPixels(shape[1], shape[0], GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
                            np.fliplr(self.frame.img).tostring()[::-1])

        color = (0.5, 0.5, 0.5, 0.5)
        if self.dragging:
            p1 = (self.m_x1, self.m_y1)
            p2 = (self.m_x2, self.m_y2)

            modifiers = QtGui.QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ShiftModifier:
                radius = geom.distance(p1, p2)
                p2_c = (int(p1[0]), p1[1]+radius)
                self.drawCircle((p1, p2_c), color=color, filled=True, num_segments=24)
            elif modifiers == QtCore.Qt.ControlModifier:
                self.drawLine((p1, p2), color=color)
            else:
                self.drawRect((p1, p2), color=color)
#        else:
        self.drawCross((self.m_x1, self.m_y1), 20, color)

        # Process job queue
        self.process_paint_jobs()
Example #3
0
    def velocity(self, elapsedtime):
        """Return movement speed in pixel/ms """
        try:
            if len(self.pos_hist) >= 2:
                if self.pos_hist[-1] is not None and self.pos_hist[
                        -2] is not None:
                    # calculate speed
                    ds = geom.distance(self.pos_hist[-1], self.pos_hist[-2])
                    movdir = geom.angle(
                        self.pos_hist[-1][0] - self.pos_hist[-2][0],
                        self.pos_hist[-1][1] - self.pos_hist[-2][1])  # dx, dy
                    dt = elapsedtime
                    sp = ds / dt

                else:
                    sp = None
                    movdir = None
            else:
                sp = None
                movdir = None

        except TypeError:
            sp = None
            movdir = None
        finally:
            return sp, movdir
Example #4
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()

        # Draw the numpy array onto the GL frame
        if self.frame is not None and self.frame.img is not None:
            shape = self.frame.img.shape
            # TODO: Flags for horizontal/vertical flipping
            GL.glDrawPixels(shape[1], shape[0], GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
                            np.fliplr(self.frame.img).tostring()[::-1])

        color = (0.5, 0.5, 0.5, 0.5)
        if self.dragging:
            p1 = (self.m_x1, self.m_y1)
            p2 = (self.m_x2, self.m_y2)

            modifiers = QtGui.QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ShiftModifier:
                radius = geom.distance(p1, p2)
                p2_c = (int(p1[0]), p1[1] + radius)
                self.drawCircle((p1, p2_c),
                                color=color,
                                filled=True,
                                num_segments=24)
            elif modifiers == QtCore.Qt.ControlModifier:
                self.drawLine((p1, p2), color=color)
            else:
                self.drawRect((p1, p2), color=color)
#        else:
        self.drawCross((self.m_x1, self.m_y1), 20, color)

        # Process job queue
        self.process_paint_jobs()
Example #5
0
 def speed(self, *args):
     """Return movement speed in pixel/s."""
     # TODO: Allow for a calibration of the field of view of cameras
     try:
         return geom.distance(self.pos_hist[-2],
                              self.pos_hist[-1]) * 30.0 if len(
                                  self.pos_hist) >= 2 else None
     except TypeError:
         return None
Example #6
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()
        # Draw the numpy array onto the GL frame
        if self.frame is not None and self.frame.img is not None:
            # Add timestamp to image if from a live source
            if self.spotter.GUI_off:
                self.frame.img = np.zeros(self.frame.img.shape, dtype=np.uint8)
                cv2.putText(img=self.frame.img,
                            text="GUI turned off",
                            org=(15, 20),
                            fontFace=cv2.FONT_HERSHEY_PLAIN,
                            fontScale=1.6,
                            color=(250, 250, 50),
                            thickness=1,
                            lineType=cv2.CV_AA)
            else:
                if self.frame.source_type == 'device':
                    cv2.putText(img=self.frame.img,
                                text=self.frame.time_text,
                                org=(15, 20),
                                fontFace=cv2.FONT_HERSHEY_PLAIN,
                                fontScale=1.6,
                                color=(250, 250, 50),
                                thickness=1)
                    #self.frame.img = cv2.cvtColor(self.frame.img, cv2.COLOR_BGR2HSV)  #for display
                    #contours, hierarchy = cv2.findContours(self.frame.img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
                # cv2.drawContours(self.frame.img, self.spotter.tracker.contour, -1, (0, 255, 0), 3)
            shape = self.frame.img.shape
            # TODO: Flags for horizontal/vertical flipping
            GL.glDrawPixels(shape[1], shape[0], GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
                            np.fliplr(self.frame.img).tostring()[::-1])

        color = (0.5, 0.5, 0.5, 0.5)
        if self.dragging:
            p1 = (self.m_x1, self.m_y1)
            p2 = (self.m_x2, self.m_y2)

            #modifiers = QtGui.QApplication.keyboardModifiers()
            #if modifiers == QtCore.Qt.ShiftModifier:
            if self.spotter.active_shape_type == 'circle':
                radius = geom.distance(p1, p2)
                p2_c = (int(p1[0]), p1[1] + radius)
                self.drawCircle((p1, p2_c),
                                color=color,
                                filled=True,
                                num_segments=24)
        # elif modifiers == QtCore.Qt.ControlModifier:
            elif self.spotter.active_shape_type == 'line':
                self.drawLine((p1, p2), color=color)
            else:
                self.drawRect((p1, p2), color=color)
#        else:
        self.drawCross((self.m_x1, self.m_y1), 20, color)

        # Process job queue
        self.process_paint_jobs()
Example #7
0
 def collision_check_circle(self, point):
     """ Circle points: center point, one point on the circle. Test for
     collision by comparing distance between center and point of object with
     radius.
     """
     distance = geom.distance(self.points[0], point)
     if self.active and (distance <= self.radius):
         return True
     else:
         return False
Example #8
0
 def collision_check_circle(self, point):
     """ Circle points: center point, one point on the circle. Test for
     collision by comparing distance between center and point of object with
     radius.
     """
     distance = geom.distance(self.points[0], point)
     if self.active and (distance <= self.radius):
         return True
     else:
         return False
Example #9
0
    def __init__(self, cnt, last_coord, offset_x, offset_y, range_area):
        try:
            self.cnt=cnt
            self.area = cv2.contourArea(self.cnt.astype(int))
            if self.area<range_area[0]:
                self.cx=None
                self.cy=None
                self.dist=None
                #print "empty area"
            else:
                moment = cv2.moments(cnt.astype(int))
                self.cx = math.ceil(moment['m10'] / moment['m00']) + offset_x
                self.cy = math.ceil(moment['m01'] / moment['m00']) + offset_y
                self.dist = geom.distance(last_coord, (self.cx, self.cy)) if (last_coord is not None) else 0

        except:
            print "error", sys.exc_info()[0]
Example #10
0
 def radius(self):
     """ Calculate the radius of the circle. """
     return geom.distance(self.points[0], self.points[1])
Example #11
0
 def radius(self):
     """ Calculate the radius of the circle. """
     return geom.distance(self.points[0], self.points[1])