Image saving issue

I want to save multiple images, but I found that the write name seems to be of const type and cannot be modified. How can I save multiple images and depth maps.

int i = 0;
sl::Mat image;
sl::Mat depth_image;

      returned_state = zed.grab();
    // A new image is available if grab() returns ERROR_CODE::SUCCESS
    if (returned_state == ERROR_CODE::SUCCESS) {

        // Get the left image
        zed.retrieveImage(image, VIEW::LEFT);
        zed.retrieveMeasure(depth_image, MEASURE::DEPTH);
        _sleep(50);//延时50ms
        // Display the image resolution and its acquisition timestamp
        image.write("img1.png");
        depth_image.write("depth1.png");
    }

Hi @zsj520,

The Mat.write() method takes a const sl::String & type as input, not a const type.
You can set any sl::String value as an input to the method, and it will save the file at the correct path.

Hello, I am now able to save multiple images, but I find that later images do not overwrite the previous ones when I run them again. Can you tell me what went wrong?

::
while (i<10)
{
returned_state = zed.grab(runParameters);
// A new image is available if grab() returns ERROR_CODE::SUCCESS
if (returned_state == ERROR_CODE::SUCCESS) {

        zed.retrieveImage(image, VIEW::LEFT);  // Get the left image
        zed.retrieveMeasure(depth_image, MEASURE::DEPTH);// Get the depth image
        zed.getPosition(zed_pose, REFERENCE_FRAME::WORLD);//返回的姿势与相机的初始位置有关 
        auto zed_orientation = zed_pose.getOrientation();//获取四元数信息
        auto zed_translation = zed_pose.getTranslation();//获取平移信息

        std::string filename = "F:/data/image_" + std::to_string(i) + ".png";
        std::string filename_depth = "F:/data/depth_" + std::to_string(i) + ".png";
        const char* data1 = filename.c_str();
        const char* data2 = filename_depth.c_str();
        sl::String filename1;
        sl::String filename2;
        filename1.set(data1);
        filename2.set(data2);
        image.write(filename1);
        depth_image.write(filename2);

        //_sleep(100);//延时50ms
        i++;
        cout << i<< "\n";
        outfile << zed_translation <<' ';  //存储位姿信息
        outfile << zed_orientation << "\n";
    }

}