-
Notifications
You must be signed in to change notification settings - Fork 6
/
slagalica-batch-video.py
59 lines (49 loc) · 2.68 KB
/
slagalica-batch-video.py
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
import sys
import argparse
import os
import traceback
from datetime import datetime
parser = argparse.ArgumentParser(description="Slagalica videos batch processor",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-srcdir", "--source", help="directory with video files", default="./examples/testVideoBatch")
parser.add_argument("-o", "--output", help="directory for csv and debug data output", default="results")
parser.add_argument("-lang", "--language", help="ocr language, can be either rs_latin or rs_cyrillic", default="rs_cyrillic")
parser.add_argument("-csv", "--csvFileName", help="name for csv file", default="questions.csv")
parser.add_argument("-d", "--debugData", help="create frame image files for every image processed. note: can use up a lot of data space!", default="True")
parser.add_argument("-showt", "--showtime", help="create windows and preview of everything that is happening", default="False")
args = parser.parse_args()
config = vars(args)
directoryWithVideoFiles = config['source']
directoryOutput = config['output']
csvFileName = config['csvFileName']
createDebugData = config['debugData']
language = config['language']
snowtime = config['showtime']
if not os.path.isdir(directoryWithVideoFiles):
print('Incorrect directory for videos: \"%s\"' %directoryWithVideoFiles)
sys.exit(1)
videoFiles = sorted(os.listdir(directoryWithVideoFiles))
totalNumberOfFiles = len(videoFiles)
print("Files directory set to: \"%s\"" %directoryWithVideoFiles)
print("Found %d files to be processed: " %totalNumberOfFiles)
for file in videoFiles:
print(" %s" %file)
start_time = datetime.now()
i = 1
for file in videoFiles:
print()
print("***********************************************************************************")
print("Batch processing \"%s\" file (%d of %d)" %(file, i, totalNumberOfFiles))
# do something
try:
os.system("python slagalica-single-video.py -srcdir \"%s\" -file \"%s\" -o \"%s\" -lang \"%s\" -csv \"%s\" -d %s -showt %s" %(directoryWithVideoFiles, file, directoryOutput, language, csvFileName, createDebugData, snowtime))
except Exception as e:
print("Error occurred during execution at " + str(datetime.now().date()) + " {}".format(datetime.now().time()))
print(traceback.format_exc())
print(e)
i+=1
currentTime = '{}'.format(datetime.now() - start_time)
print("Current cumulative batch processing duration: %s" %currentTime)
print("***********************************************************************************")
currentTime = 'Time: {}'.format(datetime.now() - start_time)
print("Batch processing finished. Total duration: %s" %currentTime)