-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrationpictures.cpp
189 lines (161 loc) · 5.7 KB
/
calibrationpictures.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "calibrationpictures.h"
CalibrationPictures::CalibrationPictures(
String pathCalibrationPicturesLeftCamera,
String pathCalibrationPicturesRightCamera)
: pathCalibrationPicturesLeftCamera{pathCalibrationPicturesLeftCamera},
pathCalibrationPicturesRightCamera{pathCalibrationPicturesRightCamera} {
getCalibrationPictures(pathCalibrationPicturesLeftCamera, "leftCamera");
getCalibrationPictures(pathCalibrationPicturesRightCamera, "rightCamera");
}
CalibrationPictures::CalibrationPictures() {}
CalibrationPictures::~CalibrationPictures() {
cout << "Destroy the Object Calibration Pictures" << endl;
}
void CalibrationPictures::takeCalibrationImages() {
StereoCamera stereoCamera(this->pathLeftCamera,this->pathRightCamera);
Mat frameLeft, frameRight,concatImage;
bool pressSaveButton{false};
int numOfSavePictures{0};
chrono::time_point<chrono::system_clock> start, end;
std::chrono::duration<double> delta;
if (!stereoCamera.isOpened()) {
cout << "Error the Stereo Camera can't open";
}
while (stereoCamera.isOpened()) {
stereoCamera.getCapLeft().read(frameLeft);
stereoCamera.getCapRight().read(frameRight);
// imshow("Left_frame", frameLeft);
// imshow("Rigth_frame", frameRight);
hconcat(frameLeft,frameRight,concatImage);
imshow("Frame", concatImage);
int k = waitKey(1);
if ((this->exit == 'q') || (k == 'q')) {
break;
} else if (this->startTakingImages == 's' || k == 's') {
cout << "<----- Start Saving images ----->" << endl;
pressSaveButton = true;
startTakingImages = 'o';
start = chrono::system_clock::now();
} else if (this->startTakingImages == 'e' || k == 'e') {
cout << "<----- End Saving Images ----->" << endl;
startTakingImages = 'o';
pressSaveButton = false;
}
if (pressSaveButton == true) {
end = chrono::system_clock::now();
delta = (end - start);
if (int(delta.count()) == 3) {
saveCalibrationImages(frameLeft, frameRight, numOfSavePictures++);
start = chrono::system_clock::now();
}
}
}
}
void CalibrationPictures::saveCalibrationImages(const Mat &frameLeft,
const Mat &frameRight,
int numOfPictures) {
string filePathLeft = pathCalibrationPicturesLeftCamera + "/imageL" +
to_string(numOfPictures) + ".png";
string filePathRight = pathCalibrationPicturesRightCamera + "/imageR" +
to_string(numOfPictures) + ".png";
imwrite(filePathLeft, frameLeft);
imwrite(filePathRight, frameRight);
cout << "Save Image " << numOfPictures << endl;
this->numOfSavingImages = numOfPictures;
}
void CalibrationPictures::getCalibrationPictures(const string &filePath,
const string &cameraName) {
if (cameraName == "leftCamera") {
String filePathNameLeft = filePath + "/imageL*.png";
cv::glob(filePathNameLeft, this->calibrationPicturesLeftCamera, false);
} else if (cameraName == "rightCamera") {
String filePathNameRight = filePath + "/imageR*.png";
cv::glob(filePathNameRight, this->calibrationPicturesRightCamera, false);
} else {
cout << "Error, choose the leftCamera or the rightCamera";
}
}
void CalibrationPictures::printFileNames(const vector<cv::String> &fileNames) {
for (auto const &fileName : fileNames) {
std::cout << std::string(fileName) << std::endl;
}
cout << "<-------------------End--------------------->" << endl << endl;
}
void CalibrationPictures::printAllFileNames() {
cout << "<---- Left Camera's calibration Images ----> " << endl;
printFileNames(calibrationPicturesLeftCamera);
cout << "<---- Right Camera's calibration Images ---->" << endl;
printFileNames(calibrationPicturesRightCamera);
}
char CalibrationPictures::getExit() const
{
return exit;
}
void CalibrationPictures::setExit(const char &value)
{
exit = value;
}
char CalibrationPictures::getStartTakingImages() const
{
return startTakingImages;
}
void CalibrationPictures::setStartTakingImages(char value)
{
startTakingImages = value;
}
String CalibrationPictures::getPathCalibrationPicturesLeftCamera() const
{
return pathCalibrationPicturesLeftCamera;
}
void CalibrationPictures::setPathCalibrationPicturesLeftCamera(const String &value)
{
pathCalibrationPicturesLeftCamera = value;
}
String CalibrationPictures::getPathCalibrationPicturesRightCamera() const
{
return pathCalibrationPicturesRightCamera;
}
void CalibrationPictures::setPathCalibrationPicturesRightCamera(const String &value)
{
pathCalibrationPicturesRightCamera = value;
}
String CalibrationPictures::getPathLeftCamera() const
{
return pathLeftCamera;
}
void CalibrationPictures::setPathLeftCamera(const String &value)
{
pathLeftCamera = value;
}
String CalibrationPictures::getPathRightCamera() const
{
return pathRightCamera;
}
void CalibrationPictures::setPathRightCamera(const String &value)
{
pathRightCamera = value;
}
int CalibrationPictures::getNumOfSavingImages() const
{
return numOfSavingImages;
}
void CalibrationPictures::setNumOfSavingImages(int value)
{
numOfSavingImages = value;
}
vector<cv::String>
CalibrationPictures::getCalibrationPicturesLeftCamera() const {
return calibrationPicturesLeftCamera;
}
void CalibrationPictures::setCalibrationPicturesLeftCamera(
const vector<cv::String> &value) {
calibrationPicturesLeftCamera = value;
}
vector<cv::String>
CalibrationPictures::getCalibrationPicturesRightCamera() const {
return calibrationPicturesRightCamera;
}
void CalibrationPictures::setCalibrationPicturesRightCamera(
const vector<cv::String> &value) {
calibrationPicturesRightCamera = value;
}