采集图片显示视频:

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3.  
  4. using namespace std;
  5. using namespace cv;
  6.  
  7. int main ()
  8. {
  9.  
  10. CvCapture *cap = cvCaptureFromCAM(); //CvCapture* capture = cvCaptureFromAVI("infile.avi");
  11. IplImage* img;
  12.  
  13. cvNamedWindow("showImg");
  14.  
  15. while()
  16. {
  17. img = cvQueryFrame(cap);
  18. if (!img)
  19. break;
  20.  
  21. cvShowImage("showImg", img);
  22.  
  23. char key = cvWaitKey();
  24. if (key == )
  25. break;
  26.  
  27. }
  28.  
  29. cvDestroyWindow("showImg");
  30. cvReleaseCapture(&cap);
  31. return ;
  32. }

按s键将图片存储到目录e:/src/cam/下

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3.  
  4. using namespace std;
  5. using namespace cv;
  6.  
  7. char path[];
  8.  
  9. int main ()
  10. {
  11. char num[] = {};
  12. int i = ;
  13.  
  14. CvCapture *cap = cvCaptureFromCAM();
  15. IplImage* img;
  16.  
  17. cvNamedWindow("showImg");
  18.  
  19. while()
  20. {
  21. img = cvQueryFrame(cap);
  22. if (!img)
  23. break;
  24.  
  25. cvShowImage("showImg", img);
  26.  
  27. char key = cvWaitKey();
  28. if (key == )
  29. break;
  30.  
  31. if (key == 's')
  32. {
  33. itoa(i++, num, );
  34. strcpy(path, "e:/src/cam/img_");
  35. strcat(path,num);
  36. strcat(path, ".bmp");
  37. cvSaveImage(path, img);
  38. cout<< path <<endl;
  39. }
  40. }
  41.  
  42. cvDestroyWindow("showImg");
  43. cvReleaseCapture(&cap);
  44. return ;
  45. }

OpenCV 例程的更多相关文章

  1. 【双目备课】OpenCV例程_stereo_calib.cpp解析

    stereo_calib是OpenCV官方代码中提供的最正统的双目demo,无论数据集还是代码都有很好实现. 一.代码效果: 相关的内容包括28张图片,1个xml和stereo_calib.cpp的代 ...

  2. OpenCV例程实现人脸检测

    前段时间看的OpenCV,其实有很多的例子程序,参考代码值得我们学习,对图像特征提取三大法宝:HOG特征,LBP特征,Haar特征有一定了解后. 对本文中的例子程序刚开始没有调通,今晚上调通了,试了试 ...

  3. common.py OpenCv例程阅读

    #!/usr/bin/env python ''' This module contais some common routines used by other samples. ''' import ...

  4. camshift.py OpenCv例程阅读

    源码在这 #!/usr/bin/env python ''' Camshift tracker ================ This is a demo that shows mean-shif ...

  5. video.py OpenCv例程阅读

    #!/usr/bin/env python ''' Video capture sample. Sample shows how VideoCapture class can be used to a ...

  6. OpenCV示例学习笔记(1)-contours2.cpp-通过findContours 函数实现轮廓提取

    这个系列的目的是通过对OpenCV示例,进一步了解OpenCV函数的使用,不涉及具体原理. 示例代码地址:http://docs.opencv.org/3.0.0/examples.html(安装op ...

  7. OpenCV 之 图像分割 (一)

    1  基于阈值 1.1  基本原理 灰度阈值化,是最简单也是速度最快的一种图像分割方法,广泛应用在硬件图像处理领域 (例如,基于 FPGA 的实时图像处理). 假设输入图像为 f,输出图像为 g,则经 ...

  8. OpenCV角点检测源代码分析(Harris和ShiTomasi角点)

    OpenCV中常用的角点检测为Harris角点和ShiTomasi角点. 以OpenCV源代码文件 .\opencv\sources\samples\cpp\tutorial_code\Trackin ...

  9. 【opencv基础】detectmultiscale函数详解

    前言 简单的人脸检测程序可以直接基于opencv的函数库进行实现,本文介绍一下detectMultiScale函数. 函数简介 opencv2人脸检测使用的是detectMultiScale函数,可以 ...

随机推荐

  1. postgresql backup

    #!/bin/sh # Database backup script # Backup use postgres pg_dump command: # pg_dump -U <user> ...

  2. c++ string类基本使用

    初始化用法 #include <iostream> #include "string" using namespace std; void main() { strin ...

  3. 15、Spring Boot 2.x 集成 Swagger UI

    1.15.Spring Boot 2.x 集成 Swagger UI 完整源码: Spring-Boot-Demos 1.15.1 pom文件添加swagger包 <swagger2.versi ...

  4. Strategic game POJ - 1463 【最小点覆盖集】

    Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...

  5. deferred.pipe([doneFilter],[failFilter],[progressFilter])

    deferred.pipe([doneFilter],[failFilter],[progressFilter]) 概述 筛选器和/或链Deferreds的实用程序方法. deferred.pipe( ...

  6. MySQL Data Directory -- Creating file-per-table tablespaces outside the data directory

    Creating file-per-table tablespaces outside the data directory 一. Data Directory 1.应对情况 当数据库所在空间不足的时 ...

  7. Active Directory 常用属性

    1.获取DirectoryEntry string str = string.Empty; string strPath = @LDAP://testDomain.com.mo; string ad  ...

  8. PHP基础--traits的应用

    Traits 在PHP中实现在方法的重复使用:Traits与Class相似,但是它能够在Class中使用自己的方法而不用继承: Traits在Class中优先于原Class中的方法,引用PHP Doc ...

  9. E.Substring Reverse Gym - 101755E

    Substring Reverse Problem Two strings s and t of the same length are given. Determine whether it is ...

  10. ERROR 1010 (HY000): Error dropping database (can't rmdir './zabbix/', errno: 17)

    在删除数据库的时候报标题所示错误 mysql> drop database zabbix; ERROR 1010 (HY000): Error dropping database (can't ...