-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
73 lines (67 loc) · 1.74 KB
/
__main__.py
File metadata and controls
73 lines (67 loc) · 1.74 KB
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
'''
Playback a section of your screen.
Useful for sharing PPT (with speaker notes on) over Tencent (VooV) Meeting.
Hit `ESC` or `q` to quit.
Hit `Spacebar` to refresh view.
Click and drag to resize the window.
'''
WINDOW = 'screenCable'
import numpy as np
import cv2
from mss import mss
from time import sleep
drag_state = None
rect = {
'left': 585, 'top': 200,
'width': 1195, 'height': 675,
}
def mouseEvent(event, x, y, flags, param):
global drag_state
if flags == cv2.EVENT_FLAG_LBUTTON:
drag_state = 1
rect['width'] = x
rect['height'] = y
cv2.resizeWindow(WINDOW, x, y)
if event == cv2.EVENT_LBUTTONUP:
drag_state = 2
def main():
global drag_state
drag_state = 2
try:
while True:
session()
sleep(.2)
drag_state = 0
except KeyboardInterrupt:
print('exiting...')
finally:
cv2.destroyAllWindows()
print('ok')
def session():
global drag_state
with mss() as sct:
cv2.imshow(
WINDOW,
np.array(sct.grab(rect)),
)
cv2.setMouseCallback(WINDOW, mouseEvent)
cv2.waitKey(300)
while True:
if drag_state == 0:
cv2.imshow(
WINDOW,
np.array(sct.grab(rect)),
)
key_press = cv2.waitKey(33) & 0xFF
rect['left'], rect[
'top'
], _, __ = cv2.getWindowImageRect(WINDOW)
if key_press in (
ord('q'),
27,
):
raise KeyboardInterrupt
elif key_press == ord(' ') or drag_state == 2:
break
cv2.destroyWindow(WINDOW)
main()