2013-03-17 27 views

回答

3
int main() 
{ 
    Mat frame; 
    namedWindow("video", 1); 
    VideoCapture cap("http://150.214.93.55/mjpg/video.mjpg"); 
    while (cap.isOpened()) 
    { 
     cap >> frame; 
     if(frame.empty()) break; 

     imshow("video", frame); 
     if(waitKey(30) >= 0) break; 
    } 
    return 0; 
} 

不知道,你的url如何看起来像,但opencv似乎坚持,它必须以mjpg结束。 因此,如果没有,关键是要附加一个虚拟参数:

http://my/cool/ip-cam.ie?dummy=video.mjpg 

,如果你需要同时打开所有4个摄像头,你需要为每一个VideoCapture:

VideoCapture cap1("url1"); 
VideoCapture cap2("url2"); 
VideoCapture cap3("url3"); 
VideoCapture cap4("url4"); 
+0

打招呼.cpp:3:5:error:'Mat'was not declared in this scope hello.cpp:3:9:error:expected';'before'frame' hello.cpp:4:27:error:'namedWindow '未在此范围内声明 hello.cpp:5:5:错误:'VideoCapture'未在此范围内声明 hello.cpp:5:18:error:expected';' 'cap' hello.cpp:6:13:错误:'cap'未在此范围内声明 hello.cpp:8:16:错误:'frame'未在此范围内声明 hello.cpp:11 :30:error:'imshow'未在此范围内声明 hello.cpp:12:22:error:'waitKey'未在此范围内声明 – iAmNotVeryGoodAtThis 2013-10-07 01:04:44

+1

using namespace cv; – berak 2013-10-07 08:21:41