编程语言
首页 > 编程语言> > 网络摄像机Python错误

网络摄像机Python错误

作者:互联网

我正在尝试从IP摄像机访问视频.我正在使用OpenCV和Python.我尝试过的代码如下:

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

在运行此代码时,我得到的输出是:

Image not converted

在使用另一种方法CaptureFromCAM而不是CaptureFromFile时,代码为:

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)

当我运行此代码时,我得到的错误是:

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

我读到它,并且在缓冲区大小与预期的输入大小不匹配的情况下,出现SampleCB()错误.我试图更改流分辨率,但似乎无济于事.我遵循了this线程和this线程.他们提供了C代码,并且在转换为Python(上面给出的代码)时不起作用.或线程提供用于运动检测的代码.我正在将Windows 7和Eclipse与Pydev一起使用进行开发.我该怎么办?

解决方法:

哦,请坚持使用cv2API.旧的cv 1在当前的OpenCV版本中不再可用:

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

标签:python,c,opencv,video-streaming,ip-camera
来源: https://codeday.me/bug/20191009/1881855.html