opecv2.3+directshow操作多个摄像头配置
来源:互联网 发布:iqr 淘宝网 编辑:程序博客网 时间:2024/05/18 11:27
1、 下载地directshow,http://download.csdn.net/download/yangalbert/4184472
2、 到opencv中文官网下载,http://www.opencv.org.cn/index.php/使用DirectShow采集图像其中的下载代码和例程
3、 配置opencv2.3
1 下载安装VS2010、OpenCV2.3,并解压缩OpenCV2.3,本处为D:\ProgramFiles\OpenCV2.3
2 配置VS2010,右键项目属性,其中vc目录添加
配置include路径:包含D:\Program Files\OpenCV2.3\build\include; D:\ProgramFiles\OpenCV2.3\build\include\opencv;D:\ProgramFiles\OpenCV2.3\build\include\opencv2
配置lib路径:
32位系统 &VC2010,库目录为:D:\Program Files\OpenCV2.3\build\x86\vc10\lib
3 设置环境变量
DLL:D:\ProgramFiles\OpenCV2.3\build\x86\vc10\bin
4 在项目属性 链接器 输入 附加依赖库 里加上
opencv_core230d.lib
opencv_highgui230d.lib
opencv_video230d.lib
opencv_ml230d.lib
opencv_legacy230d.lib
opencv_imgproc230d.lib
4、 配置directshow(可以将directshow拷贝到当前的工程下)
Project->Settings->Settingsfor:(All configurations)->C/C++->Category(Preprocessor)->Additionalinclude directories
设置为DirectShow/Include
Project->Settings->Settingsfor:(All configurations)->Link->Category(Input)->Additional librarydirectories
设置为DirectShow/Lib
5、 将opencv中文官网中下载的代码中的CameraDS.h、CameraDS.cpp复制到当前的工程中
6、运行下载代码中的main.cpp
//////////////////////////////////////////////////////////////////////+// Video Capture using DirectShow// Author: Shiqi Yu (shiqi.yu@gmail.com)// Thanks to://HardyAI@OpenCV China//flymanbox@OpenCV China (for his contribution to function CameraName, and frame width/height setting)// Last modification: April 9, 2009//// 使用说明:// 1. 将CameraDS.h CameraDS.cpp以及目录DirectShow复制到你的项目中// 2. 菜单 Project->Settings->Settings for:(All configurations)->C/C++->Category(Preprocessor)->Additional include directories// 设置为 DirectShow/Include// 3. 菜单 Project->Settings->Settings for:(All configurations)->Link->Category(Input)->Additional library directories// 设置为 DirectShow/Lib//////////////////////////////////////////////////////////////////////#include <stdio.h>#include "camerads.h"#include <highgui.h>const char *g_szTitle = "Camera";int main(){// 1、考虑到已经存在了显示图像的窗口,那就不必再次驱动摄像头了,即便往下驱动那也是摄像头已被占用。if(IsWindowVisible(FindWindow(NULL, g_szTitle))){return (-1);}//仅仅获取摄像头数目int m_iCamCount = CCameraDS::CameraCount();printf("There are %d cameras.\n", m_iCamCount);if(m_iCamCount == 0){return (-1);}CCameraDS m_CamDS;//获取所有摄像头的名称for(int i = 0; i < m_iCamCount; i++){char szCamName[1024];int retval = m_CamDS.CameraName(i, szCamName, sizeof(szCamName));if(retval >0){printf("Camera #%d's Name is '%s'.\n", i, szCamName);}else{printf("Can not get Camera #%d's name.\n", i);}}// 2、考虑到如果有多个摄像头,或者又有其中某个或某几个正在被其它程序占有,故需要逐个遍历,// 直到找到可用的为止。int m_iCamNum = 0; // 摄像头编号IplImage *pFrame = NULL;while(m_iCamNum < m_iCamCount){if((! m_CamDS.OpenCamera(m_iCamNum, false, 320, 240)) || ((pFrame = m_CamDS.QueryFrame()) == NULL)){m_iCamNum++;}else{ // 找到合适的摄像头,退出循环。break;}// 关闭摄像头,必须要关闭,因为即将要进行下一次的检测,检测前要清空当前的占用空间。m_CamDS.CloseCamera();}if(m_iCamNum == m_iCamCount){fprintf(stderr, "Can not open camera or is used by another app.\n");return (-1);}cvNamedWindow(g_szTitle);//显示cvShowImage(g_szTitle, pFrame);while(1){//获取一帧pFrame = m_CamDS.QueryFrame();//显示cvShowImage(g_szTitle, pFrame);if (cvWaitKey(20) == 'q'){break;}}m_CamDS.CloseCamera(); //可不调用此函数,CCameraDS析构时会自动关闭摄像头cvDestroyWindow(g_szTitle);return 0;}
配置过程出现的错误:
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
之前添加:
#define POINTER_64 __ptr64
否则在使用DirectShow会出现“ERROR:winnt.h error C2146:语法错误:缺少';'(在标识符'PVOID64'的前面)”的错误。
d:\my documents\visual studio 2010\projects\opencv_directshow\opencv_directshow\main.cpp
(28): error C2664: “FindWindowW”:不能将参数 2 从“const char *”转换为“LPCWSTR”
UNICODE问题,项目菜单->最后的属性->配置属性->常规->项目默认值->unicode改为未设置
对于这个问题也可以将const char*转换为LPCWSTR
- opecv2.3+directshow操作多个摄像头配置
- 基于 VC+OpenCV+DirectShow 的多个摄像头同步工作
- 基于 VC+OpenCV+DirectShow 的多个摄像头同步工作
- win7下VS2012配置DirectShow+Opencv并且多摄像头采集
- [DirectShow] [bug调研] 捕获多个摄像头时 后续的摄像头初始化失败
- OpenCV学习笔记(6)基于 VC+OpenCV+DirectShow 的多个摄像头同步工作
- OpenCV学习笔记(6)基于 VC+OpenCV+DirectShow 的多个摄像头同步工作
- OpenCV学习笔记(6)基于 VC+OpenCV+DirectShow 的多个摄像头同步工作
- VS2012下配置opencv+directshow(CCameraDS),支持多摄像头 转载自叶科忠's Blog
- Win10下VS2015配置DirectShow+OpenCV并且多摄像头的采集
- python2.7中配置opecv2.43
- opencv+directshow实现4个摄像头同步采集图像
- VS 2013使用DirectShow类操作USB摄像头
- DirectShow的配置及从摄像头读取视频并预览
- 使用OpenCV 实现多摄像头图像处理笔记(1):DirectShow的配置过程可能出现的问题
- 使用DirectShow驱动摄像头
- 使用DirectShow驱动摄像头
- 使用DirectShow驱动摄像头
- o3-关于sqlplus autotrace
- 当程序出现已停止工作
- (四)23种设计模式之我见-----------观察者模式(Observer)
- libstdc++.so.6: version `CXXABI_ARM_1.3.3' not found
- ioctl
- opecv2.3+directshow操作多个摄像头配置
- 汤姆猫信使: 折翼的信使
- Xcode 4.3.2中Interface Builder检查器的属性解析
- Oracle中如何删除重复数据
- java 调用本地应用程序
- 说说这段时间的事情
- SNMP中的MIB是什么?
- 带子目录的makefile文件
- 域用户登陆时总要先按Ctrl+Alt+Delete的问题也适用2000,2003系统