国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

python3從網(wǎng)絡(luò)攝像機(jī)解析mjpeg http流的示例

瀏覽:2日期:2022-07-05 15:29:31

前言

網(wǎng)絡(luò)攝像頭的視頻流解析直接使用通過http的Mjpeg是具有邊界幀信息的multipart / x-mixed-replace,而jpeg數(shù)據(jù)只是以二進(jìn)制形式發(fā)送。因此,實(shí)際上不需要關(guān)心HTTP協(xié)議標(biāo)頭。所有jpeg幀均以marker開頭,0xff 0xd8并以結(jié)尾0xff 0xd9。因此,上面的代碼從http流中提取了此類幀,并將其一一解碼。像下面

...(http)0xff 0xd8 --|[jpeg data] |--this part is extracted and decoded0xff 0xd9 --|...(http)0xff 0xd8 --|[jpeg data] |--this part is extracted and decoded0xff 0xd9 --|...(http)

如果圖像的獲取是從tcp網(wǎng)絡(luò)中傳輸?shù)奖镜剡M(jìn)行解析需要對(duì)bytes類型數(shù)據(jù)進(jìn)行解碼

在使用OpenCV直接調(diào)用網(wǎng)絡(luò)攝像頭時(shí)可能會(huì)出現(xiàn)

Cam not found

這時(shí)候就需要下面這種辦法

代碼: 幀解析

import cv2cap = cv2.VideoCapture(’http://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 cv2import requestsimport numpy as np r = requests.get(’http://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’xffxd8’) b = bytes.find(b’xffxd9’) 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從網(wǎng)絡(luò)攝像機(jī)解析mjpeg http流的示例的詳細(xì)內(nèi)容,更多關(guān)于python 解析mjpeg http流的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 宁国市| 长兴县| 曲靖市| 新津县| 洪湖市| 新闻| 陵川县| 英德市| 孟津县| 东城区| 凉城县| 靖宇县| 新巴尔虎右旗| 涿鹿县| 车致| 陆良县| 东兰县| 湘乡市| 军事| 莲花县| 中超| 泰顺县| 龙川县| 遂溪县| 宝应县| 福鼎市| 湖南省| 陵水| 嘉定区| 华安县| 万盛区| 浏阳市| 咸宁市| 新兴县| 郎溪县| 咸阳市| 岗巴县| 公安县| 蓬安县| 郯城县| 金昌市|