Ask Your Question

Revision history [back]

filename problem with imwrite() function

Hello guys, I have a small problem with imwrite(). I am processing each frame of a video. And I wish to store the frame once I press S key. Here is my code for generating the string of fileName. But I can't save the image.

 char c = waitKey(1000 / 1);
 if (c == 's') {
    ostringstream out;
    out << "img" << cap.get(CAP_PROP_POS_FRAMES) << ".jpg" << endl;
    string fileName(out.str());
    cout << fileName << endl;
    imwrite(fileName, diffFrame);

But if I directly replace imwrite() with imwrite("img1.jpg", diffFrame), it works. I don't know why it happens. Is there anyone who knows? Thanks you.