-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVid2JPG.py
65 lines (50 loc) · 2.03 KB
/
Vid2JPG.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
60
61
62
63
64
65
from tkinter import filedialog, messagebox
from tkinter.ttk import *
from tkinter import *
import cv2
import os
import time
filePath = ""
outputFolderPath = ""
def selectVideo():
global filePath
filePath = filedialog.askopenfilename(initialdir="C:\\", title="Select input-file", filetypes=(("input-file", "*.mp4 *.avi *.wmv"), ("all files", "*.*")))
print("Selected Video: \t" + filePath)
def selectOutputFolder():
global outputFolderPath
outputFolderPath = filedialog.askdirectory(title="Select output folder")
print("Selected Folder: \t" + outputFolderPath)
def convertVideoToImages():
global filePath
while filePath is "":
selectVideo()
video = cv2.VideoCapture(filePath)
numberOfFrames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
date = time.strftime("%d-%m-%Y")
localTime = time.strftime("%H-%M-%S")
timedOutputFolderPath = outputFolderPath + "/" + date + "_" + localTime
print("Final Output-Folder: \t" + timedOutputFolderPath)
if not os.path.exists(timedOutputFolderPath):
os.makedirs(timedOutputFolderPath)
success,image = video.read()
i = 0
success = True
while success:
success,image = video.read()
if(success):
cv2.imwrite(timedOutputFolderPath + "/" + "frame%d.jpg" % i, image)
progress['value'] = int((i / numberOfFrames) * 100)
progress.update_idletasks()
if cv2.waitKey(10) == 27:
break
i += 1
else:
sys.exit()
Label(text="Video:", width=20).grid(row=0,column=0)
Button(text="Select", command=selectVideo, width=10).grid(row=0, column=1)
Label(text="Output-Folder:", width=20).grid(row=1, column=0)
Button(text="Select", command=selectOutputFolder, width=10).grid(row=1, column=1)
Button(text="Start", command=convertVideoToImages, width=10).grid(row=2, column=0)
progress = Progressbar(orient = HORIZONTAL, length=100, mode = 'determinate')
progress.grid(row=2, column=1)
mainloop()