python-opencv調用mjpg-stream視頻流


mjpg-stream視頻流地址  http://IP:8080/?action=snapshot

接下來你就可以在瀏覽器里看到攝像頭的內容了。
接下來才是大家比較關心的問題了,如何調取這個mipg-stream流呢?由於小碩需要對采集到的圖像做一些處理,於是我采用python-opencv來實現這個project.
至於怎么安裝python,opencv等,我在上篇已經提過,我在這里不在贅述了。

import cv2
import urllib2
import numpy as np
import sys
host = "192.168.199.110:8300"#在這里記得修改IP,否則是無法調用的,剛剛瀏覽器輸入的地址
if len(sys.argv)>1:
    host = sys.argv[1]
hoststr = 'http://' + host + '/?action=stream'
print 'Streaming ' + hoststr

print 'Print Esc to quit'
stream=urllib2.urlopen(hoststr)
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:]
        #flags = 1 for color image
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),flags=1)
       # print i.shape
        cv2.imshow("xiaorun",i)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            exit(0)

 

這樣我們就可以利用opencv調用了遠程攝像頭了,方法簡單實用,各位可以自行參考,如果有問題歡迎大家提問,小編郵箱1039463596@qq.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM