Design of online laser marking system by vision guided based on template matching

Industry 4.0 has put forward the requirements of improving the marking efficiency and accuracy of the laser marking industry, and manual placement has been unable to meet the production needs. In this paper, laser marking technology is combined with image recognition technology, and the automation of marking production process is realized by controlling the stepper motor to drive the conveyor belt, and accurate marking of arbitrarily placed workpiece is realized on the conveyor belt. The test results show that this marking system designed by us has high precision, and the yield of finished products reaches 99.5%, which provides a set of efficient and reliable solution for small and medium power laser marking production line to realize online positioning function.


The overall scheme design
Laser marking is another technological innovation after the application of laser cutting, laser drilling and laser welding technology [1,2,3]. It is a new type of non-contact processing, no chemical pollution and no wear and tear of the new marking processing technology mode.Laser marking machine can be divided into CO2 laser, fiber laser, green laser, UV laser, YAG laser according to the type of product [4,8]. Common marking methods include: mechanical positioning marking and visual positioning marking. At present, visual positioning marking is divided into offline and online [5,9]. The system designed in this paper is online visual guidance marking.
Visual positioning system consists of two basic elements: hardware and software. Hardware, as an important carrier of the image positioning system, is mainly responsible for the acquisition, transmission and image processing of image signals. Software is the key to image acquisition and processing. As shown in Figure 1, the visual positioning system sends product coordinates to the marking card, and the laser marking card controls the viroscope to mark the product at the specified position and rotation Angle. The testing machine is shown in Figure 2.  Table   Image collection and image  processing  Camera Stepper motor Figure 1. Visual guidance marking system architecture。 Figure 2. The testing machine.

Coaxial mechanical structure
We use coaxial mechanism to Build the imaging system, also known as BIV (Build Inside Vision) method.Coaxial visual position after laser marking machine scanning head output through the mirror laser, through visible light coupling of laser and CCD output, after photos of image information through software algorithm for the coordinate information and sent to the scanning mirror, so as to achieve the visual guidance marking function, as shown in Figure 3, the working principle of coaxial.  This method mainly adopts optical semi-translucent semi-reflective mirror, also known as spectroscope plate, splitter plate, is a kind of optical element that can be split according to the intensity ratio of the incident beam [6,7].The image of the product can be reflected from the lens to the camera, and the laser can be passed directly through the lens.

Camera and light source
In this system, the camera and light source need to be used together.A good lighting scheme should illuminate the object surface with uniform light, highlight the object features, increase the contrast between the object and the background, and provide conditions for subsequent image processing.The camera we chose for the system is a 6 megapixel black-and-white industrial camera with a circular LED light source.The captured image looks like Figure 4.

UseTemplate-Matching to find the product location
Template-Matching is one of the most representative methods in image recognition [10].It extracts several feature vectors from the image to be recognized and compares them with the corresponding feature vectors of the template, calculates the distance between the image and the template feature vectors, and uses the minimum distance method to determine the category.Template matching is usually preceded by the establishment of a standard template library and then the use of templates to find targets. Halcon's template matching algorithm is used in this paper. The effect is shown in Figure  4.

Transformation of spatial coordinate system
Laser marking system includes two coordinate systems: camera coordinate system and workbench coordinate system. Obviously, the camera coordinate system and the worksurface coordinate system are still relative to each other after the device is installed, so this is a simple two-dimensional coordinate transformation.
In the positioning system, camera imaging projects the object entity onto the imaging plane through the principle of optical lens, and this transformation can be described by imaging transformation, that is, the imaging model of the camera. In the description of camera imaging model, the commonly used coordinate system in the vision system must be analyzed first, and coordinate is the core element of the whole positioning. Firstly, image pixel coordinate system and physical coordinate system are transformed. The image collected by the camera is transformed into digital image by the image acquisition card and stored in the computer.  Figure 5. The relation between image coordinate system and physical coordinate system. As shown in Figure 5, Cartesian coordinate o1uv is defined on the digital image, and image pixels (u,v) are the number of columns and rows of the pixel in the array, respectively. Therefore, (u,v) is the coordinate of the pixel coordinate system, and the position of the pixel in the image is not expressed in physical units. Therefore, the image coordinate system OXY, represented by the physical unit mm, needs to be established again. The coordinate system takes the intersection point of the camera's optical axis and the imaging focal plane as the origin, and the X and Y axes are parallel to the U and V axes respectively. Let the coordinates of point O in the u and v coordinate systems be (u0, v0), and the physical dimensions of each pixel in the direction of X and Y axes be dx and dy, then any pixel in the image can be transformed into each other through the two-coordinate, as shown in Equation (1).
The above expression is translated into homogeneous matrix, as shown in Equation (2).
Secondly, the world coordinate system and camera coordinate system are transformed. The camera coordinate system OXYZ which satisfies the right-hand rule, takes the optical center O point of the camera as the origin of the coordinate system; X and Y axes are respectively X and Y axes parallel to the production line coordinate system; Z axis is the optical axis of the camera, which is perpendicular to the image plane; X, Y and Z intersect at the optical center O point of the camera, as shown in Figure  5. Since the location of the camera is very important for camera imaging, an absolute coordinate system is established in the working environment of the camera to describe the location of the camera installation. This coordinate system is called the world coordinate system. Finally, it is used as the reference coordinate system to define the coordinate positions of all objects on the production line. The relationship between the world coordinate system and the camera coordinate system is shown in Equations (3). The two coordinate systems can be installed each other to define the image position.
Where, R is a 3×3 orthogonal identity matrix; T is a three-dimensional translation vector; In addition, the camera coordinate system, the imaging plane coordinate system and the workpiece surface coordinate system share the same Z-axis, and the plane coordinate perpendicular to the Z-axis is equivalent, so it can be directly transformed. It needs to be pointed out that there is a fixed distance difference P between the three laser optical axes in the Y axis direction, and the coordinate of the workpiece captured by the camera and the marking coordinate need to be transformed through Equation (4).

Preventing duplicate marking
We want to prevent it from re-marking products that have already been marked.We need to determine the position of the conveyor belt relative to the camera. Assumptions, conveyor belt moving distance equals ΔU every time, and the conveyor braking distance error range is (-b, b), and the final location is equal to (x2, y2) and can be automatically updated.The conveyor belt moves the product continuously from left to right, so: • Determine the current positions of all products and record the coordinates (x1, y1) of these products relative to the original reference position.
• Compare the last recorded product coordinate (x2,y2) with the hypothesis coordinate(x',y'): Since we design a single-degree-of-freedom table and the conveyor belt is parallel to the camera plane, it can be assumed that the error in the vertical direction is always equal to zero. Therefore, when ΔX < b through Equation (5), the system determines that the product has been marked.   Table 1, this system has high production efficiency and marking accuracy, and the marking accuracy can reach 0.02mm, which has a great advantage compared with the other three production methods.

Conclusion
In this paper, we designed a laser marking system guided by machine vision positioning to achieve identification, positioning and continuous accurate marking tasks. Firstly, the coordinate system conversion method of image coordinate and physical coordinate of the camera in the coaxial mechanism is designed, and then the chaotic products are accurately positioned by the method of template matching, and the laser marking card is used to control the laser to mark the characters at the specified position and the specified Angle, so as to realize the fast marking on the conveyor belt. The experimental results show that the system greatly improves the production efficiency, and has higher precision and stability.