stream server

This commit is contained in:
Oskar Kapala 2025-07-29 20:28:33 +02:00
parent b65ea9ba74
commit b8ba694610

25
server-stream.py Normal file
View file

@ -0,0 +1,25 @@
import cv2
import requests
import numpy as np
url = "http://localhost:8080"
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()