81inline bool natural_less(
const std::string& a,
const std::string& b) {
83 while (i < a.size() && j < b.size()) {
84 if (std::isdigit(
static_cast<unsigned char>(a[i])) &&
85 std::isdigit(
static_cast<unsigned char>(b[j]))) {
87 size_t ai = i, bj = j;
88 while (ai < a.size() && std::isdigit(
static_cast<unsigned char>(a[ai]))) ++ai;
89 while (bj < b.size() && std::isdigit(
static_cast<unsigned char>(b[bj]))) ++bj;
90 std::string da = a.substr(i, ai - i);
91 std::string db = b.substr(j, bj - j);
92 da.erase(0, da.find_first_not_of(
'0'));
93 db.erase(0, db.find_first_not_of(
'0'));
94 if (da.size() != db.size())
return da.size() < db.size();
95 if (da != db)
return da < db;
99 if (a[i] != b[j])
return a[i] < b[j];
104 return a.size() < b.size();
123 const std::string& ref_path,
124 const std::string& roi_path) {
125 std::vector<std::string> frames;
126 DIR* dir = opendir(folder.c_str());
128 throw std::runtime_error(
"Cannot open folder '" + folder +
"': " + std::strerror(errno));
132 std::string roi_basename =
"";
133 std::string ref_basename =
"";
134 if (!roi_path.empty()) {
135 size_t pos = roi_path.find_last_of(
"/\\");
136 roi_basename = (pos != std::string::npos) ? roi_path.substr(pos + 1) : roi_path;
138 if (!ref_path.empty()) {
139 size_t pos = ref_path.find_last_of(
"/\\");
140 ref_basename = (pos != std::string::npos) ? ref_path.substr(pos + 1) : ref_path;
143 struct dirent* entry;
144 while ((entry = readdir(dir)) !=
nullptr) {
145 std::string name = entry->d_name;
148 if (name.empty() || name[0] ==
'.')
continue;
151 std::string full_path = folder +
"/" + name;
153 if (stat(full_path.c_str(), &st) == 0 && S_ISDIR(st.st_mode))
continue;
156 std::string lower_name = name;
157 std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(),
158 [](
unsigned char c) { return std::tolower(c); });
163 if (lower_name ==
"roi.png")
continue;
164 if (lower_name ==
"ref.png")
continue;
167 if (!roi_basename.empty() && name == roi_basename)
continue;
168 if (!ref_basename.empty() && name == ref_basename)
continue;
170 frames.push_back(full_path);
std::vector< std::string > discover_frames(const std::string &folder, const std::string &ref_path, const std::string &roi_path)
Discover the deformed-frame image files inside folder.