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: