现在的位置: 首页 > 综合 > 正文

“ERROR: SampleCB() – buffer sizes do not match ” 解决方法

2013年09月04日 ⁄ 综合 ⁄ 共 2234字 ⁄ 字号 评论关闭

本人原创,转载请标明转载地址。http://blog.csdn.net/jia_zhengshen/article/details/9980495

opencv的highgui模块在windows的实现中使用开源的图像显示函数库:videoInput,但是为了同Linux等兼容,highgui模块做的对PAL,NTSC模块做的不是很好,并且应该是不支持多摄像头的。通过查看源码得知,虽然ideoInput是支持多摄像头的,但是由于VideoCapture 类中的VideoInput的性质被设置为“private static ”只能有一个VideoInput实例在opencv中运行,所以opencv中不支持多摄像头,而且由于VI被设置为private所以这个VI的性质是不能更改的。

所以我放弃了直接使用opencv的VideoCapture模块。改为直接采用其底层的VideoInput来实现多摄像头,解决"ERROR: SampleCB() - buffer sizes do not match "问题。

做法如下:

1.下载videoinput类库,遇到问题,现在由于其不再更新,所以最高版本的类库为vs08版本,我用的是vs10 ,经过试验10的可以使用这个由vs08编译的类库。

2.设置各种路径,lib ,include路径。估计你能看到这篇文章,这点设置应该小意思。

3.包含videoinput.h头文件。

4.写代码,把videoinput类中的data直接赋值给cv::mat,或者IplImage。

qq是如何实现的呢?看看他是如何抄袭的啊,

     

你按下“画质调节”会出现神马情况呢???????????????

下面是个我写的简单的小例子,还希望大家能够指点。

#pragma comment(linker,"/NODEFAULTLIB:atlthunk.lib")            
//据说上面的一句话必不可少。
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
#include<opencv2\highgui\highgui.hpp>
using namespace std;
using namespace cv;
#include"videoInput.h"
int main (int argc, char* argv[])
{
	videoInput::listDevices();//列出系统能够找到的所有的摄像头
	videoInput *VI = new videoInput();
	int device =1;//设备号
	//VI->setPhyCon(0,VI_COMPOSITE);
	VI->setupDevice(device );//打开设备
	VI->setFormat(device,VI_PAL_B);//我用的摄像头是PAL_B格式的,所以设置成这个格式的,其实可以不要。
	VI->showSettingsWindow(device);//使用widows的对话框来设置摄像头的格式等。可以替代掉上面的那句话。、、打开qq的画质调节,发现你的对话框和qq的竟然一样?????
														//原来qq也是用ideoInput来实现的。
	int height = VI->getHeight(device);
	int width = VI->getWidth(device );
	cout<<"height "<<height<<" width "<<width<<endl;
	IplImage *img = cvCreateImage(cvSize(width,height),8,3);
	std::cout<<VI->isDeviceSetup(device)<<std::endl;//查看设备是否启动
	std::cout<<VI->isFrameNew(device)<<std::endl;
	std::cout<<VI->getDeviceName(device)<<std::endl;//得到设备名称。
	std::cout<<VI->devicesFound<<std::endl;//一共有多少个设备。
	int i=0;
	//OPENCV C++ INTERFACE 
	Mat cmat;
	cmat.create(height,width,CV_8UC3);
	Mat cmat2;
	cmat2.create(width,height,CV_8UC3);
	while(1)
	{
		//while(!VI->isFrameNew(0))
			//cout<<i++;

		if(VI->isFrameNew(device) )
		{
			VI->getPixels(device,(unsigned char*)img->imageData,false,true);//IplImage 格式
			VI->getPixels(device,(unsigned char*)cmat.data,false,false);//opencv 的c++接口的转化。
			VI->getPixels(device,(unsigned char*)cmat2.data,false,false);
			imshow("tt",cmat);
			imshow("tt2",cmat2);
			cvShowImage("hello",img);
			if( cvWaitKey(2) >=0)
				break;
		}
	}
	VI->stopDevice(1);//释放设备。
	getchar();
	
    return 0;
} 

抱歉!评论已关闭.