-
Notifications
You must be signed in to change notification settings - Fork 0
/
idiot.pyw
82 lines (64 loc) · 2.3 KB
/
idiot.pyw
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
80
81
82
import cv2
from ffpyplayer.player import MediaPlayer
import random
import string
from win32api import GetSystemMetrics
import subprocess
monitor_x = GetSystemMetrics(0)
monitor_y = GetSystemMetrics(1)
def get_random_string(length):
# choose from all lowercase letter
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str
def set_math(n, direction):
return n + direction
cap = cv2.VideoCapture('./idiot.mp4')
player = MediaPlayer('./idiot.mp4')
val = ''
imshow_name = "Idiot_"+ get_random_string(5)
math_x = random.randrange(0, monitor_x)
math_y = random.randrange(0, monitor_y)
direction_x = random.randrange(15, 50)
direction_y = random.randrange(15, 50)
while(cap.isOpened()):
ret, frame = cap.read()
framee, val = player.get_frame()
if val != 'eof' and framee is not None:
img, t = framee
# display img
#cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
#cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
math_x = set_math(math_x, direction_x)
math_y = set_math(math_y, direction_y)
if math_x > monitor_x or math_x < 0:
if(direction_x > 0):
direction_x = -random.randrange(15, 50)
math_x = math_x + (direction_x + 1)
else:
direction_x = random.randrange(15, 50)
math_x = math_x + (direction_x + 1)
if math_y > monitor_y or math_y < 0:
if(direction_y > 0):
direction_y = -random.randrange(15, 50)
math_y = math_y + (direction_y + 1)
else:
direction_y = random.randrange(15, 50)
math_y = math_y + (direction_y + 1)
if ret:
cv2.imshow(imshow_name, frame)
cv2.moveWindow(imshow_name, math_x, math_y)
print((math_x, math_y))
else:
player.seek(-10)
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
continue
if cv2.waitKey(80) & 0xFF == ord('q'):
subprocess.Popen("cmd /c py idiot.pyw", creationflags=0x08000000)
continue
try:
cv2.getWindowProperty(imshow_name, 0)
except:
subprocess.Popen("cmd /c py idiot.pyw", creationflags=0x08000000)
cap.release()
cv2.destroyAllWindows()