Last active
January 31, 2018 01:31
-
-
Save youqingkui/b4f88e3b607ed5e3239e645ef0a4dfac to your computer and use it in GitHub Desktop.
pi图片流处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import urllib | |
import numpy as np | |
stream=urllib.urlopen('http://192.168.31.249:8080/video') | |
bytes='' | |
while True: | |
bytes+=stream.read(1024) | |
a = bytes.find('\xff\xd8') | |
b = bytes.find('\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) | |
cv2.imshow('i',i) | |
if cv2.waitKey(1) ==27: | |
exit(0) | |
import cv2 | |
import requests | |
import numpy as np | |
r = requests.get('http://192.168.31.249:8080/video', stream=True) | |
if(r.status_code == 200): | |
bytes = bytes() | |
for chunk in r.iter_content(chunk_size=1024): | |
bytes += chunk | |
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.IMREAD_COLOR) | |
cv2.imshow('i', i) | |
if cv2.waitKey(1) == 27: | |
exit(0) | |
else: | |
print("Received unexpected status code {}".format(r.status_code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment