# -*- coding: utf-8 -*-
"""


将视频分解为图片
decompose each video into images by hand !!!!!!


calib.mp4 -> ./calib_jpg/0001.jpg
             ./calib_jpg/0002.jpg
             ...


The original image size is too large, and there is no need 
to write them in folder.
The size of the input image required by the network is 416 x 128.

1.mp4 -> ./dataset/video1/000005.jpg
         ./dataset/video1/000010.jpg
         ...

2.mp4 -> ./dataset/video2/000005.jpg
         ./dataset/video2/000010.jpg
         ...

...

"""

import numpy as np
import cv2

# cap = cv2.VideoCapture("./video/calib.mp4")
cap = cv2.VideoCapture("./video/1.mp4")


N=100
i = 0
while True:
    i += 1
    ret, frame = cap.read()
    if ret is False or i == N-1:
        break
    
    #cv2.imshow("image", frame)
    #cv2.waitKey(10)
    
    # if i%20 == 0:  # calib.mp4
    #     print("i:", i)
    #     cv2.imwrite("./calib_jpg/"  + str('%04d'%i) + ".jpg", frame)

    if i%5 == 0:
        print("i:", i)
        resized_frame = cv2.resize(frame, (416, 128), interpolation=cv2.INTER_AREA)
        cv2.imwrite("./dataset/video1/"  + str('%04d'%i) + ".jpg", resized_frame)
        
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.') 
if int(major_ver)  < 3 :
    fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
    print ("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))
else :
    fps = cap.get(cv2.CAP_PROP_FPS)
    print ("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))

cap.release()
cv2.destroyAllWindows()