-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyFileUtils.cpp
95 lines (72 loc) · 2.78 KB
/
MyFileUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Created by nannan on 2019/11/10.
//
#include <iostream>
#include "MyFileUtils.h"
#include <sys/stat.h>
#include <fstream>
#include <dirent.h>
#include <cstring>
using namespace boost::filesystem;
using namespace std;
using namespace cv;
MyFileUtils::MyFileUtils() {
}
ImgNamesVect MyFileUtils::returnImgNames(const std::string &directoryPath) {
ImgNamesVect aImgNamesVect;
//define the path and ensure its existence
path dirPath(directoryPath);
if (not exists(dirPath) or not is_directory(dirPath)) {
cerr << "Cannot open directory: " << directoryPath << endl;
}
//fetch all imgs with excepted extension and store their path in mImageFilenames
for (directory_entry &x : directory_iterator(dirPath)) {
std::string extension = x.path().extension().string();
boost::algorithm::to_lower(extension);
if (extension == ".jpg" or extension == ".png") {
aImgNamesVect.push_back(x.path().string());
cout << x.path().string() << " has been written to the aImgNamesVect." << endl;
}
}
if (aImgNamesVect.size() <= 0) {
cerr << "Unable to find valid files in images directory (\"" << directoryPath << "\")." << endl;
}
return aImgNamesVect;
}
ImgsVect MyFileUtils::returnImgsVec(ImgNamesVect aImgNamesVect) {
ImgsVect aImgsVect;
for (auto &imageFilename : aImgNamesVect) {
aImgsVect.push_back(cv::imread(imageFilename));
if (mDownscaleFactor != 1.0) {
cv::resize(aImgsVect.back(), aImgsVect.back(), cv::Size(), mDownscaleFactor, mDownscaleFactor);
}
if (aImgsVect.back().empty()) {
cerr << "Unable to read image from file: " << imageFilename << endl;
}
}
int aImgVectSize = aImgsVect.size();
cout << "The size of aImgsVect is :" << to_string(aImgVectSize) << endl;
return aImgsVect;
}
void MyFileUtils::makeMyDirs() {
if (0 != access(caliOutputPath.c_str(), 0)) {
mkdir(caliOutputPath.c_str(), 0777);
cout << "The path:" << caliOutputPath.c_str() << " is created successfully" << endl;
}
if(0!=access(featureOutputPath.c_str(),0)){
mkdir(featureOutputPath.c_str(),0777);
cout<<"The path:"<<featureOutputPath.c_str()<<" is created successfully"<<endl;
}
// if(0!=access(matchingOutputPath.c_str(),0)){
// mkdir(matchingOutputPath.c_str(),0777);
// cout<<"The path:"<<matchingOutputPath.c_str()<<" is created successfully"<<endl;
// }
}
cv::Size MyFileUtils::returnImgSize(ImgsVect aImgsVect) {
cv::Size image_size;
image_size.width = aImgsVect[0].cols;
image_size.height = aImgsVect[0].rows;
cout << "image_size.width = " << image_size.width << endl;
cout << "image_size.height = " << image_size.height << endl;
return image_size;
}