# Irregular Workpiece Template-Matching Algorithm Using Contour Phase
## 2 Template Matching Based on Geometric Features and Hu Invariant Moments  
### Construction of the Base Feature Vector  
The most frequently employed picture-invariant moment today was first presented by [PERSON], [PERSON] [31] in 1961. It is a series of invariant moments with image characteristics obtained by using a nonlinear combination of some regular moments. No matter how these photos are resized, rotated, or otherwise altered, these invariant moments stay the same. For a discrete two-dimensional image \(f(x,y)\), the \((p+q)\) order moments can be represented as follows in accordance with the definition of Hu invariant moments in the literature [31]:  
\[m_{pq}=\sum_{x}\sum_{y}x^{p}y^{q}f(x,y) \tag{1}\]  
The corresponding \((p+q)\) order central moments are shown below.  
\[m_{pq}=\sum_{x}\sum_{y}(x-\overline{x})^{p}(y-\overline{y})^{q}f(x,y) \tag{2}\]  
where \(p,q=0,\ 1,\ 2,\ \ldots,+\infty\), \(\overline{x}=\frac{m_{10}}{m_{00}},\overline{y}=\frac{m_{01}}{m_{00}},\overline {x},\overline{y}\) denote the gray center position of the image. According to Equation (1), the geometric moments are the projections of the image on the function \(x^{p}y^{q}\). The standardized \(()\) order central moments are shown as below [32].  
\[\eta_{pq}=\frac{m_{pq}}{m_{00}^{r}} \tag{3}\]  
where \(r=(p+q)/2\). Hu, [PERSON] generated seven image moments with invariance by expanding a nonlinear combination of second-order central moments and third-order central moments from the algebraic theory. These seven image moments are shown in Equation (4).  
\[\begin{gathered} M_{1}=\eta_{20}+\eta_{02}\\ M_{2}=(\eta_{20}-\eta_{02})^{2}+4\eta_{11}{}^{2}\\ M_{3}=(\eta_{30}-3\eta_{12})^{2}+(3\eta_{21}-\eta_{03})^{2}\\ M_{4}=(\eta_{30}+\eta_{12})^{2}+(\eta_{21}+\eta_{03})^{2}\\ M_{5}=(\eta_{30}-3\eta_{12})(\eta_{30}+\eta_{12})\Big{[}(\eta_{30}+ \eta_{12})^{2}-(3\eta_{21}-\eta_{03})^{2}\Big{]}+(3\eta_{21}-\eta_{03})[3(3 \eta_{21}+\eta_{03})^{2}-(\eta_{21}+\eta_{03})^{2}]\\ M_{6}=(\eta_{20}-\eta_{02})\Big{[}(\eta_{30}+\eta_{12})^{2}-(\eta_{2 1}+\eta_{03})^{2}\Big{]}+4\eta_{11}(\eta_{30}+\eta_{12})(\eta_{21}+\eta_{03}) \\ M_{7}=(3\eta_{21}-\eta_{03})(\eta_{21}+\eta_{03})\Big{[}3(\eta_{30}+ \eta_{22})^{2}-(\eta_{21}+\eta_{03})^{2}\Big{]}\end{gathered} \tag{4}\]It has been shown that the invariant moments based on second-order moments (i.e., \(M_{1}\), \(M_{2}\)) can better maintain the rotation, translation, and scaling of two-dimensional objects during the recognition of target objects in images. Other higher-order invariant moments bring larger errors and have little impact on object recognition. Therefore, in this paper, \(M_{1}\) and \(M_{2}\) invariant moments are selected as components of the artifact base feature vector. To enhance the accuracy of the base feature vector, additional constraints need to be added to the base feature vector. In this paper, area, circumference (contour points), the ratio of long to short radius, mean radius and radius variance are selected as the remaining constrained feature values, which together with \(M_{1}\) and \(M_{2}\) form the base feature vector of the artifact image.