linux打开笔记本摄像头驱动程序,Linux下利用Opencv打开笔记本摄像头问题

新建test文件夹,文件夹存在test.cpp和CMakeLists.txttest.cpp#include

#include

#include

#include

#include

#include

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(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

fd5854ab70d1eca353a318fbf47fd486.png

总结

以上所述是小编给大家介绍的Linux下利用Opencv打开笔记本摄像头问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

时间: 2017-07-31

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值