Skip to content

Commit 79541ff

Browse files
committed
[feat] add PIMPL of Positioning
1 parent 6142a55 commit 79541ff

File tree

6 files changed

+125
-77
lines changed

6 files changed

+125
-77
lines changed

include/attribute.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef _ATTRIBUTE_H_
2+
#define _ATTRIBUTE_H_
3+
namespace ipo {
4+
enum class DynamicThresholdTypes {
5+
DYNAMIC_THRES_LIGHT = 0,
6+
DYNAMIC_THRES_DARK = 1,
7+
DYNAMIC_THRES_LIGHT_AND_DARK_INRANGE = 2,
8+
DYNAMIC_THRES_LIGHT_OR_DARK_OUTRANGE = 3,
9+
};
10+
enum PositioningTypeEnums {
11+
FEATURE_MATCHING = 0,
12+
TEMPLATE_MATCHING = 1,
13+
};
14+
enum PositioningRectEnums {
15+
TEMPLATE_IMG_RECT = 0,
16+
SEARCHING_IMG_RECT = 1,
17+
};
18+
enum FeatureAttributeEnums {
19+
HESSIAN_THRESHOLD = 0, // 100~3000
20+
LOWE_RATIO = 1, // 0~1.0
21+
};
22+
enum TemplateAttributeEnums {
23+
ANGLE_TOLERANCE = 0, // 0~180
24+
NUMBER_OF_LEVELS = 1, // 1~5
25+
THRESHOLD_SCORE = 2, // 0~1.0
26+
};
27+
}; // namespace ipo
28+
29+
#endif // _ATTRIBUTE_H_

include/component/image_proc.h

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#ifndef _IMAGE_PROC_H_
22
#define _IMAGE_PROC_H_
33

4-
// #include "common.h"
5-
// #include "opencv2/highgui.hpp"
6-
// #include "opencv2/imgcodecs.hpp"
4+
#include "attribute.h"
75
#include "opencv2/core.hpp"
8-
// #include "opencv2/imgproc.hpp"
6+
#include "opencv2/highgui.hpp"
7+
#include "opencv2/imgcodecs.hpp"
98

