python 摄像头 异常_IP摄像机Python错误

I am trying to access a video from an IP camera. I am using OpenCV and Python to do so. The code that I have tried is given below:

import numpy as np

import cv2

from cv2 import cv

camera=cv.CaptureFromFile("http://root:root@192.168.0.90/axis-cgi/mjpg/video.cgi?resolution=640x480&req_fps=30&.mjpg")

if camera is None:

print 'Camera is null'

else:

print 'Camera is not null'

cv.NamedWindow("win")

while True:

image=cv.QueryFrame(camera)

cv.ShowImage("win", image)

k=int(cv.WaitKey(10))

if k is 27:

break

On running this code the output that I am getting is:

Image not converted

On using another method, CaptureFromCAM instead of CaptureFromFile the code is:

import numpy as np

import cv2

from cv2 import cv

camera=cv.CaptureFromCAM(0)

if camera is None:

print 'Camera is null'

else:

print 'Camera is not null'

cv.NamedWindow("win")

while True:

image=cv.QueryFrame(camera)

if image is None:

print 'No conversion to IPL Image'

break

else:

cv.ShowImage("win", image)

When I run this code the error I am getting is:

ERROR: SampleCB() - buffer sizes do not match

No conversion to IPL Image

I read about it, and the SampleCB() error is in the case when the buffer size does not match the expected input size. I tried to change the streaming resolution, but nothing seems to work. I followed this thread and this thread. They are giving the C++ code and on conversion to Python (the code given above) it does not work. Or the thread gives the code for motion detection. I am using Windows 7 and Eclipse with Pydev for development. What do I do?

解决方案

Oh, please stick with the cv2 API. The old cv one is no more available in current OpenCV versions:

import numpy as np

import cv2

cv2.namedWindow("win")

camera = cv2.VideoCapture("http://username:pass@192.168.0.90/axis-cgi/mjpg/video.cgi?resolution=640x480&req_fps=30&.mjpg")

while camera.isOpened():

ok, image = camera.read()

if not ok:

print 'no image read'

break

cv2.imshow("win", image)

k = cv2.waitKey(1) & 0xff

if k == 27 : break # Esc pressed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值