Linux下使用Opencv打开笔记本摄像头
2018-06-17 22:08:55来源:未知 阅读 ()
新建test文件夹,文件夹存在test.cpp和CMakeLists.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
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- C++ 在名称空间中使用using声明和using编译指令 2020-05-29
- OpenCV开发笔记(五十九):红胖子8分钟带你深入了解分水岭 2020-05-24
- Building & Debugging chromium on CLion for Linu 2020-05-19
- 1.ffmpeg、ffplay、ffprobe命令使用 2020-05-11
- opencv-12-高斯滤波-双边滤波(附C++代码实现) 2020-05-10
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash