コード例 #1
0
    def _load_frame_by_date(self, date: datetime):
        """
        Assume that frames are organized
        """
        min_delta = -1
        logger.debug('Loading frame by date')
        found = False

        # Improves processing time
        self._last_index += 1
        selected_frame = None

        if self._last_index < len(self._frame_info):
            frame = self._frame_info[self._last_index]
            ticks = frame[1]

            date_frame = ClassUtils.ticks_to_datetime(ticks)
            delta = (date - date_frame).seconds

            if 0 <= delta <= 0.5:
                selected_frame = frame
                found = True

        # Iterate over all elems
        if selected_frame is None:
            for index, frame in enumerate(self._frame_info):
                ticks = frame[1]

                date_frame = ClassUtils.ticks_to_datetime(ticks)
                delta = (date - date_frame).total_seconds()

                if min_delta == -1 or delta < min_delta:
                    if 0 <= delta <= 0.5:
                        min_delta = delta
                        selected_frame = frame
                        self._last_index = index
                        found = True

        # Get last if not found
        if selected_frame is None:
            selected_frame = self._last_frame
            found = False

        # Add found variable to dir
        selected_frame[2]['found'] = found

        self._last_frame = selected_frame
        return selected_frame
コード例 #2
0
def main():
    print('Initializing main function')

    ticks = 636764878330000000
    print('Converting ticks: {0}'.format(ticks))

    converted_date = ClassUtils.ticks_to_datetime(ticks)
    print('Date converted: {0}'.format(converted_date))

    print('Done!')
コード例 #3
0
def main():
    print('Initializing main function')

    date = datetime(2018, 2, 1, 12, 0, 0, 4563)
    print('Date: {0}'.format(date))
    ticks = ClassUtils.datetime_to_ticks(date)

    print('Ticks: {0}'.format(ticks))

    new_date = ClassUtils.ticks_to_datetime(ticks)
    print('New datetime: {0}'.format(new_date))

    print('Done!')
コード例 #4
0
def main():
    print('Initializing main function')

    print('Select file to open')
    Tk().withdraw()

    init_dir = '/home/mauricio/Videos/Oviedo/2018-10-30/'
    filename, list_frames = load_video_info(init_dir)

    # Creating window to show frames
    print(
        'Press any button to continue, esc to quit, s to save, c to change file'
    )

    cv2.namedWindow('main_window', cv2.WND_PROP_AUTOSIZE)

    index = 0
    while True:
        frame_info = list_frames[index]
        frame_bin = frame_info[0]
        ticks = frame_info[1]

        date_frame = ClassUtils.ticks_to_datetime(ticks)
        print('Date Frame: {0}'.format(date_frame))

        image_np = np.frombuffer(frame_bin, dtype=np.uint8)
        frame = cv2.imdecode(image_np, cv2.IMREAD_ANYCOLOR)

        print('Showing frame {0} of {1}'.format(index, len(list_frames)))
        cv2.imshow('main_window', frame)

        key = cv2.waitKey(0)
        print('Key pressed: {0}'.format(key))

        if key == 52:
            # Left arrow
            index -= 1
            if index < 0:
                index = 0
        elif key == 54:
            # Right arrow
            index += 1
            if index == len(list_frames):
                index = len(list_frames) - 1
        elif key == 27:
            # Esc
            break
        elif key == 115:
            # s
            print('Saving image')

            init_dir = '/home/mauricio/Pictures/Poses'
            options = {'initialdir': init_dir, 'defaultextension': '.jpg'}
            file_image = asksaveasfilename(**options)

            if not file_image:
                print('Filename not selected')
            else:
                print('Saving image in {0}'.format(file_image))
                cv2.imwrite(file_image, frame)
                # Bug OpenCV
                cv2.destroyAllWindows()
                cv2.namedWindow('main_window', cv2.WND_PROP_AUTOSIZE)

        elif key == 99:
            cv2.destroyAllWindows()
            dir_name = os.path.dirname(filename)
            print('Last processed video: {0}'.format(filename))
            filename, list_frames = load_video_info(dir_name)

            # Creating window to show frames
            print(
                'Press any button to continue, esc to quit, s to save, c to change file'
            )
            cv2.namedWindow('main_window', cv2.WND_PROP_AUTOSIZE)
            index = 0
        else:
            print('Key not selected')

    print('Done!')