-
Notifications
You must be signed in to change notification settings - Fork 0
/
obs_capture.py
48 lines (41 loc) · 1.26 KB
/
obs_capture.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
import cv2 as cv
class OBSCapture:
def __init__(self):
self.cap = cv.VideoCapture(0)
if not self.cap.isOpened():
raise Exception("Cannot open camera")
self.cap.set(cv.CAP_PROP_FRAME_WIDTH, 1546)
self.cap.set(cv.CAP_PROP_FRAME_HEIGHT,1080)
self.cap.set(cv.CAP_PROP_BUFFERSIZE, 2)
def reset_windows_pos(self):
pass
def capture(self):
while True:
ret, frame = self.cap.read()
if not ret:
break
frame = cv.copyMakeBorder(frame,
60,
0,
0,
0,
cv.BORDER_CONSTANT,
value=(255, 255, 255))
yield frame
if __name__ == '__main__':
import time
import datetime
screen_capture = OBSCapture()
last_time = 0
for frame in screen_capture.capture():
# print('fps = %.1f' % (1 / (time.time() - last_time)))
# last_time = time.time()
cv.imshow("view", frame)
key_code = cv.waitKey(1) & 0xFF
if key_code == ord("q"):
cv.destroyAllWindows()
break
elif key_code == ord("s"):
cv.imwrite(
'data/raw/%s.png' %
datetime.datetime.now().isoformat().replace(':', '.'), frame)