C, opencv reads pictures from the folder in batches for processing, and saves them in batches

 

1 Batch read glob

  The glob function is provided in the opencv4.x version, and the Directory class can be used in the previous version.

 

int main() {

    //批量读取
    string src_path = "E:\\Toky\\VsProject\\ColoNavigation\\ColoNavi_Opencv\\ColoNavi_Opencv\\data\\";
    vector<cv::String> file_vec;
    glob(src_path + "*.jpg", file_vec, false);
    int i = 1; //图片递增命名
    for (string file_name : file_vec)
    {
        cout << file_name << endl;
       
        //你自己的处理操作

        result = reconstruction(mask, image);
        //写入文件夹下
        imwrite(src_path+"after_remove_hilight\\"+ to_string(i)+".jpg", result);
        showImge("result", result);
        i++;
    }

2 Batch write imwrite

Note that the to_string  here  converts an integer to a string for batch writing when saving pictures

imwrite(src_path+"after_remove_hilight\\"+ to_string(i)+".jpg", result);

Reference from:

https://blog.csdn.net/kelin6/article/details/78912402?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

https://blog.csdn.net/m_buddy/article/details/86485618

Guess you like

Origin blog.csdn.net/Toky_min/article/details/107151927