-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideoFrameConverter_parallel.py
More file actions
66 lines (57 loc) · 2.77 KB
/
videoFrameConverter_parallel.py
File metadata and controls
66 lines (57 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
import argparse
import cv2
import math
import os
import time
from threading import Thread
from os import listdir, makedirs
from os.path import isfile, join, basename, splitext, exists
#NOTE: Videos recorded in 25 fps
#file to convert videos of phonemes into frames in threads
def vid2img(pathTofolder, outputPath, fn):
#this is the folder for letter a # needs to be changed for google drive
video = cv2.VideoCapture(join(pathTofolder,fn))
count = 0
success,image = video.read()
success = True
new_img_folder = splitext(fn)[0]
if new_img_folder == 'aa' or 'ah':
new_img_folder == 'a'
elif new_img_folder == 'eh':
new_img_folder = 'e'
elif new_img_folder == 'ii':
new_img_folder = 'i'
elif new_img_folder == 'oh':
new_img_folder == 'o'
elif new_img_folder == 'uh':
new_img_folder = 'u'
new_path = outputPath + new_img_folder
if not exists(new_path):
os.makedirs(new_path)
while success:
success,image = video.read()
if success == False:
break
print ('Read a new frame: ', success)
cv2.imwrite(new_path + '\\image%d.jpg' % count, image)
count += 1
def executeFrameConversion(pathTofolder, outputPath, fn):
thread = Thread(target = vid2img, args = (pathTofolder, outputPath, fn))
# t1 = Thread(target = vid2img, args = ('C:\\Users\\w & space', 'C:\\Users\\train_data\\raw_imgs_1440x1080\\train_data_raw_4\\', 1))
# t2 = Thread(target = vid2img, args = ('C:\\Users\\w & space', 'C:\\Users\\train_data\\raw_imgs_1440x1080\\train_data_raw_4\\', 2))
# t3 = Thread(target = vid2img, args = ('C:\\Users\\w & space', 'C:\\Users\\train_data\\raw_imgs_1440x1080\\train_data_raw_4\\', 2))
# t4 = Thread(target = vid2img, args = ('C:\\Users\\w & space', 'C:\\Users\\train_data\\raw_imgs_1440x1080\\train_data_raw_4\\', 2))
# t5 = Thread(target = vid2img, args = ('C:\\Users\\w & space', 'C:\\Users\\train_data\\raw_imgs_1440x1080\\train_data_raw_4\\', 2))
# t1.start()
# t2.start()
return thread
def main(pathTofolder, outputPath):
threads = [executeFrameConversion(pathTofolder, outputPath, fn) for fn in listdir(pathTofolder)]
for t in threads:
t.start()
print ('new thread created!')
for t in threads:
t.join()
if __name__ == '__main__':
main(pathTofolder = 'C:\\Users\\AndV2\\and_test', outputPath = 'C:\\Users\\single_evaluation_data\\AndV2\\') # change to necessary data being converted