#!/usr/bin/env python3 # Разовый тест: снять кадр с RTSP-камеры и отправить на наш сервер распознавания. # Запуск (когда на весах стоит машина и виден номер): python3 grab_test.py import subprocess, base64, urllib.request, json, datetime, time RTSP_URL = 'rtsp://iivideo:Vk9mT2xLp7nQ4wBj@192.168.20.3:9784/cameras/124/streaming/main' SERVER = 'https://scales.zeroday.su/api/capture' FRAME = '/tmp/scale_frame_test.jpg' print("1) Снимаю кадр с камеры...") cmd = ['ffmpeg', '-y', '-loglevel', 'error', '-rtsp_transport', 'tcp', '-i', RTSP_URL, '-frames:v', '1', '-update', '1', '-vf', 'scale=1280:-2', '-q:v', '4', '-f', 'image2', FRAME] try: subprocess.run(cmd, timeout=15, check=True) except Exception as e: print(" ОШИБКА захвата кадра:", e); raise SystemExit(1) img = open(FRAME, 'rb').read() print(f" OK, кадр {len(img)} байт") eid = f"opi-camtest-{int(time.time())}" print(f"2) Отправляю на сервер (event_id={eid}, вес-заглушка 12345)...") payload = json.dumps({ 'event_id': eid, 'device_id': 'scales_opi', 'weight': 12345.0, 'captured_at': datetime.datetime.now().isoformat(), 'media_type': 'image/jpeg', 'photo_b64': base64.b64encode(img).decode() }).encode() req = urllib.request.Request(SERVER, data=payload, headers={'Content-Type': 'application/json'}) print(" ответ сервера:", urllib.request.urlopen(req, timeout=20).read().decode()) print(f"3) Готово! Скажи Claude event_id={eid} — проверю кадр и распознанный номер.")