eyemNCCBasedMatch.h
4.1 KB
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
#pragma once
//
// eyemNCCBasedMatchͷ
//
#ifndef __EYEM_NCCBASEDMATCH_H
#define __EYEM_NCCBASEDMATCH_H
#include "eyemLib.h"
class ncc_based_matching
{
public:
ncc_based_matching() {};
~ncc_based_matching(void);
int create_ncc_model(cv::Mat&, int iMinReduceArea);
int find_ncc_model(cv::Mat& tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, float* fCenterX, float* fCenterY, float* fMatchScore, float* fMatchAngle);
void draw_match_shapes();
private:
struct s_TemplData
{
std::vector<cv::Mat> vecPyramid;
std::vector<cv::Scalar> vecTemplMean;
std::vector<double> vecTemplNorm;
std::vector<double> vecInvArea;
std::vector<BOOL> vecResultEqual1;
BOOL bIsPatternLearned;
int iTopLayer;
void clear()
{
std::vector<cv::Mat>().swap(vecPyramid);
std::vector<double>().swap(vecTemplNorm);
std::vector<double>().swap(vecInvArea);
std::vector<cv::Scalar>().swap(vecTemplMean);
std::vector<BOOL>().swap(vecResultEqual1);
}
void resize(int iSize)
{
vecTemplMean.resize(iSize);
vecTemplNorm.resize(iSize, 0);
vecInvArea.resize(iSize, 1);
vecResultEqual1.resize(iSize, FALSE);
}
s_TemplData()
{
bIsPatternLearned = FALSE;
iTopLayer = 0;
}
};
struct s_MatchParameter
{
cv::Point2d pt;
double dMatchScore;
double dMatchAngle;
//Mat matRotatedSrc;
cv::Rect rectRoi;
double dAngleStart;
double dAngleEnd;
cv::RotatedRect rectR;
cv::Rect rectBounding;
BOOL bDelete;
double vecResult[3][3];//for subpixel
int iMaxScoreIndex;//for subpixel
BOOL bPosOnBorder;
cv::Point2d ptSubPixel;
double dNewAngle;
s_MatchParameter(cv::Point2f ptMinMax, double dScore, double dAngle)//, Mat matRotatedSrc = Mat ())
{
pt = ptMinMax;
dMatchScore = dScore;
dMatchAngle = dAngle;
bDelete = FALSE;
dNewAngle = 0.0;
bPosOnBorder = FALSE;
}
s_MatchParameter()
{
double dMatchScore = 0;
double dMatchAngle = 0;
}
~s_MatchParameter()
{
}
};
struct s_SingleTargetMatch
{
cv::Point2d ptLT, ptRT, ptRB, ptLB, ptCenter;
double dMatchedAngle;
double dMatchScore;
};
cv::Mat m_matSrc;
cv::Mat m_matDst;
cv::Mat showResult;
s_TemplData m_TemplData;
std::vector<s_SingleTargetMatch> m_vecSingleTargetData;
int getTopLayer(cv::Mat&, int);
void drawDashLine(cv::Mat& matDraw, cv::Point ptStart, cv::Point ptEnd, cv::Scalar color1 = cv::Scalar(0, 0, 255), cv::Scalar color2 = cv::Scalar::all(255));
void drawMarkCross(cv::Mat& matDraw, int iX, int iY, int iLength, cv::Scalar color, int iThickness);
static bool compareScoreBig2Small(const s_MatchParameter& lhs, const s_MatchParameter& rhs) { return lhs.dMatchScore > rhs.dMatchScore; }
static bool comparePtWithAngle(const std::pair<cv::Point2f, double>& lhs, const std::pair<cv::Point2f, double>& rhs) { return lhs.second < rhs.second; }
static bool compareMatchResultByScore(const s_SingleTargetMatch& lhs, const s_SingleTargetMatch& rhs) { return lhs.dMatchScore > rhs.dMatchScore; }
static bool compareMatchResultByPosX(const s_SingleTargetMatch& lhs, const s_SingleTargetMatch& rhs) { return lhs.ptCenter.x < rhs.ptCenter.x; }
void filterWithScore(std::vector<s_MatchParameter>* vec, double dScore);
void filterWithRotatedRect(std::vector<s_MatchParameter>* vec, int iMethod, double dMaxOverLap);
void sortPtWithCenter(std::vector<cv::Point2f>& vecSort);
cv::Point2f ptRotatePt2f(cv::Point2f ptInput, cv::Point2f ptOrg, double dAngle);
cv::Size bestRotationSize(cv::Size sizeSrc, cv::Size sizeDst, double dRAngle);
BOOL subPixEsimation(std::vector<s_MatchParameter>* vec, double* dNewX, double* dNewY, double* dNewAngle, double dAngleStep, int iMaxScoreIndex);
void getRotatedROI(cv::Mat& matSrc, cv::Size size, cv::Point2f ptLT, double dAngle, cv::Mat& matROI);
cv::Point nextMaxLoc(cv::Mat& matResult, cv::Point ptMaxLoc, double dMinValue, int iTemplateW, int iTemplateH, double& dMaxValue, double dMaxOverlap);
void m_matchTemplate(cv::Mat& matSrc, s_TemplData* pTemplData, cv::Mat& matResult, int iLayer);
void TM_CCOEFF_Denominator(cv::Mat& matSrc, s_TemplData* pTemplData, cv::Mat& matResult, int iLayer);
};
ncc_based_matching nbm;
#endif/* __EYEM_NCCBASEDMATCH_H */