0

here is the error:

Error no Operand "<<" matches these operands

the line I get error on is:

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

but if I use this line I get no error:

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

here is the code:

#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;
}
//////////////////////////////////////

why is that....please help me get output of variable "size" and please cite online resource for your answer so I may learn to get output of any OpenCV variable.

1
  • Why C in the title and tags ? This looks like C++ ?... Commented Aug 31, 2013 at 8:25

2 Answers 2

1

There is no CvSize stream inserter. If you want that syntax, then define one:

std::ostream& operator <<(std::ostream& os, const CvSize& siz)
{
    os << siz.width << ',' << siz.height;
    return os;
}
Sign up to request clarification or add additional context in comments.

7 Comments

don't really understand your answer @WhozCraig ...This is for a computer science project and I'm new to C I'd like to be able to set a variable like char a = #S(SIZE :WIDTH 1280 :HEIGHT 1024); and pass it to a function like this IplImage* imgThresh=cvCreateImage(a ,IPL_DEPTH_8U, 1); but I need to know what string would satisfy the first parameter of cvCreateImage....I'd like to see the mechanism behind the Code so I can Wrap it ...
@user2735131 This simply declares a stream insertion operator (you're using them already for types like const char *. This allows you to have a variable of type CvSize, which an output stream normally doesn't understand, and send a variable of that type to the stream. So rather than doing this: cout << siz.width << ',' << siz.height << endl you can do this: cout << siz << endl;. In other words, it makes the syntax you have that currently does not work, work.
@user2735131 and yes, you can use this same concept for any data type you want to send to a std::ostream or derivations therein (like a file stream, for example). Many types (all the native types like int, char, float, etc..) are already part of the standard library. When you have a type that isn't part of the standard library, you can do this.
when I enter your function into my code directly underneath CvSize size = cvGetSize(frame); after I changed it so it reads std::ostream& operator <<(std::ostream& os, const CvSize& size) { os << size.width << ',' << size.height; return os; } I get Error: Expected a ";" on the first Bracket.....this is in Visual Studio 2012
Don't put it underneath. It's a function, declare and define it like any other function. In your case I would put it before main.
|
1

CvSize is a structure and size is of type CvSize

You need to use it like following :

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

However frame is pointer to a IplImage

using a cout on frame will just give you a memory address pointed by frame

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.