IP摄像机Python错误 [英] IP camera Python error

查看:643
本文介绍了IP摄像机Python错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从IP摄像机访问视频。我使用OpenCV和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

使用另一种方法, CaptureFromCAM 而不是 CaptureFromFile

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)


$ b b

当我运行这个代码,我得到的错误是:

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

ERROR: SampleCB() - buffer sizes do not match
No conversion to IPL Image

我读了一下,而且 SampleCB()错误是在缓冲区大小与预期输入大小不匹配的情况下。我试图改变流分辨率,但似乎没有什么工作。我按照主题和这个主题。他们给的C ++代码和转换到Python(上面给出的代码),它不工作。或者线程给出了用于运动检测的代码。我使用 Windows 7和 Eclipse 与Pydev 发展。

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?

推荐答案

哦,请坚持使用cv2 API 。旧的cv版本在当前OpenCV版本中不再可用:

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

这篇关于IP摄像机Python错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