linux opencv调用笔记本摄像头,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

c682bd2a169b341efe8a152a0d7bcf5e.png

总结

以上所述是小编给大家介绍的linux下利用opencv打开笔记本摄像头问题,希望对大家有所帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值