This notebook is a function for getting image from video.notebook below have two part: function part and example part.

Function define part

def gdown_unzip(id, filename):
    """download a zipfile and unzip it under data directory
    """
    dataset_url = 'https://drive.google.com/u/1/uc?id=' + id
    dataset_name = filename

    if not os.path.isdir(dataset_name):
        gdown.download(dataset_url, output = dataset_name + '.zip', quiet=False)
        zip_file = ZipFile( dataset_name + '.zip')
        #zip_file.extractall()
        zip_file.extractall() # depends on how to zip it
        zip_file.close()

get_images_from_video[source]

get_images_from_video(video_name, time_F)

open and read video,then save the images of video depending on the parameter(time_F) you setup.

Testing example

we will move to 'data' directory to start all examples, this directory have been added to '.gitignoe' , so is convenient to test in local and light in cloud

cd data
/home/arg/arg_robotics_tools/data

gdown_unzip(id, filename)

id is the google drive id, filename is your filename in google drive (should be a .zip file )

id = '1YVXSOUB9sb1hCD64oLZtTJrSIdZqTetQ'
filename = 'wamv_5_16'
gdown_unzip(id, filename)
print("\n Finished downloading.")
Downloading...
From: https://drive.google.com/u/1/uc?id=1YVXSOUB9sb1hCD64oLZtTJrSIdZqTetQ
To: /home/arg/arg_robotics_tools/data/wamv_5_16.zip
100%|███████████████████████████████████████████████████████████████████████████████████| 138M/138M [00:13<00:00, 10.3MB/s]
 Finished downloading.

Create file 'output'

mkdir output

function calling

we can simply call get_images_from_video to get the images.
input: time_F, video
output: images capture from the video
time_F can change the number of output image

time_F = 500
video_name = 'wamv_5_16.mp4' 
video_images = get_images_from_video(video_name, time_F) 
for i in range(0, len(video_images)): 
    cv2.imwrite('/home/arg/arg_robotics_tools/data/output/%dout.jpg'%i,video_images[i])

print("\n Finished.")
 Finished.