Last active
December 17, 2022 18:19
-
-
Save jonmatthis/538bba8a749d0372ee623cd23be1dde6 to your computer and use it in GitHub Desktop.
simple video display with opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Connect to camera at port '0' and display in a loop - close with ESC | |
requires `opencv-python` or `opencv-contrib-python` | |
note - should run in any environment that can run `freemocap` stuff | |
""" | |
import time | |
import cv2 | |
import numpy as np | |
camera_id = 0 | |
cap = cv2.VideoCapture(camera_id) | |
should_continue = True | |
start_time = time.perf_counter() | |
timestamps = [] | |
while should_continue: | |
success, image = cap.read() | |
timestamps.append(time.perf_counter() - start_time) | |
median_framerate = np.median(np.diff(timestamps)) ** -1 | |
print(f"read image success: {success} , image.shape: {image.shape}, median_framerate: {median_framerate}") | |
cv2.imshow(f'Camera {camera_id} - Press ESC to exit', image) | |
if cv2.waitKey(1) == 27: | |
print(f"ESC key pressed - shutting down") | |
cv2.destroyAllWindows() | |
should_continue = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment