OpenCV——win7下VS2013配置directshow+opencv双摄像头

1、安装和配置opencv,具体看毛星云的,很详细

2、下载directshow  地址:https://download.csdn.net/download/csdn_dzh/10557597

3、开始配置directshow,假设你直接解压到D盘

    1)创建一个控制台程序

    2)在"VC++目录"的"可执行文件目录"中添加D:\DirectShow\bin

    3)在"VC++目录"的"包含目录"中添加D:\DirectShow\include

    4)在"VC++目录"的"库目录"中添加D:\DirectShow\lib

4、使用CCameraDS类

把D:\DirectShow\include中的"CameraDS.h"、"CameraDS.cpp"复制到控制台程序的当前目录下,加载现有项到程序中

5、运行下面的程序

#include 
 
#include "camerads.h"
 
#include 
 
const char *g_szTitle = "Camera";
 
int main()
{
	int m_iCamCount = CCameraDS::CameraCount();
	printf("There are %d cameras.\n", m_iCamCount);
 
	if(m_iCamCount == 0)
	{
		return (-1);
	}
 
	CCameraDS m_CamDS0;
	CCameraDS m_CamDS1;
 
	IplImage *pFrame0 = NULL;
	IplImage *pFrame1 = NULL;
	IplImage *pFrame2 = NULL;
 
	m_CamDS0.OpenCamera(0, false, 320, 240);
	m_CamDS1.OpenCamera(1, false, 320, 240);
 
	cvNamedWindow("video0");
	cvNamedWindow("video1");
 
	while(1)
	{
		//获取一帧
		pFrame0 = m_CamDS0.QueryFrame();
 
		//显示
		cvShowImage("video0", pFrame0);
 
		//获取一帧
		pFrame1 = m_CamDS1.QueryFrame();
 
		//显示
		cvShowImage("video1", pFrame1);
 
		if (cvWaitKey(20) == 'q')
		{
			break;
		}
	}
 
	m_CamDS0.CloseCamera(); //可不调用此函数,CCameraDS析构时会自动关闭摄像头
	m_CamDS1.CloseCamera();
	cvDestroyWindow("video0");
	cvDestroyWindow("video1");
 
 
	return 0;
}

6、这时候会报个错,你点击一下,直到编译器给你跳转到winNT.h文件第300行左右的如下两行

    typedef void *PVOID;

    typedef void *POINTER_64 PVOID64;

    在这之前添加:

     #define POINTER_64 __ptr64

7、再一次运行,done

你可能感兴趣的:(OpenCV)