opencv 打开网络摄像头

闲着没事从同学那里找到了个openwrt   ,突然间想起来OPENCV可以很轻松的打开自带的摄像头,刚开始学习OPENCV 打开过若干次笔记本的摄像头,OPENCV能否打开网络摄像头呢?在百度上搜资料看到别人曾经做到过OPENCV+openwrt做无线监控的项目,觉得OPENCV从网络摄像头获取视频也必定可以实现,其他的论坛里也找到过相关的资料  。我在自己的电脑上面试试了试刚开始老是不行,直接报错找不到摄像头,这个问题很是让我郁闷。不过最后还是解决了:


下面附上程序 :

#include "cv.h"
#include "highgui.h"
#include


int main(int, char**) {
    cv::VideoCapture vcap;
     cv::Mat image;
CvCapture  *capture ;
    const std::string videoStreamAddress = "http://192.168.1.1:8080/?action=stream?dummy=param.mjpg"; 
    /* it may be an address of an mjpeg stream, 
    e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */


    //open the video stream and make sure it's opened
    if(!vcap.open(videoStreamAddress)) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }


    //Create output window for displaying frames. 
    //It's important to create this window outside of the `for` loop
    //Otherwise this window will be created automatically each time you call
    //`imshow(...)`, which is very inefficient. 
    cv::namedWindow("Output Window");




    for(;;) {
        if(!vcap.read(image)) {
            std::cout << "No frame" << std::endl;
            cv::waitKey();
        }
        cv::imshow("Output Window", image);


       if(cv::waitKey(1) >= 0) break;
  
    }   
}







你可能感兴趣的:(c++)