CPPxDIC
C++ Digital Image Correlation library for fingertip 3D reconstruction
Loading...
Searching...
No Matches
image_folder_reader.cpp
Go to the documentation of this file.
1
10
11#include <algorithm>
12#include <filesystem>
13#include <utility>
14
15namespace fs = std::filesystem;
16
17namespace cppxdic {
18namespace input {
19
20namespace {
21
23std::string to_lower(std::string s) {
24 std::transform(s.begin(), s.end(), s.begin(),
25 [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
26 return s;
27}
28
30bool has_image_extension(const std::string& lower_name) {
31 static const char* kExts[] = {".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff"};
32 for (const char* ext : kExts) {
33 const std::string e(ext);
34 if (lower_name.size() > e.size() &&
35 lower_name.compare(lower_name.size() - e.size(), e.size(), e) == 0) {
36 return true;
37 }
38 }
39 return false;
40}
41
42} // namespace
43
44ImageFolderReader::ImageFolderReader(std::string folder) : folder_(std::move(folder)) {}
45
46std::vector<std::string> ImageFolderReader::listFrames(bool skip_roi_ref) const {
47 std::vector<std::string> frames;
48
49 std::error_code ec;
50 if (!fs::is_directory(folder_, ec)) {
51 return frames; // Cannot open folder -> empty list.
52 }
53
54 for (const auto& entry : fs::directory_iterator(folder_, ec)) {
55 if (ec) break;
56 if (!entry.is_regular_file()) continue;
57
58 const std::string name = entry.path().filename().string();
59 if (name.empty() || name[0] == '.') continue; // skip hidden files
60
61 const std::string lower = to_lower(name);
62 if (!has_image_extension(lower)) continue;
63
64 if (skip_roi_ref && (lower == "roi.png" || lower == "ref.png")) continue;
65
66 frames.push_back(entry.path().string());
67 }
68
69 // Lexicographic sort; zero-padded numeric filenames order correctly.
70 std::sort(frames.begin(), frames.end());
71 return frames;
72}
73
74} // namespace input
75} // namespace cppxdic
ImageFolderReader(std::string folder)
Construct a reader for a given image folder.
std::vector< std::string > listFrames(bool skip_roi_ref=true) const
List image frames in the folder, sorted by filename.
Image-folder input reader (Section 3b) - STUB.
DataSerializer - Abstract base class for format-agnostic DIC data I/O.