opencv 打开网络摄像头

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


下面附上程序 :

#include "cv.h"
#include "highgui.h"
#include <iostream>


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;
  
    }   
}







  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值