如何使用Python3从网络摄像机提取MJPEG HTTP流示例代码?
- 内容介绍
- 文章标签
- 相关推荐
本文共计252个文字,预计阅读时间需要2分钟。
前言:网络摄影头的视频流解析及直接使用通过HTTP的Mjpeg
网络摄影头的视频流解析可以通过直接使用HTTP协议中的Mjpeg来实现。Mjpeg是一种具有边界信息的多部分multipart/x-mixed-replace格式,而jpeg数据则仅以二进制形式发送。因此,在实际应用中,通常不需要关注HTTP协议的头部信息。所有jpeg帧都以这种方式平均发送。
前言
网络摄像头的视频流解析直接使用通过localhost:8080/frame.mjpg') while True: ret, frame = cap.read() print(frame) if ret == True: cv2.imshow('Video', frame) if cv2.waitKey(1) == 27: exit(0)
视频流解析
import cv2 import requests import numpy as np r = requests.get('192.168.1.xx/mjpeg.cgi', auth=('user', 'password'), 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))
以上就是python3从网络摄像机解析mjpeg http流的示例的详细内容,更多关于python 解析mjpeg http流的资料请关注易盾网络其它相关文章!
本文共计252个文字,预计阅读时间需要2分钟。
前言:网络摄影头的视频流解析及直接使用通过HTTP的Mjpeg
网络摄影头的视频流解析可以通过直接使用HTTP协议中的Mjpeg来实现。Mjpeg是一种具有边界信息的多部分multipart/x-mixed-replace格式,而jpeg数据则仅以二进制形式发送。因此,在实际应用中,通常不需要关注HTTP协议的头部信息。所有jpeg帧都以这种方式平均发送。
前言
网络摄像头的视频流解析直接使用通过localhost:8080/frame.mjpg') while True: ret, frame = cap.read() print(frame) if ret == True: cv2.imshow('Video', frame) if cv2.waitKey(1) == 27: exit(0)
视频流解析
import cv2 import requests import numpy as np r = requests.get('192.168.1.xx/mjpeg.cgi', auth=('user', 'password'), 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))
以上就是python3从网络摄像机解析mjpeg http流的示例的详细内容,更多关于python 解析mjpeg http流的资料请关注易盾网络其它相关文章!

