直接上代码,注释很详细
#include <sys/stat.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#define CV_LOAD_IMAGE_COLOR 1
// st_mtime按修改时间排序
struct img_sorted_by_modify_time {
bool operator() (const std::string& p1, const std::string& p2) {
struct stat attribp1;
struct stat attribp2;
stat(p1.c_str(), &attribp1);
stat(p2.c_str(), &attribp2);
return attribp1.st_mtime < attribp2.st_mtime;
}
};
// 主函数
int main(int argc, char* argv[]) {
//std::string input_img_path_parent = argv[1];
// 定义排序路径
std::string input_img_path_parent = "images";
std::string input_img_path;
std::vector<std::string> f