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