43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
"""View the robot's MJPEG stream on a laptop."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
import cv2
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="View Saqr PPE stream from robot")
|
|
parser.add_argument("--ip", default="192.168.123.164", help="Robot IP address")
|
|
parser.add_argument("--port", default="8080", help="Stream port")
|
|
args = parser.parse_args()
|
|
|
|
url = f"http://{args.ip}:{args.port}/stream"
|
|
print(f"Connecting to {url} ...")
|
|
|
|
cap = cv2.VideoCapture(url)
|
|
if not cap.isOpened():
|
|
print(f"[ERROR] Cannot connect to {url}")
|
|
return
|
|
|
|
print("Connected! Press q to quit.")
|
|
|
|
while True:
|
|
ret, frame = cap.read()
|
|
if not ret:
|
|
print("Stream lost, reconnecting...")
|
|
cap.release()
|
|
cap = cv2.VideoCapture(url)
|
|
continue
|
|
|
|
cv2.imshow("Saqr PPE - Robot Stream", frame)
|
|
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
break
|
|
|
|
cap.release()
|
|
cv2.destroyAllWindows()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|