26 lines
674 B
Python
26 lines
674 B
Python
|
|
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()
|