49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
Saqr - View robot PPE stream on laptop via OpenCV
|
|
===================================================
|
|
Connects to the robot's MJPEG stream and displays in an OpenCV window.
|
|
|
|
Usage:
|
|
python view_stream.py
|
|
python view_stream.py --ip 192.168.123.164
|
|
python view_stream.py --ip 10.255.254.86 --port 8080
|
|
"""
|
|
|
|
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}")
|
|
print(f" Try: python view_stream.py --ip 10.255.254.86")
|
|
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()
|