forked from beanyoung/MatchTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_template.h
152 lines (136 loc) · 3.43 KB
/
match_template.h
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
#ifndef MATCH_TEMPALTE_H_
#define MATCH_TEMPALTE_H_
#include "cv.h"
#include "highgui.h"
/**
* @class ShiftValue
* @author BeanYoung
* @date 06/25/2011
* @file match_template.h
* @brief contain the shift value
*/
struct ShiftValue
{
double dX;
double dY;
double dAngle;
};
/**
* @brief find best pTemplate in pSrc and the shift result saved in iResult
* @param pTemplate: template image
* @param pSrc: source image,where the template to be located
* @param dAngle: rotate from -dAngle to +dAngle
* @param dScore: pass threshold
* @param iResult: x,y and angle
* @return -1 input params error
* 0 match error
* 1 match success
*/
int MatchTemplate(const IplImage* pTemplate,
const IplImage* pSource,
double dAngle,
double dScore,
ShiftValue& iResult);
/**
* @brief get the pyrdowned nTimes image
* @param pSource
* @param nTime
* @return pyrdowned image
*/
IplImage* GetPyrDownImage(const IplImage* pSource, int nTime);
/**
* @brief
* @param pTemplate: template to be matched
* @param pSource: source image to be matched
* @param dAngle: the rotate angle range is between -dAngle and dAngle
* @param dStep: distance between each iterator
* @param iShift: shift params
* @return -1 input params error
* 0 match error
* 1 match success
*/
int MatchWithAngle(const IplImage* pTemplate,
const IplImage* pSource,
double dAngle,
double dStep,
ShiftValue& iShift);
/**
* @brief rotate pSource image with dAngle
* @param pSource
* @param dAngle
* @return if success return rotated image
* else return NULL
*/
IplImage* RotateImage(const IplImage* pSource, double dAngle);
/**
* @brief transfer the iShiftParam from (first angle, second transfer)
* to (laser engraving)
* @param dX
* @param dY
* @param iSrcShiftParam
* @param iDstShiftParam
*/
void TranferCoordinate(double dX, double dY,
const ShiftValue& iSrcShiftParam,
ShiftValue& iDstShiftParam);
/**
* @brief rotate the SrcPoint with Angle
* @param iSrcPoint
* @param dAngle
* @param iDstPoint
*/
int GetRotatedPoint(const CvPoint& iSrcPoint,
double dAngle,
CvPoint& iDstPoint);
/**
* @brief
* @param pSourceImage
* @param iTemplateSize
* @param iCenterPoint
* @param dExpand: expand range from 0 to max
* @param iTopLeftPoint: return top-left point of ROI
* @return 1: success
* -1: input param is NULL
* 0: unsuccess
*/
int SetImageROIWithCenterPoint(IplImage* pSourceImage,
CvSize iTemplateSize,
CvPoint iCenterPoint,
double dExpand,
CvPoint& iTopLeftPoint);
/**
* @brief draw the rect and center
* @param pSourceImage
* @param iTemplateSize
* @param iShiftParam
* @param dColor
*/
void DrawResult(IplImage* pSourceImage,
CvSize iTemplateSize,
ShiftValue iShiftParam,
double dColor);
/**
* @brief add iA to iB and save the result in iC
* @param iA
* @param iB
* @param iC
*/
void AddShiftParams(ShiftValue& iA, ShiftValue& iB, ShiftValue& iC);
/**
* @brief first canny SourceImage and then expand the edge with witdh nWidth
* @param pSourceImage
* @param pEdge
* @param nWidth
*/
int ExpandEdge(const IplImage* pSourceImage, IplImage* pEdge, int nWidth);
/**
* @brief get the min pyrdown time
* @param iTemplateSize
* @param iSourceSize
* @param nMinLength
* @return
*/
int GetPyrdownTime(CvSize iTemplateSize,
CvSize iSourceSize,
int nMinLength);
#endif