# Irregular Workpiece Template-Matching Algorithm Using Contour Phase
## 1 Introduction
But no matter what method is used, it only achieves the purpose of successful matching, and can further give the center position of the target workpiece, but it cannot measure the rotation angle of the workpiece well. In order to use the robot to grasp and spray the workpiece automatically, it is also necessary to know the rotation angle of the workpiece relative to the template. The classic template-matching algorithm needs to traverse all the location points to be searched in the reference image [18]. This exhaustive search algorithm is computationally intensive, slow, and has no good practical value [19]. Given that the classical template-matching algorithm has the disadvantages of being computationally intensive and time-consuming, the researchers proposed to reduce the computation by using a fast template-matching algorithm, simplifying the correlation metric function or using a non-orthogonal search strategy [20]. For regular workpieces, the literature [21; 22; 23] proposed a method to proxy the amount of workpiece rotation by the rotation of the external rectangle of the workpiece, which more accurately calculates the rotation of the regular set of workpieces with respect to the stencil workpiece. Reference [18] defines a saliency constraint similarity measurement method for the automatic recognition of planar objects with irregular shapes and low heights in complex backgrounds, so as to achieve accurate matching of planar object contours. Reference [24] used the Hausdorff distance for the registration of the template image, and used the classification algorithm of the support vector machine to detect and classify the defects of the PCB board. In [25], using five white circular features around the charging port (CP), the distance to the center of the ellipse is obtained according to the principle that the center is the furthest point from the contour. In addition, the pose information on the CP is obtained by the geometric solution method. Under 4 flux light intensity, the positioning error of this method is 1.4 mm, the angle error is 1.6\({}^{\circ}\), and the insertion success rate is 98.9%. The cluster template-matching algorithm (CTMA) proposed in [26] uses contour matching and logarithmic evaluation metrics to obtain matching positions. Based on the image deformation rate and zoom rate, a matching template is established to achieve fast and accurate matching of textureless circular features and complex light fields. Reference [27] combines the pixel statistics method with the template-matching method and proposes a new fastener positioning method called local unidirectional template matching (LUTM). According to the experimental results of reference [27], the method described can effectively realize the precise positioning of ballastless track and track fasteners with ballast simultaneously. In order to solve the problem of slow speed and a large amount of calculation of traditional template-matching algorithms in power image recognition, reference [28] proposes a second template-matching algorithm for fast identification of target images. The algorithm can accurately identify and locate electric power equipment, detect equipment faults, and improve the matching speed. Reference [29] proposed an improved template-matching algorithm for tube-to-tube sheet-welding positioning, which can automatically create a template for each image, instead of using one template to match all tube images, and the matching result can accurately locate the target tube. Reference [30] proposed a template-matching method based on direction code, which roughly estimates the rotation angle, which struggles to play a role in practical applications. Combining the above research, this paper proposes a template-matching algorithm based on contour phase difference to better obtain accurate information of irregular workpiece poses. We will briefly describe the stencil matching based on geometric features and Hu-invariant moments and its shortcomings in Section 2, which leads to the algorithm proposed in this paper.