Пример #1
0
    def draw(self, img, tracking_units, positions, roi=True):
        """
        Draw results on a frame.

        :param img: the frame that was just processed
        :type img: :class:`~numpy.ndarray`
        :param positions: a list of positions resulting from analysis of the frame by a tracker
        :type positions: list(:class:`~ethoscope.core.data_point.DataPoint`)
        :param tracking_units: the tracking units corresponding to the positions
        :type tracking_units: list(:class:`~ethoscope.core.tracking_unit.TrackingUnit`)
        :return:
        """

        self._last_drawn_frame = img.copy()

        img = self._annotate_frame(self._last_drawn_frame, tracking_units,
                                   positions, roi)

        if self._draw_frames:
            cv2.imshow(self._window_name, self._last_drawn_frame)
            cv2.waitKey(0)

        if self._video_out is None:
            return self._last_drawn_frame

        if self._video_writer is None:
            self._video_writer = cv2.VideoWriter(
                self._video_out, VideoWriter_fourcc(*self._video_out_fourcc),
                self._video_out_fps, (img.shape[1], img.shape[0]))

        self._video_writer.write(self._last_drawn_frame)

        return img
Пример #2
0
    def draw(self, img, t, positions, tracking_units):
        """
        Draw results on a frame.

        :param img: the frame that was just processed
        :type img: :class:`~numpy.ndarray`
        :param t: frame time
        :param positions: a list of positions resulting from analysis of the frame by a tracker
        :type positions: list(:class:`~ethoscope.core.data_point.DataPoint`)
        :param tracking_units: the tracking units corresponding to the positions
        :type tracking_units: list(:class:`~ethoscope.core.tracking_unit.TrackingUnit`)
        :return:
        """
        self._t = t
        self._last_drawn_frame = img.copy()

        self._annotate_frame(self._last_drawn_frame, positions, tracking_units)

        if self._draw_frames:
            cv2.namedWindow(self._window_name,
                            cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO)
            cv2.resizeWindow(self._window_name, self._framesWinSizeX,
                             self._framesWinSizeY)
            cv2.imshow(self._window_name, self._last_drawn_frame)
            cv2.waitKey(1)

        if self._video_out is None:
            return

        if self._video_writer is None:
            self._video_writer = cv2.VideoWriter(
                self._video_out, VideoWriter_fourcc(*self._video_out_fourcc),
                self._video_out_fps, (img.shape[1], img.shape[0]))

        self._video_writer.write(self._last_drawn_frame)