Possible Duplicate:
C++ convert int and string to char*
The function I use looks like this:
int cvSaveImage(const char* filename,const CvArr* image);
This function expects a const char* as first parameter. For example:
cvSaveImage("ImageName",img)
would be right.
However, I would like to put instead of ‘Name’ in “ImageName”, an int variable value.
I’ve tried something like this, but doesn’t work at all, it crashes:
int num = 10;
char buffer[1024];
sprintf(buffer,"Image%d",num);
cvSaveImage((const char *)buffer,img);
Any ideas?
You must specify an extension for the file. That is the only way openCV firgures out the format to write in. OpenCV throws an exception which is most likely why your program is crashing.
Also, if you are working on a new project, please consider moving to the C++ interface of openCV. It is much more structured, has more features and is also recommended.