你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下使用OpenCV打开笔记本摄像头

[日期:2017-08-01] 来源:Linux社区  作者:wangyarui [字体: ]

Linux下使用OpenCV打开笔记本摄像头

新建test文件夹,文件夹存在test.cppCMakeLists.txt

test.cpp
#include <iostream> #include <string> #include <sstream> #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/videoio.hpp> using namespace cv; using namespace std; const char* keys = { "{help h usage ? | | print this message}" "{@video | | Video file, if not defined try to use webcamera}" }; int main(int argc, const char** argv) { CommandLineParser parser(argc, argv, keys); parser.about("Reading a video and camera v1.0.0"); if (parser.has("help")) { parser.printMessage(); return 0; } String videoFile = parser.get<String>(0); if (!parser.check()) { parser.printErrors(); return 0; } VideoCapture cap; if (videoFile != "") { cap.open(videoFile);// read a video file }else { cap.open(0);// read the default caera } if (!cap.isOpened())// check if we succeeded { return -1; } namedWindow("Video", 1); while (1) { Mat frame; cap >> frame; // get a new frame from camera imshow("Video", frame); if (waitKey(30) >= 0) break; } // Release the camera or video file cap.release(); return 0; }
CMakeLists.txt

project(test)

cmake_minimum_required(VERSION 2.8.7)

# option to enable OpenMP; only relevant for the KCF version with the
# VOT scale estimation
option(WITH_OPENMP "Enable OpenMP" OFF)

if(WITH_OPENMP)
    find_package(OpenMP REQUIRED)

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(WITH_OPENMP)

# add c++11 support
if(CMAKE_COMPILER_IS_GNUCC)
    ADD_DEFINITIONS ( -std=c++11 )
endif(CMAKE_COMPILER_IS_GNUCC)

# add OpenCV
set(OPENCV_DIR_HINT "")

if(WIN32)
    get_filename_component(OPENCV_DIR_PLATFORM $ENV{OPENCV_DIR} DIRECTORY)
    get_filename_component(OPENCV_DIR_HINT ${OPENCV_DIR_PLATFORM} DIRECTORY)
endif(WIN32)

set(OpenCV_STATIC OFF)
find_package(OpenCV REQUIRED HINTS ${OPENCV_DIR_HINT})

编译过程:

 

> cd test
> g++ test.cpp -o test `pkg-config --cflags --libs opencv`
> ./test

OpenCV官方教程中文版(For Python) PDF  http://www.linuxidc.com/Linux/2015-08/121400.htm

Ubuntu 14.04安装OpenCV2.4.9  http://www.linuxidc.com/Linux/2016-07/132884.htm

Ubuntu 16.04上用CMake图形界面交叉编译树莓派的OpenCV3.0 http://www.linuxidc.com/Linux/2016-10/135914.htm

Ubuntu 16.04中安装OpenCV 2.4.11  http://www.linuxidc.com/Linux/2016-07/132882.htm

Ubuntu 16.04下Matlab2014a+Anaconda2+OpenCV3.1+Caffe安装  http://www.linuxidc.com/Linux/2016-07/132860.htm

Linux上安装和编译OpenCV3.0.0  http://www.linuxidc.com/Linux/2017-07/145446.htm

Ubuntu 16.04下TensorFlow+Caffe+OpenCV3.1+Theano部署  http://www.linuxidc.com/Linux/2017-01/139503.htm

Ubuntu 16.04 编译安装OpenCV 3.1及OpenCV多版本切换 http://www.linuxidc.com/Linux/2017-01/139325.htm

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

Ubuntu 安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2016-12/138293.htm

OpenCV的详细介绍请点这里
OpenCV的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-08/146026.htm

linux
相关资讯       OpenCV打开摄像头 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款