import cv2
import urllib.request
import numpy as np
import ssl
import requests
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# stream = requests.get('http://127.0.0.1:9120/', stream=True)
stream = urllib.request.urlopen("http://127.0.0.1:9120", context=ctx)
bytes = b''
while True:
bytes += stream.read(1024)
a = bytes.find(b'\xff\xd8')
b = bytes.find(b'\xff\xd9')
if a != -1 and b != -1:
jpg = bytes[a:b+2]
bytes = bytes[b+2:]
# i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.CV_LOAD_IMAGE_COLOR)
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
cv2.imshow('i', i)
print(i.shape)
if cv2.waitKey(1) == 27:
exit(0)
原创文章,转载请注明出处:http://124.221.219.47/article/py-mjpeg-read/