agrobot_base/Python/raspi/test_stream_raw.py

55 lines
1.4 KiB
Python
Raw Normal View History

2026-04-16 20:07:06 +00:00
import time
from multispectral_service import MultiSpectralService
from stream_receiver import StreamReceiver
STREAM_PORT = 6001
PI_HOST = "192.168.105.6"
PC_HOST = "192.168.105.5"
def main():
receiver = StreamReceiver(host="0.0.0.0", port=STREAM_PORT)
receiver.start()
time.sleep(0.5)
svc = MultiSpectralService(host=PI_HOST, port=5000, timeout=10)
svc.connect()
try:
_fps = 15
print("SET RES:", svc.set_resolution(640, 480))
print("SET FPS:", svc.set_fps(_fps))
print("BEGIN:", svc.begin())
print("START STREAM:", svc.start_stream(PC_HOST, STREAM_PORT, fps=_fps))
t0 = time.perf_counter()
last_frame_id = -1
while time.perf_counter() - t0 < 5:
meta = receiver.last_meta
frame = receiver.last_frame
if meta is not None and meta["frame_id"] != last_frame_id:
last_frame_id = meta["frame_id"]
print(meta)
#print(
# f"frame_id={meta['frame_id']} "
# f"shape={frame.shape if frame is not None else None} "
# f"dt_total_pi={meta.get('dt_total_pi'):.4f}"
#)
time.sleep(0.02)
print("STOP STREAM:", svc.stop_stream())
print("STOP:", svc.stop())
finally:
svc.disconnect()
receiver.stop()
if __name__ == "__main__":
main()