-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo_live_generator.py
46 lines (34 loc) · 1.28 KB
/
video_live_generator.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
import cv2
import numpy as np
import subprocess
class VideoLiveGenerator:
def __init__(self, input_port):
self.input_port = input_port
self.input = cv2.VideoCapture(int(input_port))
self.set_camera_settings(str(input_port))
self.input.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
self.input.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
frame = self.get_frame()
self.SCREEN_HEIGHT, self.SCREEN_WIDTH = frame.shape[:2]
self.H_FIELD_OF_VIEW = 68.37
self.V_FIELD_OF_VIEW = 41.21
def __enter__(self):
return self
def set_camera_settings(self, camera_port):
camera_path = "/dev/video" + camera_port
try:
subprocess.call(["v4l2-ctl", "-d", camera_path, "-c", "exposure_auto=1"])
subprocess.call(["v4l2-ctl", "-d", camera_path, "-c", "exposure_absolute=1"])
except FileNotFoundError:
print("exposure adjustment not completed")
def get_frame(self):
_, frame = self.input.read()
frame = np.rot90(frame, 3).copy()
return frame
def get_horizontal_fov(self):
return self.H_FIELD_OF_VIEW
def get_vertical_fov(self):
return self.V_FIELD_OF_VIEW
def generate(self):
frame = self.get_frame()
return frame, None