Skip to content

Commit dbc35aa

Browse files
committed
Updated Vec class and testing less memory hungry structure for storing data
1 parent 356e717 commit dbc35aa

File tree

6 files changed

+7609
-17
lines changed

6 files changed

+7609
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,4 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289+
/Doc

testOpenCV/MiniCalc.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ class MiniCalc {
281281

282282
v2<double> sum;
283283
auto gab = false;
284-
auto result = false;
285284

286285
for (auto i = first; i < size; ++i) {
287286
if (elements[i].y > target.rows - barrier)
@@ -304,15 +303,11 @@ class MiniCalc {
304303
line(target, elements[i], elements[i + 1], Scalar(255, 255, 255), 1, LINE_AA);
305304
sum.x += abs(elements[i + 1].x - elements[i].x);
306305
sum.y += abs(elements[i + 1].y - elements[i].y);
307-
result = true;
308306
}
309307
gab ^= true;
310308
}
311309

312-
if (result)
313-
return sum;
314-
315-
return v2<double>(0.0, 0.0);
310+
return sum;
316311
}
317312

318313
static double computeYSum(vi& elements) {

testOpenCV/ThicknessGauge.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ImageSave.h"
66
#include "CaptureFailException.h"
77
#include "Specs.h"
8+
#include <array>
89

910
int ThicknessGauge::getBaseLine() const {
1011
return baseLine_;
@@ -147,7 +148,6 @@ bool ThicknessGauge::generatePlanarImage() {
147148
if (!cap.isOpened()) // check if we succeeded
148149
throw CaptureFailException("Error while attempting to open capture device.");
149150

150-
Point textPoint(100, 100);
151151
Size blurSize(3, 3);
152152

153153
const auto alpha = 0.5;
@@ -172,11 +172,17 @@ bool ThicknessGauge::generatePlanarImage() {
172172

173173
ImageSave is("pic_x", SaveType::Image_Png, Information::Basic);
174174

175-
const int arrayLimit = 512; // shit c++11 ->
175+
const auto arrayLimit = 512; // shit c++11 ->
176176

177177
Mat frame;
178-
Mat outputs[arrayLimit];
179-
vi pix_planarMap[arrayLimit];
178+
vector<Mat> outputs(frameCount_);
179+
vector<vi> pix_Planarmap(frameCount_ * 2); // using double of these for testing
180+
vector<v2<double>> gabs(frameCount_);
181+
182+
//array<Mat, arrayLimit> outputs;
183+
//array<vi, arrayLimit> pix_planarMap;
184+
//array<v2<int>, arrayLimit> gabs;
185+
180186
vi nonZero;
181187

182188
// capture first frame
@@ -221,7 +227,6 @@ bool ThicknessGauge::generatePlanarImage() {
221227
//createTrackbar("Kernel size: 2n +1", dilationWindowName, &dilation_size, max_ed_kernel_size);
222228
}
223229

224-
225230
// test for video recording
226231
if (saveVideo_) {
227232
is.SetInformation(Information::Full);
@@ -237,10 +242,14 @@ bool ThicknessGauge::generatePlanarImage() {
237242
vector<Point2d> test_subPix;
238243

239244
// configure output stuff
240-
for (auto i = 0; i < frameCount_; ++i) {
241-
pix_planarMap[i].reserve(imageSize_.width);
245+
for (auto& p : pix_Planarmap) {
246+
p.reserve(imageSize_.width);
242247
}
243248

249+
//for (auto i = 0; i < frameCount_; ++i) {
250+
// pix_planarMap[i].reserve(imageSize_.width);
251+
//}
252+
244253
// start the process of gathering information for set frame count
245254

246255
while (true) {
@@ -250,7 +259,7 @@ bool ThicknessGauge::generatePlanarImage() {
250259
for (auto i = 0; i < frameCount_; ++i) {
251260

252261
outputs[i] = Mat::zeros(imageSize_, CV_8UC1);
253-
pix_planarMap[i].clear();
262+
pix_Planarmap.at(i).clear();
254263

255264
cap >> frame;
256265

@@ -272,15 +281,18 @@ bool ThicknessGauge::generatePlanarImage() {
272281
if (showWindows_) imshow(outputWindowName, frame);
273282

274283
// extract information from the image, and make new output based on pixel intensity mean in Y-axis for each X point
275-
auto generateOk = miniCalc.generatePlanarPixels(frame, outputs[i], pix_planarMap[i], test_subPix);
284+
auto generateOk = miniCalc.generatePlanarPixels(frame, outputs[i], pix_Planarmap.at(i), test_subPix);
276285

277286
if (!generateOk) {
278287
cout << "Failed to map pixels to 2D plane for frame #" << to_string(i + 1) << " of " << to_string(frameCount_) << endl;
279288
break;
280289
}
281290

282-
findNonZero(outputs[i], pix_planarMap[arrayLimit - (1 + i)]);
283-
if (miniCalc.fillElementGabs(pix_planarMap[arrayLimit - (1 + i)], outputs[i], baseLine_)) {
291+
findNonZero(outputs[i], pix_Planarmap[arrayLimit - (1 + i)]);
292+
gabs.push_back(miniCalc.fillElementGabs(pix_Planarmap[arrayLimit - (1 + i)], outputs[i], baseLine_));
293+
if (gabs.back().hasValue()) {
294+
// at least one gab was filled..
295+
284296
//Mat temp(pix_planarMap[arrayLimit - (1 + i)]);
285297
//cout << "TEMP cols " << temp.cols << endl;
286298
//imshow("temp", temp);

testOpenCV/Vec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ class v2 {
147147
return det(that) == 0 ? 1 : 0;
148148
}
149149

150+
virtual bool hasValue() {
151+
return this->x != 0 || this->y != 0;
152+
}
153+
150154
};
151155

152156
template<class T>
@@ -213,6 +217,10 @@ class v3 : public v2<T> {
213217
return v3<T>(this->x, this->y, this->z) * that / (len() * that.len());
214218
}
215219

220+
bool hasValue() override {
221+
return this->x != 0 || this->y != 0 || this->z != 0;
222+
}
223+
216224
};
217225

218226
template<class T>

0 commit comments

Comments
 (0)