新建test文件夹,文件夹存在test.cppCMakeLists.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 "
  "{@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打开笔记本摄像头问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。