diff --git a/examples/streamgazertsp.py b/examples/streamgazertsp.py index 843940f..53117c8 100644 --- a/examples/streamgazertsp.py +++ b/examples/streamgazertsp.py @@ -11,7 +11,7 @@ async def stream_rtsp(): - async with connect_to_glasses.with_hostname(os.environ["G3_HOSTNAME"]) as g3: + async with connect_to_glasses.with_hostname(os.environ["G3_HOSTNAME"], using_zeroconf=True) as g3: async with g3.stream_rtsp(scene_camera=True, gaze=True) as streams: async with streams.gaze.decode() as gaze_stream, streams.scene_camera.decode() as scene_stream: for i in range(200): @@ -26,18 +26,31 @@ async def stream_rtsp(): gaze, gaze_timestamp = await gaze_stream.get() while gaze_timestamp is None: gaze, gaze_timestamp = await gaze_stream.get() - cv2.imshow("Video", frame.to_ndarray(format="bgr24")) # type: ignore - cv2.waitKey(1) # type: ignore + logging.info(f"Frame timestamp: {frame_timestamp}") logging.info(f"Gaze timestamp: {gaze_timestamp}") + frame = frame.to_ndarray(format="bgr24") + + # If given gaze data if "gaze2d" in gaze: gaze2d = gaze["gaze2d"] logging.info(f"Gaze2d: {gaze2d[0]:9.4f},{gaze2d[1]:9.4f}") + + # Convert rational (x,y) to pixel location (x,y) + h, w = frame.shape[:2] + fix = (int(gaze2d[0] * w), int(gaze2d[1] * h)) + + # Draw gaze + frame = cv2.circle(frame, fix, 10, (0, 0, 255), 3) + elif i % 50 == 0: logging.info( "No gaze data received. Have you tried putting on the glasses?" ) + cv2.imshow("Video", frame) # type: ignore + cv2.waitKey(1) # type: ignore + def main(): asyncio.run(stream_rtsp()) diff --git a/pyproject.toml b/pyproject.toml index cde401a..4980543 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,3 +65,6 @@ skip_gitignore = true [tool.pytest.ini_options] asyncio_mode = "auto" testpaths = ["tests"] + +# Timeout +faulthandler_timeout=30 diff --git a/src/g3pylib/__init__.py b/src/g3pylib/__init__.py index efd47a6..62027e7 100644 --- a/src/g3pylib/__init__.py +++ b/src/g3pylib/__init__.py @@ -25,6 +25,7 @@ from types import TracebackType from typing import Any, AsyncIterator, Coroutine, Generator, Optional, Tuple, Type, cast + import g3pylib.websocket from g3pylib._utils import APIComponent from g3pylib.calibrate import Calibrate