2025-07-29 20:28:33 +02:00
|
|
|
import cv2
|
|
|
|
|
import requests
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
2025-07-29 20:37:16 +02:00
|
|
|
url = "http://pilego.local:8080"
|
2025-07-29 20:28:33 +02:00
|
|
|
stream = requests.get(url, stream=True)
|
|
|
|
|
|
|
|
|
|
bytes_buffer = b""
|
|
|
|
|
|
|
|
|
|
for chunk in stream.iter_content(chunk_size=1024):
|
|
|
|
|
bytes_buffer += chunk
|
|
|
|
|
a = bytes_buffer.find(b'\xff\xd8') # początek JPEG
|
|
|
|
|
b = bytes_buffer.find(b'\xff\xd9') # koniec JPEG
|
|
|
|
|
if a != -1 and b != -1:
|
|
|
|
|
jpg = bytes_buffer[a:b+2]
|
|
|
|
|
bytes_buffer = bytes_buffer[b+2:]
|
|
|
|
|
|
|
|
|
|
img = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
|
|
|
|
|
if img is not None:
|
|
|
|
|
cv2.imshow("MJPEG Stream", img)
|
|
|
|
|
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
cv2.destroyAllWindows()
|