opencv1.0版本摄像头驱动不兼容问题的解决方法
2011-07-12 10:16
525 查看
由于近期在做之前分封装好了的一个使用opencv1.0版本的dll文件,因为dll将opencv1.0已经集成进去了,所以我的工程也只能回到1.0版本。经过测试发现图片、avi 视频都是可以完美使用的,唯一不行的就是视频,在网上查找了一个说明,大致的原因都是opencv1.0版本的摄像头驱动并不兼容win7,所以这就成为了一个问题,翻了不少地方,终于找到一个可以完美解决的办法。
给出网站原帖地址: http://www.opencv.org.cn/index.php/%E4%BD%BF%E7%94%A8DirectShow%E9%87%87%E9%9B%86%E5%9B%BE%E5%83%8F 里面很含有相关说明和一个demo,按照这个demo修改就可以完全解决win7的摄像头兼容问题.
//////////////////////////////////////////////////////////////////////
// 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
// 在vc++2005开发环境下的使用说明:
// 1.将CameraDS.h CameraDS.cpp复制到你的项目中
// 2.将DirectShow复制到你的opencv根目录下,菜单 工具->选项->项目和解决方案->vc++目录,把..(你的opencv安装目录)/DirectShow/Include添加到
// “引用文件”中$(VCInstallDir)PlatformSDK\include和$(FrameworkSDKDir)include下面任意位置
// 3.菜单 工具->选项->项目和解决方案->vc++目录,把..(你的opencv安装目录)/DirectShow/Lib添加到“库文件”下面。也可参考使用说明3。
//////////////////////////////////////////////////////////////////////
#include "camerads.h"
#include <highgui.h>
#include <stdio.h>
int main()
{
int cam_count;
//仅仅获取摄像头数目
cam_count = CCameraDS::CameraCount();
printf("There are %d cameras.\n", cam_count);
//获取所有摄像头的名称
for(int i=0; i < cam_count; i++)
{
char camera_name[1024];
int retval = CCameraDS::CameraName(i, camera_name, sizeof(camera_name) );
if(retval >0)
printf("Camera #%d's Name is '%s'.\n", i, camera_name);
else
printf("Can not get Camera #%d's name.\n", i);
}
if(cam_count==0)
return -1;
CCameraDS camera;
//打开第一个摄像头
//if(! camera.OpenCamera(0, true)) //弹出属性选择窗口
if(! camera.OpenCamera(0, false, 320,240)) //不弹出属性选择窗口,用代码制定图像宽和高
{
fprintf(stderr, "Can not open camera.\n");
return -1;
}
cvNamedWindow("camera");
while(1)
{
//获取一帧
IplImage *pFrame = camera.QueryFrame();
//显示
cvShowImage("camera", pFrame);
if (cvWaitKey(20) == 'q')
break;
}
camera.CloseCamera(); //可不调用此函数,CCameraDS析构时会自动关闭摄像头
cvDestroyWindow("camera");
return 0;
}
给出网站原帖地址: http://www.opencv.org.cn/index.php/%E4%BD%BF%E7%94%A8DirectShow%E9%87%87%E9%9B%86%E5%9B%BE%E5%83%8F 里面很含有相关说明和一个demo,按照这个demo修改就可以完全解决win7的摄像头兼容问题.
//////////////////////////////////////////////////////////////////////
// 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
// 在vc++2005开发环境下的使用说明:
// 1.将CameraDS.h CameraDS.cpp复制到你的项目中
// 2.将DirectShow复制到你的opencv根目录下,菜单 工具->选项->项目和解决方案->vc++目录,把..(你的opencv安装目录)/DirectShow/Include添加到
// “引用文件”中$(VCInstallDir)PlatformSDK\include和$(FrameworkSDKDir)include下面任意位置
// 3.菜单 工具->选项->项目和解决方案->vc++目录,把..(你的opencv安装目录)/DirectShow/Lib添加到“库文件”下面。也可参考使用说明3。
//////////////////////////////////////////////////////////////////////
#include "camerads.h"
#include <highgui.h>
#include <stdio.h>
int main()
{
int cam_count;
//仅仅获取摄像头数目
cam_count = CCameraDS::CameraCount();
printf("There are %d cameras.\n", cam_count);
//获取所有摄像头的名称
for(int i=0; i < cam_count; i++)
{
char camera_name[1024];
int retval = CCameraDS::CameraName(i, camera_name, sizeof(camera_name) );
if(retval >0)
printf("Camera #%d's Name is '%s'.\n", i, camera_name);
else
printf("Can not get Camera #%d's name.\n", i);
}
if(cam_count==0)
return -1;
CCameraDS camera;
//打开第一个摄像头
//if(! camera.OpenCamera(0, true)) //弹出属性选择窗口
if(! camera.OpenCamera(0, false, 320,240)) //不弹出属性选择窗口,用代码制定图像宽和高
{
fprintf(stderr, "Can not open camera.\n");
return -1;
}
cvNamedWindow("camera");
while(1)
{
//获取一帧
IplImage *pFrame = camera.QueryFrame();
//显示
cvShowImage("camera", pFrame);
if (cvWaitKey(20) == 'q')
break;
}
camera.CloseCamera(); //可不调用此函数,CCameraDS析构时会自动关闭摄像头
cvDestroyWindow("camera");
return 0;
}
相关文章推荐
- Y450 摄像头驱动问题的解决方法“0X00405202指令,或vmstillmnt”
- CentOS下安装Python3后BeautifulSoup 版本不兼容问题解决方法
- Win7下安装启动vs2012的程序版本不兼容问题解决方法
- 已解决:HorizontalScrollView的setScrollViewListener方法不兼容低版本的问题
- 关于DevExpress2011.1.8版本和NetFramework4.5框架的不兼容问题解决方法
- ubuntu 下用 opencv驱动笔记本摄像头问题解决方法
- linux (REHL)系统的网络服务与此版本的网络管理器不兼容问题解决方法
- Microsoft ReportViewer 控件类型版本兼容问题及解决方法
- eclipse安装fatjar插件方法及版本不兼容问题解决
- Qt3和Qt4版本差异带来的问题和解决方法
- strutsDAO层添加数据时 mysqljar包版本兼容问题解决
- 5招方法完全解决浏览器兼容问题
- PL2303在ARM Linux下驱动的问题及解决方法
- windows 7 出现MTP usb设备驱动安装问题解决方法
- 解决CSS 兼容问题的一些方法,转
- ubuntu14.04 server版 安装指定版本docker的方法(解决apt-get install无法安装指定版本docker的问题)
- 解决Bootstrap不兼容IE8及以下版本的问题
- 一种解决新版本API完全兼容老版本API的方法
- JavaScript在IE和Firefox(火狐)的不兼容问题解决方法小结 【转】http://blog.csdn.net/uniqer/article/details/7789104
- C++二进制兼容问题及解决方法