qq_41747698
2021-10-28 17:36
采纳率: 75%
浏览 105

opencv如何批量保存imwrite图像,文件批量命名问题

现想用opencv在接口指定save_path后动态命名并保存图像到该文件夹,但是会出现文件名报错问题,会运行几秒钟之后并退出,怀疑是sprintf_s或者imwrite路径问题,请问应该如何修改,或者使用其它方式?

if (saveimg == 1 && img_count % 50 == 0) {
            if (_access(save_path, 0) == -1) { _mkdir(save_path); }
            //char * file_path, *file_path2;
            img_name += 1;
            char file_path[100], file_path2[100];

            sprintf_s(file_path,sizeof(file_path), "%s%s%s%s", save_path, "/", img_name, ".jpg");
            sprintf_s(file_path2, sizeof(file_path2), "%s%s%s%s", save_path, "/", img_name, "_reverse.jpg");
            //sprintf(file_path, save_path, "/%d.jpg", img_count);
            //sprintf(file_path2, save_path, "/%d_reverse.jpg", img_count);
            cout << "img_path" << file_path << "\n";
            imwrite(file_path, number_img);
            Mat bitwise_img;
            if (reverse_blackwhite == 1) {
                bitwise_not(number_img, bitwise_img);
                imwrite(file_path2, bitwise_img);

2条回答 默认 最新

相关推荐 更多相似问题