# Irregular Workpiece Template-Matching Algorithm Using Contour Phase
## 1 Introduction  
At present, the world is going through the transformation of Industry 4.0. In order to successfully transition to Industry 4.0, companies must develop and implement certain key technologies of Industry 4.0 [1]. Machine vision technology is one of the key technologies of Industry 4.0, and the application of machine vision has gradually been added to many machines and production lines and is playing an increasingly important role. It can be used for product quality inspection and target positionings, such as some appearance defect detection and accurate positioning of precision workpieces. Machine vision can also be used for hazardous tasks in some hazardous environments that are not suitable for direct human operation. Additionally, in some workpiece inspection tasks, compared with the human eye's inspection, machine vision systems can greatly improve the inspection accuracy and inspection efficiency, their own capabilities being incomparable to the human eye. Because machine vision plays an increasingly important role today, research on machine vision has also become popular. In machine vision, the technology of judging the object input to the computer by comparing it with the template in the sample database is called template matching [2,3]. Identifying and locating objects is an important research topic, and template matching plays an important role in it. With the continuous development of template-matching technology [4], this is widely used in industry and agriculture. In recent years, the shortage of labor and the increasing demands of workers on the working environment has made the spraying industry more and more automated. Regular workpieces usually use the robot's teaching program to realize the automatic glue-spraying process. However, due to their irregular shape, it is difficult to locate the position and posture of irregular workpieces directly. In the field of image processing, template matching searches for the existence of a known template in another image based on a known object image (i.e., template). This method is best suited for the localization of irregular workpieces if there is a target workpiece whose position needs to be located in order to guide the robot for painting [5]Therefore, the theoretical significance and practical application of template matching have great research value [6]. Template-matching algorithms are a common feature acquisition method, which has been well applied in various fields of production and life. However, the accuracy of template matching is affected to some extent by light, background, and occlusion. When the size and rotation angle of the object change, the number of templates will increase, which will increase the time of template matching and affect the efficiency of matching. In recent years, research on the efficiency and robustness of template matching has made some progress [7; 8; 9; 10; 11; 12; 13]. Regarding the template-matching algorithm, its general features can be divided into two categories. The first category is template-matching algorithms based on grayscale information [14; 15]. It completes the matching between the target image and the template image by calculating the similarity between the template and the target image. This template-matching method is relatively simple in principle and easy to implement, and can meet real-time requirements. In some well-lit environments, it can also obtain relatively satisfactory results. However, in the actual environment, the illumination is often uneven, which leads to poor matching results. Another category is template-matching methods based on geometric features [16; 17]. The features applied to template matching can generally be divided into point features, surface features, and line features. Compared with the difficulty and indistinct features in the extraction of surface features and line features, point features are widely used and studied because of their simple, clear and robust extraction process.