您好,登錄后才能下訂單哦!
小編給大家分享一下Linux下如何使用Opencv打開筆記本攝像頭問題,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
新建test文件夾,文件夾存在test.cpp和CMakeLists.txttest.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
總結
以上所述是小編給大家介紹的Linux下利用Opencv打開筆記本攝像頭問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
以上是“Linux下如何使用Opencv打開筆記本攝像頭問題”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。