detach render FPS from frame emit

This commit is contained in:
Ruben van de Ven 2024-06-20 12:32:05 +02:00
parent 7f1c3d86f7
commit 531d61b69a
2 changed files with 28 additions and 12 deletions

View file

@ -148,10 +148,11 @@ class FrameEmitter:
if str(video_path).isdigit():
# numeric input is a CV camera
video = cv2.VideoCapture(int(str(video_path)))
# TODO: make config variables
video.set(cv2.CAP_PROP_FRAME_WIDTH, int(1280))
video.set(cv2.CAP_PROP_FRAME_HEIGHT, int(720))
print("exposure!", video.get(cv2.CAP_PROP_AUTO_EXPOSURE))
video.set(cv2.CAP_PROP_FPS, 1)
video.set(cv2.CAP_PROP_FPS, 5)
else:
video = cv2.VideoCapture(str(video_path))
fps = video.get(cv2.CAP_PROP_FPS)

View file

@ -125,18 +125,33 @@ class Renderer:
def run(self):
frame = None
prediction_frame = None
i=0
first_time = None
while self.is_running.is_set():
i+=1
zmq_ev = self.frame_sock.poll(timeout=2000)
if not zmq_ev:
# when no data comes in, loop so that is_running is checked
continue
frame: Frame = self.frame_sock.recv_pyobj()
# zmq_ev = self.frame_sock.poll(timeout=2000)
# if not zmq_ev:
# # when no data comes in, loop so that is_running is checked
# continue
try:
frame: Frame = self.frame_sock.recv_pyobj(zmq.NOBLOCK)
except zmq.ZMQError as e:
idx = frame.index if frame else "NONE"
logger.debug(f"reuse video frame {idx}")
else:
logger.debug(f'new video frame {frame.index}')
if frame is None:
# might need to wait a few iterations before first frame comes available
time.sleep(.1)
continue
try:
prediction_frame: Frame = self.prediction_sock.recv_pyobj(zmq.NOBLOCK)
except zmq.ZMQError as e:
@ -145,7 +160,7 @@ class Renderer:
if first_time is None:
first_time = frame.time
decorate_frame(frame, prediction_frame, first_time, self.config)
img = decorate_frame(frame, prediction_frame, first_time, self.config)
img_path = (self.config.output_dir / f"{i:05d}.png").resolve()
@ -153,11 +168,11 @@ class Renderer:
logger.debug(f"write frame {frame.time - first_time:.3f}s")
if self.out_writer:
self.out_writer.write(frame.img)
self.out_writer.write(img)
if self.streaming_process:
self.streaming_process.stdin.write(frame.img.tobytes())
self.streaming_process.stdin.write(img.tobytes())
if self.config.render_window:
cv2.imshow('frame',frame.img)
cv2.imshow('frame',img)
cv2.waitKey(1)
logger.info('Stopping')
@ -188,8 +203,8 @@ def decorate_frame(frame: Frame, prediction_frame: Frame, first_time: float, con
# Fill image with red color(set each pixel to red)
overlay[:] = (130, 0, 75)
frame.img = cv2.addWeighted(frame.img, .4, overlay, .6, 0)
img = frame.img
img = cv2.addWeighted(frame.img, .4, overlay, .6, 0)
# img = frame.img.copy()
# all not working:
# if i == 1: