2012-02-08 45 views
1

我使用openCV 2.3.1連接到IP攝像機。如何使用OpenCV 2.3.1連接到IP Camera?

這裏是我的代碼

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

CvCapture *camera = cvCreateFileCapture("http://usr:[email protected]: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上看過關於這個問題的很多線程,但我沒有任何方法可以解決這個問題。我使用的是OpenFV 2.3.1,我已經用ffmpeg構建了它(我不確定這一點,但是在構建它之後,我的文件夾中有opencv_ffmpeg.dll)。

+0

它看起來像'cvCreateFileCapture'只支持本地文件。 – 2012-02-08 01:55:48

回答

1

由於the documentation says,只能將路徑傳遞給本地文件cvCreateFileCapture()。

如果你想在IP攝像機上使用openCV,你必須以另一種方式從服務器獲取圖像,然後用openCV單獨分析幀。

+0

真的嗎?我沒有看到文件提到一個本地文件。我已閱讀了很多主題,並且有些人使用此代碼獲得了成功。 但是,如果它是真的,你能告訴我連接到IP攝像機的另一種方式嗎? 非常感謝:) – Levanphong7887 2012-02-08 02:32:05

0

嘗試使用LibIpCurl。它支持連接到IP攝像頭。