Esempio n. 1
0
 def play_image_sequence(self, frame_rate=25):
     """
     plot the images just like a video
     :return:
     """
     frame_duration = 1000 // frame_rate
     for i, img in enumerate(self.left_sequence):
         cv2_imshow('', img)
         cv2_waitKey(frame_duration)
         print('Frame-' + str(i + 1))
Esempio n. 2
0
    def __to_save_img_seq(self, video_capture: VideoCapture, video_name: str):
        # Frame counter
        i = 0

        # To be 100% sure that we get the filename without the extension

        video_name = os_path_splitext(video_name)[0]
        image_sequence_dir = os_path_join(self.im_seqs_dir, video_name)
        while video_capture.isOpened():
            ret, frame = video_capture.read()
            if ret:
                os_makedirs(image_sequence_dir, exist_ok=True)
                if video_name is None:
                    raise Exception(
                        'VideoHandlerError: if video_to_image_sequence receives a "save_sequences=True" then "video_name" must also receive a value. '
                    )
                frame_name = '{0:06}'.format(i + 1) + '_' + video_name + '.jpg'
                # Save image
                cv2_imwrite(os_path_join(image_sequence_dir, frame_name),
                            frame)
                # wait 1ms and make another check before 'breaking'
                if cv2_waitKey(1) & 0xFF == ord('q'):
                    break
                i += 1
            else:
                break

        print('Total frames of sequence read:', i - 1)
Esempio n. 3
0
def pause(time, ground):
    while time >= 1:
        ground[np_shape(ground)[1] / 2 + 70:np_shape(ground)[1] / 2 + 100,
               np_shape(ground)[1] / 2 - 10:np_shape(ground)[1] / 2 +
               40, :] = 255
        cv2_putText(
            ground, str(time),
            (np_shape(ground)[1] / 2 - 5, np_shape(ground)[1] / 2 + 93),
            cv2_FONT_HERSHEY_SIMPLEX, 1, 0)
        cv2_imshow("Tic_Tac_Toe", ground)
        k = cv2_waitKey(1000) & 0xFF
        if k == 27:
            return 1
        elif k != 255:
            return 0
        time -= 1
    return 0
Esempio n. 4
0
    def __play_video(self, video_capture: VideoCapture, frame_rate: int,
                     title: str):
        frame_duration = 1000 // frame_rate
        # Frame counter
        i = 1

        while video_capture.isOpened():
            ret, frame = video_capture.read()
            if ret:
                # display frame
                cv2_imshow(title, frame)
                # wait 40ms and make another check before 'breaking'
                if cv2_waitKey(frame_duration) & 0xFF == ord('q'):
                    break
                i += 1
            else:
                break

        print('Video player:', i, 'consecutive frames were displayed.')
Esempio n. 5
0
    def __to_img_seq(self, video_capture: VideoCapture):
        # Frame counter
        i = 1

        # image sequence
        image_seq = []
        while video_capture.isOpened():
            ret, frame = video_capture.read()
            if ret:
                image_seq.append(frame)
                # wait 1ms and make another check before 'breaking'
                if cv2_waitKey(1) & 0xFF == ord('q'):
                    break
                i += 1
            else:
                break

        print('Total frames of sequence read:', i - 1)

        video_capture.release()
        cv2_destroyAllWindows()

        return np_array(image_seq)
    if name % 100000 == 1:
        d_sub = D_main + "\\" + str(
            (name / 100000) * 100) + str(n_k) + '-' + str(
                (1 + name / 100000) * 100) + 'K'
        #folder(d_sub)
    if name % 10000 == 1:
        d_sub_1 = d_sub + "\\" + str(
            (name / 10000) * 10) + str(n_k) + '-' + str(
                (1 + name / 10000) * 10) + 'K'
        #folder(d_sub_1)
    if name % 1000 == 1:
        d_sub_2 = d_sub_1 + "\\" + str(
            name / 1000) + str(n_k) + '-' + str(1 + name / 1000) + 'K' + direct
        n_k = "K"
        folder(d_sub_2)
    cv2_imwrite(os_path.join(d_sub_2, CATAN + '_' + str(name) + '.PNG'),
                ground)
    #out.write(ground)
    key = cv2_waitKey(1) & 0xFF
    if key == 27:
        break
    elif key == ord('p'):
        k = cv2_waitKey(0) & 0xFF
        if k == 27:
            break

    #t.append(time()-t1)
#print sum(t)/len(t)
cv2_destroyAllWindows()
#out.release()
Esempio n. 7
0
while True:
    player_1 = []
    player_2 = []
    ground = np_ones((dim_y, dim_x, 3)) * 255
    ground = ground.astype('uint8')

    out_lines = lines(ground, dim_x, dim_y)
    out_points = center_points(out_lines)

    for i in xrange(9):
        cv2_putText(ground, str(i + 1),
                    (out_points[i, 1] - 5, out_points[i, 0]),
                    cv2_FONT_HERSHEY_SIMPLEX, 1, 0)
    while True:
        cv2_imshow("Tic_Tac_Toe", ground)
        key = cv2_waitKey(1) & 0xFF
        if key == 27:
            brk = 1
            break
        elif key != 255:
            if key == 9:
                cv2_imwrite('tic_tac_toe.PNG', ground)
            if 49 <= key <= 57:
                turn = fill_pose(ground, out_points, key, turn)
                #cv2_imshow("Tic_Tac_Toe",ground)
                br = winner(ground, turn, key, player_1, player_2)
                cv2_imshow("Tic_Tac_Toe", ground)
                if br == 1 or br == 2:
                    pl1 += (br == 1) * 1
                    pl2 += (br == 2) * 1
                    turn = 1 - turn