1.安装Opencv

1.1 编译

$git clone https://github.com/opencv/opencv.git
$cd opencv/
$git checkout tags/3.2.0
$mkdir build
$cd build/
$cmake ..
$make

1.2 安装

sudo make install

install之后要执行ldconfig,否则程序可能找不到动态库

sudo ldconfig

检查系统当前opencv版本号

pkg-config --modversion opencv

2.打开摄像头

打开摄像头并将视频流写入到视频文件中

#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>using namespace cv;
using namespace std;int main(int, char**)
{Mat src;// use default camera as video sourceVideoCapture cap(0);// check if we succeededif (!cap.isOpened()) {cerr << "ERROR! Unable to open camera\n";return -1;}// get one frame from camera to know frame size and typecap >> src;// check if we succeededif (src.empty()) {cerr << "ERROR! blank frame grabbed\n";return -1;}bool isColor = (src.type() == CV_8UC3);//--- INITIALIZE VIDEOWRITERVideoWriter writer;
    VideoWriter writerh264;int codec = CV_FOURCC('M', 'J', 'P', 'G');  // select desired codec (must be available at runtime)
    int codech264 = CV_FOURCC('H', '2', '6', '4');  // select desired codec (must be available at runtime)double fps = 25.0;                          // framerate of the created video streamstring filename = "./live.avi";             // name of the output video file
    string filenameh264 = "./live_h264.avi";             // name of the output video filewriter.open(filename, codec, fps, src.size(), isColor);
    writerh264.open(filenameh264, codech264, fps, src.size(), isColor);// check if we succeededif (!writer.isOpened()) {cerr << "Could not open the output video file for write\n";return -1;}if (!writerh264.isOpened()) {cerr << "Could not open the output video file for write\n";return -1;}//--- GRAB AND WRITE LOOPcout << "Writing videofile: " << filename << endl<< "Press any key to terminate" << endl;for (;;){// check if we succeededif (!cap.read(src)) {cerr << "ERROR! blank frame grabbed\n";break;}// encode the frame into the videofile streamwriter.write(src);
        writerh264.write(src);// show live and wait for a key with timeout long enough to show imagesimshow("Living", src);
        int key = cv::waitKey(1);if(key == 'q')break;}// the videofile will be closed and released automatically in VideoWriter destructorreturn 0;
}

Opencv 打开笔记本摄像头相关推荐

  1. Python使用opencv打开笔记本摄像头时遇到的问题及解决办法

    Python使用opencv打开笔记本摄像头时遇到的问题及解决办法 最近在学习python,想用opencv做个人脸检测,打开笔记本摄像头时遇到了问题.摄像头总是闪一下就关闭,并提示一行警告([ WA ...

  2. Linux命令模式下打开摄像头,Linux下利用Opencv打开笔记本摄像头问题

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

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

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

  4. opencv笔记(二)之opencv打开笔记本摄像头

    一.前言 楼主最近在使用opencv采集摄像头信息,一开始都不知道怎么去打开笔记本的摄像头的,于是有空做一个记录分享 至于win下怎么配置opencv可以参考楼主文章Opencv笔记(一)之vs201 ...

  5. 使用opencv打开笔记本摄像头

    opencv版本是3.10.0 系统是win7x64位 工具是vs2013 刚开始用网上找的代码发现不能正常打开摄像头要么摄像头灯亮了一下程序就自动结束了,要么就是弹出选择视频源的界面然后点击也没有反 ...

  6. OpenCV 学习笔记(5) 使用opencv打开笔记本摄像头

    #include "stdafx.h" #include <opencv2\opencv.hpp> #include <iostream> #include ...

  7. Linux下使用Opencv打开笔记本摄像头

    新建test文件夹,文件夹存在test.cpp和CMakeLists.txt test.cpp#include <iostream> #include <string> #in ...

  8. C#联合Halcon打开笔记本摄像头

    ** C#联合Halcon打开笔记本摄像头 环境配置 halcon12+vs2013 添加引用 64位操作系统选择dotnet35目录下的halcondotnet.dll 32位选择dotnet20目 ...

  9. 使用Opencv打开手机摄像头

    使用opencv打开手机摄像头,这里指的是电脑端写的opencv软件读取手机摄像头图像. 其主要原理是在手机端打开一个端口,打开.读取手机摄像头,然后通过ip-端口号实现远程摄像头图像读取,其实就是让 ...

最新文章

  1. datatable和dataset的区别
  2. EOSIO Dawn 4.0 发布
  3. [20171227]表的FULL_HASH_VALUE值的计算2
  4. 计算机病毒需要附着在,计算机病毒是如何传播的?
  5. 三十、MySQL 处理重复数据
  6. 港中文开源 | 融合视频目标检测与单目标、多目标跟踪
  7. 二叉树——二叉树问题(洛谷 P3884)
  8. 如何在HTML添加英文字母序号,怎样在文章中正确的使用序号(国外英文资料).doc...
  9. mysql手册06_触发器
  10. 手写实现bpnn神经网络
  11. absolute和relative的区别
  12. mysql dos 怎样卸载_MySQL安装与卸载
  13. 2 资源关系 | 到底什么是”局“-- 清华宁向东的管理学课总结
  14. USTC English Club20171010
  15. JAVA接入微信刷脸支付分支付【V2、V3两种接入都有提供】
  16. Ubuntu 17.10安装搜狗拼音输入法
  17. 江苏2020高中计算机学业水平,2020江苏高中学业水平测试时间安排表
  18. 关于Facebook发币,FB元老级员工们有话说
  19. 与众不同的区块链投资第一课
  20. 机器视觉、模式识别开源库汇总

热门文章

  1. java 程序执行后 强制gc_快速理解Java垃圾回收奥秘(GC)
  2. mysql md5 加盐加密_MD5—加密,加盐
  3. (三)本地yum源配置
  4. java用tabula解析pdf文件中的表格
  5. JavaScript:使用Xpath定位网页元素(含Iframe定位)
  6. 循迹的光电搬运小车含PID(硬件+源代码+3D文件)
  7. IT从业者成过劳死高危人群 员工不满病态企业文化
  8. MMOG网络同步算法揭秘(QQ幻想)
  9. Linux iostat命令详解
  10. “40美元摩托罗拉手机”到中国还没那么快