109
namespace ipo {
11-
12-
enum class DynamicThresholdTypes {
13-
DYNAMIC_THRES_LIGHT = 0,
14-
DYNAMIC_THRES_DARK = 1,
15-
DYNAMIC_THRES_LIGHT_AND_DARK_INRANGE = 2,
16-
DYNAMIC_THRES_LIGHT_OR_DARK_OUTRANGE = 3,
17-
};
18-
1910
/**
2011
* @brief Calculate the diff value between subtraction of grayscale image and fuzzy image. If the value exceed the offset value, then it equal to 255, and vice versa.
2112
* @param src input image.
@@ -53,5 +44,21 @@ int GetNewRotatedImageSize(const cv::Mat &src, const double &angle, int &width,
5344
cv::Mat ImageRotateByCenterAndAdjustBoundary(const cv::Mat &src, const double &angle);
5445
cv::Mat ImageRotate(const cv::Mat &src, const double &angle, const cv::Point &center);
5546
cv::Mat ImageShift(const cv::Mat &src, const cv::Point2f &from_pt, const cv::Point2f &to_pt);
47+
48+
//====Positioning (PIMPL)====
49+
class Positioning {
50+
public:
51+
Positioning(const PositioningTypeEnums &type);
52+
~Positioning();
53+
int SetGoldenSampleImage(const cv::Mat &golden_sample_img);
54+
int SetRect(const PositioningRectEnums &rect_type, const cv::Rect &rect);
55+
int SetAttribute(const int &attribute_type, const double &value);
56+
cv::Mat GetResult(const cv::Mat &sample_img);
57+
58+
private:
59+
class PimplPositioning;
60+
std::auto_ptr<PimplPositioning> p_pimplPositioning;
61+
};
62+
5663
} // namespace ipo
5764
#endif // _IMAGE_PROC_H_

include/component/positioning.h

+11-62
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
#ifndef _POSITIONING_H_
22
#define _POSITIONING_H_
33

4+
#include "attribute.h"
45
#include "common.h"
56
#include "image_proc.h"
67
namespace ipo {
7-
enum PositioningTypeEnums {
8-
FEATURE_MATCHING = 0,
9-
TEMPLATE_MATCHING = 1,
10-
};
11-
enum PositioningRectEnums {
12-
TEMPLATE_IMG_RECT = 0,
13-
SEARCHING_IMG_RECT = 1,
14-
};
15-
enum FeatureAttributeEnums {
16-
HESSIAN_THRESHOLD = 0, // 100~3000
17-
LOWE_RATIO = 1, // 0~1.0
18-
};
19-
enum TemplateAttributeEnums {
20-
ANGLE_TOLERANCE = 0, // 0~180
21-
NUMBER_OF_LEVELS = 1, // 1~5
22-
THRESHOLD_SCORE = 2, // 0~1.0
23-
};
24-
258
class IPositioning {
269
public:
2710
virtual int SetGoldenSampleImage(const cv::Mat &golden_sample_img) = 0;
@@ -81,53 +64,19 @@ class TemplateMatching : public IPositioning {
8164
class Creator {
8265
public:
8366
// virtual void Create(const PositioningTypeEnums &type) = 0;
67+
protected:
68+
IPositioning *ptr;
8469
};
8570

86-
class Positioning : public Creator {
71+
class Positioning::PimplPositioning : public Creator {
8772
public:
88-
Positioning(const PositioningTypeEnums &type) {
89-
switch (type) {
90-
case PositioningTypeEnums::FEATURE_MATCHING: {
91-
ptr = new FeatureMatching();
92-
break;
93-
}
94-
case PositioningTypeEnums::TEMPLATE_MATCHING: {
95-
ptr = new TemplateMatching();
96-
break;
97-
}
98-
default: {
99-
std::cout << "(enum)PositioningTypeEnums There is no such enum in the enumeration list." << std::endl;
100-
std::cout << "Switch to the default algorithm : TemplateMatching" << std::endl;
101-
break;
102-
}
103-
}
104-
}
105-
~Positioning() {
106-
delete ptr;
107-
}
108-
int SetGoldenSampleImage(const cv::Mat &golden_sample_img) {
109-
if (ptr->SetGoldenSampleImage(golden_sample_img) != 0) {
110-
return -1;
111-
}
112-
return 0;
113-
}
114-
int SetRect(const PositioningRectEnums &rect_type, const cv::Rect &rect) {
115-
if (ptr->SetRect(rect_type, rect) != 0) {
116-
return -1;
117-
}
118-
return 0;
119-
}
120-
int SetAttribute(const int &attribute_type, const double &value) {
121-
if (ptr->SetAttribute(attribute_type, value) != 0)
122-
return -1;
123-
return 0;
124-
}
125-
cv::Mat GetResult(const cv::Mat &sample_img) {
126-
return ptr->GetResult(sample_img);
127-
}
128-
129-
private:
130-
IPositioning *ptr;
73+
// PimplPositioning();
74+
PimplPositioning(const PositioningTypeEnums &type);
75+
~PimplPositioning();
76+
int SetGoldenSampleImage(const cv::Mat &golden_sample_img);
77+
int SetRect(const PositioningRectEnums &rect_type, const cv::Rect &rect);
78+
int SetAttribute(const int &attribute_type, const double &value);
79+
cv::Mat GetResult(const cv::Mat &sample_img);
13180
};
13281

13382
//=========method 2=========

main.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "component/image_proc.h"
2-
#include "component/positioning.h"
2+
33
// ---load image---
44
cv::Mat &&src = cv::imread("../images/Okonomiyaki.png");
55
/*
@@ -15,7 +15,7 @@ cv::Mat &&src = cv::imread("../images/Okonomiyaki.png");
1515
------positioning------
1616
8 : positioning by feature matching(SURF)
1717
9 : positioning by template matching
18-
10 :
18+
10 :
1919
*/
2020
#define index 9
2121

@@ -157,5 +157,6 @@ int main() {
157157
cv::waitKey(0);
158158
}
159159
#elif index == 10
160-
160+
int main() {
161+
}
161162
#endif

src/component/image_proc.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,6 @@ cv::Mat ImageShift(const cv::Mat &src, const cv::Point2f &from_pt, const cv::Poi
479479
return dst.clone();
480480
}
481481

482+
//====PositioningCreator====
483+
482484
} // namespace ipo

