I have added functionality of entering letters during runtime, they are displayed for you viewing pleasure. Additionally, I have began working making the item listed above be pubsub'd and there more useful to all of mankind
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import pubsub
|
||||
|
||||
if False:
|
||||
from typing import Union
|
||||
|
||||
@ -12,5 +13,10 @@ class CamCtrl:
|
||||
|
||||
@staticmethod
|
||||
def reset_vid(cam_id # type: Union[int, str]
|
||||
):
|
||||
):
|
||||
pubsub.publish("cvcamhandlers." + str(cam_id) + ".cmd", 'r')
|
||||
|
||||
@staticmethod
|
||||
def key_stroke(key_entered):
|
||||
pubsub.publish("cvKeyStroke.", key_entered)
|
||||
|
||||
|
@ -1,11 +1,24 @@
|
||||
import cv2
|
||||
from ..webcam_pub.camctrl import CamCtrl
|
||||
|
||||
|
||||
if False:
|
||||
from typing import List
|
||||
|
||||
frame_dict = {}
|
||||
|
||||
def triangle_seen():
|
||||
print("a triangle was seen")
|
||||
def square_seen():
|
||||
print("a square was seen")
|
||||
def nothing_seen():
|
||||
print("nothing was seen")
|
||||
|
||||
command_dict = {
|
||||
"t": triangle_seen,
|
||||
"s": square_seen,
|
||||
" ": nothing_seen
|
||||
}
|
||||
|
||||
# todo: figure out how to get the red x button to work. Try: https://stackoverflow.com/a/37881722/782170
|
||||
def sub_win_loop(
|
||||
@ -25,11 +38,27 @@ def sub_win_loop(
|
||||
frames = frame_dict[input_vid_global_names[i]]
|
||||
for f in range(len(frames)):
|
||||
cv2.imshow(names[f % len(names)]+" (press q to quit)", frames[f])
|
||||
if cv2.getWindowProperty(names[f % len(names)]+" (press q to quit)", 0) != 0:
|
||||
print("X was pressed")
|
||||
for name in names:
|
||||
cv2.destroyWindow(name)
|
||||
for c in input_cams:
|
||||
CamCtrl.stop_cam(c)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
|
||||
key_criteria = cv2.waitKey(1) & 0xFF
|
||||
|
||||
if key_criteria == ord("q"):
|
||||
for name in names:
|
||||
cv2.destroyWindow(name)
|
||||
for c in input_cams:
|
||||
CamCtrl.stop_cam(c)
|
||||
return
|
||||
|
||||
if chr(key_criteria) in command_dict:
|
||||
command_dict[chr(key_criteria)]()
|
||||
CamCtrl.key_stroke(chr(key_criteria))
|
||||
elif chr(key_criteria) != "ÿ":
|
||||
print(chr(key_criteria))
|
||||
|
||||
|
||||
|
@ -2,6 +2,15 @@ import unittest as ut
|
||||
import cv_pubsubs.webcam_pub as w
|
||||
from cv_pubsubs.window_sub import frame_dict, sub_win_loop
|
||||
|
||||
def subscribe_to_key_command(cam_id, # type: Union[int, str]
|
||||
frame_handler, # type: Callable[[int, np.ndarray], Any]
|
||||
request_size=(1280, 720), # type: Tuple[int, int]
|
||||
high_speed=False, # type: bool
|
||||
fps_limit=240 # type: float
|
||||
): # type: (...) -> threading.Thread
|
||||
t = threading.Thread(target=frame_handler_loop, args=(cam_id, frame_handler, request_size, high_speed, fps_limit))
|
||||
t.start()
|
||||
return t
|
||||
|
||||
class TestSubWin(ut.TestCase):
|
||||
|
||||
|
Reference in New Issue
Block a user