import cv2 import urllib.request import numpy as np import sys host = "192.168.1.109:8080" #在这里记得修改IP,否则是无法调用的,刚刚浏览器输入的地址 if len(sys.argv)1: host = sys.argv[1] hoststr = 'http://' +
import urllib.request
import numpy as np
import sys
host = "192.168.1.109:8080" #在这里记得修改IP,否则是无法调用的,刚刚浏览器输入的地址
if len(sys.argv)>1:
host = sys.argv[1]
hoststr = 'http://' + host + '/?action=stream'
print('Streaming ' + hoststr)
print('Print Esc to quit')
stream=urllib.request.urlopen(hoststr)
bytes=bytes()
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:]
#flags = 1 for color image
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),flags=1)
# print i.shape
cv2.imshow("wjw",i)
if cv2.waitKey(1) & 0xFF == ord('q'):
exit(0)
import cv2
import urllib.request
import numpy as np
import sys
import base64
import time
import os
host = "192.168.1.109:8080" #在这里记得修改IP,否则是无法调用的,刚刚浏览器输入的地址
if len(sys.argv)>1:
host = sys.argv[1]
hoststr = 'http://' + host + '/?action=stream'
print('Streaming ' + hoststr)
print('Print Esc to quit')
stream=urllib.request.urlopen(hoststr)
bytes=bytes()
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:]
#flags = 1 for color image
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),flags=1)
# print i.shape
cv2.imshow("wjw",i)
if cv2.waitKey(1) & 0xFF == ord('q'):
exit(0)
name = str(time.time())
p = '/home/wjw/Desktop/123/'+name+'.jpg'
# 判断目录是否存在
if not os.path.exists(os.path.split(p)[0]):
# 目录不存在创建,makedirs可以创建多级目录
os.makedirs(os.path.split(p)[0])
try:
# 保存数据到文件
with open(p, 'wb') as f:
f.write(jpg)
print('保存成功')
except Exception as e:
print('保存失败', e)
【版权声明】本博文著作权归作者所有,任何形式的转载都请联系作者获取授权并注明出处!
【重要说明】本文为本人的学习记录,论点和观点仅代表个人而不代表当时技术的真理,目的是自我学习和有幸成为可以向他人分享的经验,因此有错误会虚心接受改正,但不代表此刻博文无误!
【Gitee地址】秦浩铖:https://gitee.com/wjw1014