티스토리 뷰

OS/Raspberry Pi

Python - mjpeg 영상 화면에 출력

파란크리스마스 2017. 8. 16. 00:15
728x90

출처 : python - How to parse mjpeg http stream from ip camera? - Stack Overflow

Python - mjpeg 영상 화면에 출력

import cv2
import requests
import numpy as np

#stream = urllib.request.urlopen("http://127.0.0.1:8080/?action=snapshot")
#stream = urllib2.urlopen("http://127.0.0.1:8080/?action=snapshot")
#bytes = bytes()

while True:
    r = requests.get('http://127.0.0.1:8080/?action=snapshot"', auth=('user', 'password'), stream=True)
    if(r.status_code == 200):
        bytes = b''
        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))


댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함