-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (30 loc) · 1.04 KB
/
main.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
import cv2 as cv
import time
import imutils
import rumps
from threading import Thread
video_path = 'video/bad_apple.mp4'
app = rumps.App("")
def play_video() -> None:
cap = cv.VideoCapture(video_path)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
cap.release()
rumps.quit_application()
return
# Threshold the image then make the background transparent
image = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
image = imutils.resize(image, height=18)
_, image = cv.threshold(src=image, thresh=127,
maxval=255, type=cv.THRESH_BINARY)
image = cv.merge([image.copy(), image.copy(),
image.copy(), image.copy()], 4)
# Write image to file, as rumps currently accepts only an image path
cv.imwrite(img=image, filename='frame.png')
app.icon = 'frame.png'
time.sleep(0.04)
if __name__ == '__main__':
thread = Thread(target=play_video)
thread.start()
app.run()