Change it to:
cvSaveImage(string(savedCode+filename).c_str(), imgBiner);
Suggestion: since you're using C++, you should use the new C++ API instead, it will work directly:
imwrite(savedCode+filename, imgBiner);
Question
i have code to input image name like IMG01.
ostringstream input;
input << z << ".jpg";
string filename = input.str();
const char* filename1 = filename.c_str(); [image processing here...]
then, i want save an image result with name bwIMG01.jpg using cvSaveImage
. Exp:
cvSaveImage("bwIMG01.jpg", imgBW);
my problem is to write change the output name for every image. i've tried this code below, but it is not work....
char savedImg [30];
string savedCode = "bw";
savedImg = savedCode+filename;
cvSaveImage(savedImg, imgBiner);
any idea?
Solution
Change it to:
cvSaveImage(string(savedCode+filename).c_str(), imgBiner);
Suggestion: since you're using C++, you should use the new C++ API instead, it will work directly:
imwrite(savedCode+filename, imgBiner);
OTHER TIPS
please use the c++ api, and the handy cv::format() instead:
cv::Mat imBW;
for ( int i=0; i<30; i++ )
imwrite( format("bwIMG%02d.jpg", i), imgBW);
again, please avoid the old c-api, it is no more developed.