如何使用OpenCV 2.3.1连接到IP Camera?

时间:2012-02-08 01:39:01

标签: c++

我正在使用openCV 2.3.1连接到IP Camera。

这是我的代码

#include "../../../OpenCV/include/opencv/cv.h"
#include "../../../OpenCV/include/opencv/highgui.h"

CvCapture *camera = cvCreateFileCapture("http://usr:pass@ip:port/nphMotionJpeg?resolution=320x240&Quality=Standard");
    if (camera == NULL)
        printf("camera is null\n");
    else
        printf("camera is not null");

    cvNamedWindow("img");
    int d = cvWaitKey(10);
    while (d != atoi("q"))
    {
        d = cvWaitKey(10);
        double t1 = (double)cvGetTickCount();
        IplImage *img = cvQueryFrame(camera);
        double t2=(double)cvGetTickCount();
        printf("time: %gms  fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));
        cvShowImage("img",img);
    }
    cvReleaseCapture(&camera);

但是上面的cvCreateFileCapture()函数总是返回null,但如果我使用cvCreateFileCapture(“video.avi”)就可以了,请解释一下为什么?

我已经在stackoverflow.com上阅读了很多关于这个问题的主题,但我还没有办法解决这个问题。

我正在使用OpenCV 2.3.1,并且我用ffmpeg构建它(我不确定这个,但我在构建它之后在我的文件夹上有opencv_ffmpeg.dll)。

2 个答案:

答案 0 :(得分:2)

作为the documentation says,您只能将本地文件的路径传递给cvCreateFileCapture()。

如果你想在IP摄像机上使用openCV,你必须用另一种方法从服务器获取图像,然后用openCV单独分析帧。

答案 1 :(得分:0)

尝试使用LibIpCurl。它支持与Ip相机的连接。

相关问题