Merge pull request #47 from SimLeek/reopening
Fixed bug where reopening videos froze the window
This commit is contained in:
@@ -10,7 +10,7 @@ jobs:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
python-version: [3.6, 3.7]
|
||||
python-version: [3.7, 3.8]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
@@ -4,7 +4,7 @@ Display any array, webcam, or video file.
|
||||
display is a function that displays these in their own windows.
|
||||
"""
|
||||
|
||||
__version__ = "1.1.1"
|
||||
__version__ = "1.3.1"
|
||||
|
||||
from .window.subscriber_windows import display, breakpoint_display, read_updates, publish_updates
|
||||
from . import effects
|
||||
|
||||
@@ -147,7 +147,6 @@ def pub_cam_loop_opencv(
|
||||
sub = subscriber_dictionary.cam_cmd_sub(name)
|
||||
sub.return_on_no_data = ""
|
||||
msg = ""
|
||||
|
||||
if mjpg:
|
||||
try:
|
||||
cam.set(cv2.CAP_PROP_FOURCC, cv2.CAP_OPENCV_MJPEG)
|
||||
@@ -174,7 +173,11 @@ def pub_cam_loop_opencv(
|
||||
if frame_counter >= cam.get(cv2.CAP_PROP_FRAME_COUNT):
|
||||
frame_counter = 0
|
||||
cam = cv2.VideoCapture(cam_id)
|
||||
subscriber_dictionary.CV_CAMS_DICT[name].frame_pub.publish(frame)
|
||||
try:
|
||||
subscriber_dictionary.CV_CAMS_DICT[name].frame_pub.publish(frame)
|
||||
except KeyError: # we got deleted. Time to exit.
|
||||
cam.release()
|
||||
return False
|
||||
msg = sub.get()
|
||||
sub.release()
|
||||
|
||||
@@ -195,9 +198,10 @@ def pub_cam_thread(
|
||||
"""Run pub_cam_loop in a new thread. Starts on creation."""
|
||||
|
||||
name = uid_for_source(cam_id)
|
||||
t = None
|
||||
if name in uid_dict.keys():
|
||||
t = uid_dict[name]
|
||||
else:
|
||||
if t is None or not t.is_alive(): # Enables reopening cameras
|
||||
if "cv" in force_backend.lower():
|
||||
pub_cam_loop = pub_cam_loop_opencv
|
||||
elif (
|
||||
|
||||
@@ -216,10 +216,10 @@ async def read_updates_zero_mq(
|
||||
try:
|
||||
md = s.recv_json(flags=flags)
|
||||
msg = s.recv(flags=flags, copy=copy, track=track)
|
||||
buf = memoryview(msg)
|
||||
arr = np.frombuffer(buf, dtype=md["dtype"])
|
||||
arr.reshape(md["shape"])
|
||||
name = md["name"]
|
||||
buf = memoryview(msg) # type: ignore
|
||||
arr = np.frombuffer(buf, dtype=md["dtype"]) # type: ignore
|
||||
arr.reshape(md["shape"]) # type: ignore
|
||||
name = md["name"] # type: ignore
|
||||
cb_val = end_callback(md)
|
||||
yield name, arr
|
||||
except zmq.ZMQError as e:
|
||||
|
||||
@@ -51,6 +51,14 @@ def stop_cam(cam_id: Union[int, str]):
|
||||
CV_CAM_HANDLERS_DICT[str(cam_id)].cmd_pub.publish("quit", blocking=True)
|
||||
|
||||
|
||||
def del_cam(cam_id: Union[int, str]):
|
||||
"""Delete camera "cam_id"."""
|
||||
if str(cam_id) in CV_CAMS_DICT:
|
||||
del CV_CAMS_DICT[str(cam_id)]
|
||||
if str(cam_id) in CV_CAM_HANDLERS_DICT:
|
||||
del CV_CAM_HANDLERS_DICT[str(cam_id)]
|
||||
|
||||
|
||||
def cam_cmd_sub(cam_id, blocking=True):
|
||||
"""Get a command subscriber for registered camera "cam_id"."""
|
||||
if blocking:
|
||||
|
||||
@@ -112,6 +112,7 @@ class SubscriberWindows(object):
|
||||
def __stop_all_cams(self):
|
||||
for c in self.source_names:
|
||||
subscriber_dictionary.stop_cam(c)
|
||||
subscriber_dictionary.del_cam(c)
|
||||
|
||||
def handle_keys(self, key_input: int):
|
||||
"""Capture key input for the escape function and passing to key control subscriber threads."""
|
||||
@@ -214,7 +215,6 @@ class SubscriberWindows(object):
|
||||
def update_frames(self):
|
||||
"""Update the windows with the newest data for all frames."""
|
||||
self.frames = {}
|
||||
|
||||
for i in range(len(self.input_vid_global_names)):
|
||||
if self.input_vid_global_names[i] in self.FRAME_DICT and not isinstance(
|
||||
self.FRAME_DICT[self.input_vid_global_names[i]], NoData
|
||||
|
||||
@@ -23,9 +23,9 @@ if os.path.exists(readme_path):
|
||||
setup(
|
||||
long_description=readme,
|
||||
name="displayarray",
|
||||
version="1.3.0",
|
||||
version="1.3.1",
|
||||
description="Tool for displaying numpy arrays.",
|
||||
python_requires="==3.*,>=3.6.0",
|
||||
python_requires="==3.*,>=3.7.0",
|
||||
project_urls={"repository": "https://github.com/simleek/displayarray"},
|
||||
author="SimLeek",
|
||||
author_email="simulator.leek@gmail.com",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
[tox]
|
||||
envlist = py36, py37, mypy, pydocstyle
|
||||
envlist = py37, py38, mypy, pydocstyle
|
||||
isolated_build = false
|
||||
skip_missing_interpreters = true
|
||||
skipsdist=True
|
||||
|
||||
[gh-actions]
|
||||
python =
|
||||
3.6: py36, pydocstyle
|
||||
3.7: py37, mypy, pydocstyle
|
||||
3.8: py38, pydocstyle
|
||||
|
||||
[testenv]
|
||||
whitelist_externals = coverage
|
||||
|
||||
Reference in New Issue
Block a user