需要帮助理解为什么我在OpenCV C代码中收到此错误消息...?

时间:2013-08-31 08:13:48

标签: c++ opencv

这是错误:

Error no Operand "<<" matches these operands

我收到错误的行是:

cout << "M = "<< endl << " " << size << endl << endl;

但是,如果我使用这一行,我没有错误:

cout << "M = "<< endl << " " << frame << endl << endl;

这是代码:

#include <cv.h>
#include <highgui.h>


using namespace std;
int main(){
CvCapture* capture =0;

capture = cvCreateCameraCapture(0);
if(!capture){
//printf("Capture failure\n");
return -1;
}

IplImage* frame=0;
int size = 0;
cvNamedWindow("Video");


//iterate through each frames of the video
while(true){

frame = cvQueryFrame(capture);
if(!frame) break;

frame=cvCloneImage(frame);

CvSize size = cvGetSize(frame);
cout << "M = "<< endl << " " << size << endl << endl;
//Clean up used images

cvReleaseImage(&frame);

//Wait 50mS
int c = cvWaitKey(10);
//If 'ESC' is pressed, break the loop
if((char)c==27 ) break;
}

cvDestroyAllWindows() ;
cvReleaseCapture(&capture);

return 0;
}
//////////////////////////////////////

为什么......请帮助我获得变量“大小”的输出 请引用在线资源获取答案,这样我就可以学习输出任何OpenCV变量。

2 个答案:

答案 0 :(得分:1)

CvSizestructure,而size的类型为CvSize

您需要像以下一样使用它:

cout <<" Height:" << size.height<<" Width:"<< size.width<< endl;

但是frame是指向IplImage

的指针

使用cout上的frame只会为您提供frame指向的内存地址

答案 1 :(得分:1)

没有CvSize流插入器。如果您需要该语法,请定义一个:

std::ostream& operator <<(std::ostream& os, const CvSize& siz)
{
    os << siz.width << ',' << siz.height;
    return os;
}
相关问题