Added fps_limit passing in. Improved sub win. Modified rgc and rng dev approproately.

This commit is contained in:
SimLeek
2018-01-20 10:57:16 -07:00
parent b22441e306
commit a66dd0f05e
4 changed files with 15 additions and 69 deletions
+6 -4
View File
@@ -9,9 +9,10 @@ if False:
def frame_handler_loop(cam_id, # type: Union[int, str]
frame_handler, # type: Callable[[int, np.ndarray], Any]
request_size=(1280, 720) # type: Tuple[int, int]
request_size=(1280, 720), # type: Tuple[int, int]
fps_limit = 60
):
t = pub_cam_thread(cam_id, request_size)
t = pub_cam_thread(cam_id, request_size, fps_limit)
sub_cam = pubsub.subscribe("cvcams." + str(cam_id) + ".vid")
sub_owner = pubsub.subscribe("cvcamhandlers." + str(cam_id) + ".cmd")
msg_owner = ''
@@ -26,8 +27,9 @@ def frame_handler_loop(cam_id, # type: Union[int, str]
def frame_handler_thread(cam_id, # type: Union[int, str]
frame_handler, # type: Callable[[int, np.ndarray], Any]
request_size=(1280, 720) # type: Tuple[int, int]
request_size=(1280, 720), # type: Tuple[int, int]
fps_limit = 60
): # type: (...) -> threading.Thread
t = threading.Thread(target=frame_handler_loop, args=(cam_id, frame_handler, request_size))
t = threading.Thread(target=frame_handler_loop, args=(cam_id, frame_handler, request_size, fps_limit))
t.start()
return t
+3 -2
View File
@@ -44,10 +44,11 @@ def pub_cam_loop(cam_id, # type: Union[int, str]
return True
def pub_cam_thread(cam_id, # type: Union[int, str]
request_ize=(1280, 720) # type: Tuple[int, int]
request_ize=(1280, 720), # type: Tuple[int, int]
fps_limit = 60
):
# type: (...) -> threading.Thread
t = threading.Thread(target=pub_cam_loop, args=(cam_id, request_ize))
t = threading.Thread(target=pub_cam_loop, args=(cam_id, request_ize, fps_limit))
t.start()
return t
-52
View File
@@ -1,52 +0,0 @@
import numpy as np
import cv2
#todo: add dshow, v4l
if False: # don't include if actually running
from typing import List, Tuple
def make_camlist(): # type: () -> List[cv2.VideoCapture]
cam_list = [] # type: List[cv2.VideoCapture]
while len(cam_list) == 0 or cam_list[-1].isOpened():
cam_list.append(cv2.VideoCapture(len(cam_list)))
return cam_list
def capture_cams(cam_list # type: List[cv2.VideoCapture]
): # type: (...) -> List[np.ndarray]
frame_list = []
for c in range(len(cam_list)):
(ret, frame) = cam_list[c].read() # type: Tuple[bool, np.ndarray ]
if ret is False or not isinstance(frame, np.ndarray):
cam_list[c].release()
cam_list.pop(c)
continue
frame_list.append(frame)
# for i in range(100):
# try:
# print(i, cam_list[c].get(i))
# except:
# break
# exit()
return frame_list
def show_cams(cam_list # type: List[cv2.VideoCapture]
): # type: (...) -> None
while True:
frame_list = capture_cams(cam_list)
for f in range(len(frame_list)):
print(frame_list[f].shape)
cv2.imshow('frame' + str(f), frame_list[f])
if cv2.waitKey(1) & 0xFF == ord('q'):
break
def end_cams(cam_list # type: List[cv2.VideoCapture]
): # type: (...) -> None
for cam in cam_list:
cam.release()
+6 -11
View File
@@ -8,15 +8,16 @@ cvWindows = []
frameDict = {}
# todo: figure out how to get the red x button to work. Try: https://stackoverflow.com/a/37881722/782170
def sub_win_loop(*,
names, # type: List[str]
input_vid_global_names, # type: List[str]
callbacks=(None,)
callbacks=(None,),
input_cams=(0,)
):
global cvWindows
global frameDict
first_run = True
while True:
for i in range(len(input_vid_global_names)):
if input_vid_global_names[i] in frameDict and frameDict[input_vid_global_names[i]] is not None:
@@ -25,16 +26,10 @@ def sub_win_loop(*,
else:
frames = frameDict[input_vid_global_names[i]]
for f in range(len(frames)):
if first_run:
if names[f % len(names)] not in cvWindows:
cvWindows.append(names[f % len(names)])
cv2.namedWindow(names[f % len(names)])
cv2.imshow(names[f % len(names)], frames[f])
if cv2.waitKey(1) & 0xFF == ord('q'):
for name in cvWindows:
for name in names:
cv2.destroyWindow(name)
for n in names:
cam_ctrl.stop_cam(n)
for c in input_cams:
cam_ctrl.stop_cam(c)
return
first_run = False