本文介绍了如何通过OpenCV和python打开IP Camera Url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在具有ffmpeg支持的MacX(Lion)上安装了opencv
I have install opencv on MacX(Lion) with ffmpeg support
import cv2
import cv
import base64
import time
import urllib2
import numpy as np
from cv2 import __version__
print(__version__)
video="http://xxx.223.91.91/mjpg/1/video.mjpg?dummy=param.avi"
vv = cv.CaptureFromFile(video)
cv2.namedWindow("preview")
vc = cv2.VideoCapture("http://xxx.223.91.91/mjpg/1/video.mjpg?dummy=param.mjpg")
但显示警告
2.4.2
警告:无法读取电影文件 http://xxx.223.91.91/mjpg/1/video.mjpg?dummy = param.avi
WARNING: Couldn't read movie file http://xxx.223.91.91/mjpg/1/video.mjpg?dummy=param.avi
警告:无法读取电影文件 http://xxx.223.91.91/mjpg/1/video.mjpg?dummy = param.mjpg
WARNING: Couldn't read movie file http://xxx.223.91.91/mjpg/1/video.mjpg?dummy=param.mjpg
我用Google编写了很多代码,但是找不到解决该问题的方法.请帮助我,谢谢.
I Google a lot of code, but could not find a solution to the problem.Please help me, thank you.
推荐答案
import cv2
import urllib
import numpy as np
stream=urllib.urlopen('http://localhost:8080/frame.mjpg')
bytes=''
while True:
bytes+=stream.read(16384)
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:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
cv2.imshow('i',i)
if cv2.waitKey(1) ==27:
exit(0)
这篇关于如何通过OpenCV和python打开IP Camera Url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!