src/component/positioning.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
#include "image_proc.h"
44

55
using namespace ipo;
6+
7+
//===========PIMPL (Positioning)===========
8+
// Positioning::Positioning() : p_pimplPositioning(new PimplPositioning){}
9+
Positioning::Positioning(const PositioningTypeEnums &type) : p_pimplPositioning(new PimplPositioning(type)) {}
10+
Positioning::~Positioning() {}
11+
int Positioning::SetGoldenSampleImage(const cv::Mat &golden_sample_img) {
12+
return p_pimplPositioning->SetGoldenSampleImage(golden_sample_img);
13+
}
14+
int Positioning::SetRect(const PositioningRectEnums &rect_type, const cv::Rect &rect) {
15+
return p_pimplPositioning->SetRect(rect_type, rect);
16+
}
17+
int Positioning::SetAttribute(const int &attribute_type, const double &value) {
18+
return p_pimplPositioning->SetAttribute(attribute_type, value);
19+
}
20+
cv::Mat Positioning::GetResult(const cv::Mat &sample_img) {
21+
return p_pimplPositioning->GetResult(sample_img);
22+
}
23+
624
//===========FeatureMatching============
725
int FeatureMatching::SetGoldenSampleImage(const cv::Mat &golden_sample_img) {
826
if (golden_sample_img.empty()) {
@@ -391,3 +409,45 @@ cv::Mat TemplateMatching::GetResult(const cv::Mat &sample_img) {
391409
dst = ImageShift(dst, maxLoc, cv::Point(template_rect.x, template_rect.y));
392410
return dst.clone();
393411
}
412+
413+
//====class Positioning====
414+
Positioning::PimplPositioning::PimplPositioning(const PositioningTypeEnums &type) {
415+
switch (type) {
416+
case PositioningTypeEnums::FEATURE_MATCHING: {
417+
this->ptr = new FeatureMatching();
418+
break;
419+
}
420+
case PositioningTypeEnums::TEMPLATE_MATCHING: {
421+
this->ptr = new TemplateMatching();
422+
break;
423+
}
424+
default: {
425+
std::cout << "(enum)PositioningTypeEnums There is no such enum in the enumeration list." << std::endl;
426+
std::cout << "Switch to the default algorithm : TemplateMatching" << std::endl;
427+
break;
428+
}
429+
}
430+
}
431+
Positioning::PimplPositioning::~PimplPositioning() {
432+
delete this->ptr;
433+
}
434+
int Positioning::PimplPositioning::SetGoldenSampleImage(const cv::Mat &golden_sample_img) {
435+
if (this->ptr->SetGoldenSampleImage(golden_sample_img) != 0) {
436+
return -1;
437+
}
438+
return 0;
439+
}
440+
int Positioning::PimplPositioning::SetRect(const PositioningRectEnums &rect_type, const cv::Rect &rect) {
441+
if (this->ptr->SetRect(rect_type, rect) != 0) {
442+
return -1;
443+
}
444+
return 0;
445+
}
446+
int Positioning::PimplPositioning::SetAttribute(const int &attribute_type, const double &value) {
447+
if (this->ptr->SetAttribute(attribute_type, value) != 0)
448+
return -1;
449+
return 0;
450+
}
451+
cv::Mat Positioning::PimplPositioning::GetResult(const cv::Mat &sample_img) {
452+
return this->ptr->GetResult(sample_img);
453+
}

0 commit comments

Comments
 (0)