C++ 之 ubuntu环境 opencv读视频流

一.ubuntu环境下配置 opencv, 通过opencv源码编译安装(参考其他)
二.准备以下2个文件
在这里插入图片描述
cv.cpp 内容如下

    #include <opencv2/highgui/highgui.hpp>   
    #include <opencv2/imgproc/imgproc.hpp>   
    #include <opencv2/core/core.hpp>  
      
    using namespace cv;  
      
    int main(int argc, char** argv)  
    {  
      
        VideoCapture cap(0);  
        if (!cap.isOpened())  
        {  
            return -1;  
        }  
        Mat frame;  
        while (1)  
        {  
            cap >> frame;  
            if (frame.empty()) break;  
            imshow("当前视频", frame);  
            if (waitKey(30) >= 0)  
                break;  
        }  
        return 0;  
    }  

CMakeLists.txt 内容如下

    # cmake needs this line 要求的最低版本  
    cmake_minimum_required(VERSION 2.8)  
      
    # Define project name 定义工程名  
    project(example_project)  
      
    # Find OpenCV, you may need to set OpenCV_DIR variable  
    # to the absolute path to the directory containing OpenCVConfig.cmake file  
    # via the command line or GUI 自动查找库  
    find_package(OpenCV REQUIRED)  
      
    # Declare the executable target built from your sources 声明可执行目标文件及源文件  
    add_executable(cv cv.cpp) # 目标文件,源文件0,源文件1,...  
      
    # Link your application with OpenCV libraries 将目标文件与库链接  
    target_link_libraries(cv ${OpenCV_LIBS})   # 目标文件,库路径 

cmake的版本要求设置: 一般放在最开始
cmake_minimum_required(VERSION 2.8)
Set the minimum required version of cmake for a project and update Policy Settings to match the version given:

cmake_minimum_required(VERSION major.minor[.patch[.tweak]]
                       [FATAL_ERROR])

If the current version of CMake is lower than that required it will stop processing the project and report an error.

三.在当前目录下执行

cmake .
make

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
四.执行最终生成的cv, 即可以看到视频画面

./cv
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值