-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew window.py
79 lines (62 loc) · 2.66 KB
/
new window.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import tkinter
import cv2
import PIL.Image, PIL.ImageTk
from ffpyplayer.player import MediaPlayer
import time
#video_source = '.\output.avi'
class App:
def __init__(self, window, window_title,video_source=0):
self.window = window
self.window.title(window_title)
self.video_source = video_source
self.vid = VideoCapture(video_source)
self.canvas = tkinter.Canvas(window, width = self.vid.width, height = self.vid.height)
self.canvas.pack()
self.btn_record = tkinter.Button(window, text="Recoed", width = 50, command = self.r_start)
self.btn_record.pack(anchor = tkinter.CENTER, expand = True)
#self.btn_record = tkinter.Button(window, text="Snapshot", width = 50, command = self.snapshot)
#self.btn_record.pack(anchor = tkinter.CENTER, expand = True)
self.delay = 15
self.update()
self.window.mainloop()
"""def snapshot(self):
ret,frame = self.vid.get_frame()
if ret:
cv2.imwrite("frame-" + time.strftime("%d-%m-%Y-%H-%M-%S") + ".jpg", cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))"""
def r_start(self, record_state):
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('gg.avi', fourcc, 20.0, (640,480))
while(record_state):
ret,frame = self.vid.get_frame()
right = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out.write(right)
def r_stop(self):
def update(self):
ret, frame = self.vid.get_frame()
if ret:
self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(frame))
self.canvas.create_image(0, 0 ,image = self.photo, anchor = tkinter.NW)
self.window.after(self.delay, self.update)
class VideoCapture:
def __init__(self, video_source=0):
self.vid = cv2.VideoCapture(video_source)
if not self.vid.isOpened():
raise ValueError("Unable to open video source", video_source)
self.width = self.vid.get(cv2.CAP_PROP_FRAME_WIDTH)
self.height = self.vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
def get_frame(self):
if self.vid.isOpened():
ret,frame = self.vid.read()
if ret:
return (ret, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
else:
return(ret, None)
else:
return (ret, None)
def __del__(self):
if self.vid.isOpened():
self.vid.release()
App(tkinter.Tk(), "Trial Player" )
"""r"D:\movie_Making\take0001\flick\world.avi"""
"""top = tkinter.Tk()
top.mainloop()"""