Multi-target and multi-angle continuous measurement algorithm based on template matching
By using template matching algorithms to perform multi-objective and multi-angle measurements in the image measuring instrument, the problems of traditional measurement efficiency and accuracy error are solved, efficient and accurate measurements are achieved, and production efficiency and product quality are improved.
Patent Information
- Application Number
- CN202411028999.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-15
AI Technical Summary
Traditional image measuring instruments are inefficient when performing single measurements, and measurement size selection based on different references can lead to accuracy errors.
A multi-objective and multi-angle continuous measurement algorithm based on template matching is adopted. By establishing a reference measurement template, multi-objective and multi-angle template matching is performed, the translation reference points are calculated, and the measurement dimension coordinates of the target image are obtained using the rotation transformation formula.
It improves measurement efficiency and product quality, reduces measurement errors and production losses, enhances the competitiveness and market share of the enterprise, and promotes the development of manufacturing to intelligence, flexibility and customization.
Smart Images

Figure CN118967770A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing algorithms, and in particular to a multi-target, multi-angle continuous measurement algorithm based on template matching. Background Art
[0002] In modern production, it is often necessary to measure the dimensions of workpieces to determine whether the products meet production standards. Traditional production mainly uses manual measurement methods, which have a limited measurement range and the accuracy is also affected by subjective factors.
[0003] The existing image measuring instrument is a high-precision optical image measuring instrument composed of a high-resolution CCD color lens, a continuously variable magnification objective lens, a color display, a video crosshair display, a precision grating ruler, a multi-functional data processor, data measurement software and a high-precision workbench structure. It can quickly read the displacement value of the optical ruler and generate a graph on the screen for the operator to compare the image and the graph, so that the possible deviation of the measurement result can be intuitively distinguished, and the accuracy is higher than that of manual measurement.
[0004] However, traditional image measuring instruments use single-time measurement technology. If there is a need for 100% inspection of a large number of workpieces, relying solely on inspection and measurement one by one is not only inefficient, but also selecting measurement dimensions based on different benchmarks will also cause certain accuracy errors. Summary of the invention
[0005] The purpose of the present invention is to provide a multi-target, multi-angle continuous measurement algorithm based on template matching, which solves the problem that the traditional image measuring instrument performs single measurement technology. Relying on one-by-one detection and measurement is not only inefficient, but also causes certain accuracy errors when selecting measurement dimensions based on different benchmarks.
[0006] To achieve the above object, the present invention provides a multi-target, multi-angle continuous measurement algorithm based on template matching, comprising the following steps:
[0007] Establishing benchmark measurement templates;
[0008] Overlay the reference measurement template image on the target image to perform multi-target and multi-angle template matching;
[0009] Calculate the translation reference point;
[0010] The measured dimensions are matched to obtain the measured dimensions of the reference template corresponding to the target.
[0011] Wherein, the step of establishing a reference measurement template further includes:
[0012] A standard workpiece is used for template image registration. When registering and measuring the template image, the size parameters of the workpiece that need to be measured are clarified. The registered template parameters are saved in the software database for subsequent matching measurements.
[0013] Wherein, the reference measurement template image is overlaid on the target image to perform multi-target and multi-angle template matching, and the steps further include:
[0014] When performing multi-angle template matching, the template image is rotated 360° with a step size of 1° and then matched with the target image.
[0015] Wherein, the reference measurement template image is overlaid on the target image to perform multi-target and multi-angle template matching, and the steps further include:
[0016] When performing multi-angle template matching, the target image is rotated 360° with a step size of 1° and then matched with the template image.
[0017] Wherein, the reference measurement template image is overlaid on the target image to perform multi-target and multi-angle template matching, and the steps further include:
[0018] When performing multi-target matching, a threshold is set. If the score value is greater than the threshold, all the matched results are saved as candidate matching results;
[0019] When the candidate matching area is the same target and multiple matching results are obtained, the non-maximum suppression algorithm is used to filter out the overlapping areas and only retain the best matching area.
[0020] Among them, calculating the translation reference point, the step also includes
[0021] The center point of the target image is used as the translation reference point.
[0022] The measurement dimensions are matched to obtain the reference template measurement dimensions corresponding to the target, and the step further includes:
[0023] The translation and rotation transformation parameters required for matching the target image with the template image are calculated, and the size coordinates of the target image relative to the template image that need to be measured are obtained using the rotation transformation formula.
[0024] The rotation transformation formula is:
[0025] The coordinate position of a point (x, y) after rotating counterclockwise by angle θ around an arbitrary point p (dx, dy) is (x1, y1):
[0026] x1=dx+(x-dx)·cos(θ)-(y-dy)·sin(θ)
[0027] y1=dy+(x-dx)·sin(θ)+(y-dy)·cos(θ).
[0028] The present invention is a multi-target, multi-angle continuous measurement algorithm based on template matching. The premise of continuous measurement is that a standard workpiece is first registered for the template image. When registering and measuring the template image, it is clear what size parameters the workpiece needs to measure, including straight line distance, circle center distance, circle diameter, etc. The registered template parameters will be saved in the software database for subsequent matching measurement. Then multi-target, multi-angle template matching is performed. The essence of continuous measurement is to perform translation and rotation transformation on the target image and overlap it with the template image. To calculate the translation relationship of the image, the translation reference point of the image must be calculated. In the present invention, the center point of the target matching image is used as the translation reference point. After the above steps, the translation and rotation transformation parameters required for matching the target image with the template image can be calculated. The rotation transformation formula can be used to calculate the size coordinates of the target image relative to the template image to achieve continuous measurement. Continuous measurement technology can help enterprises improve production efficiency and product quality, reduce measurement errors and production losses, thereby improving competitiveness and market share. Continuous measurement technology is an important part of the intelligent and digital transformation of manufacturing. It can realize real-time monitoring and control of the production process and promote the development of manufacturing towards intelligence, flexibility and customization. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0030] Figure 1 It is the template image of the present invention.
[0031] Figure 2 It is the target image of the present invention.
[0032] Figure 3 It is the established measurement template of the present invention.
[0033] Figure 4 It is the multi-objective matching result of the present invention.
[0034] Figure 5 It is the IOU structure diagram of the present invention.
[0035] Figure 6 It is the image multi-target and multi-angle matching result of the present invention.
[0036] Figure 7 It is the measurement result of the present invention.
[0037] Figure 8It is a flow chart of the steps of the template matching-based multi-target, multi-angle continuous measurement algorithm of the present invention. DETAILED DESCRIPTION
[0038] Embodiments of the present invention are described in detail below. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, but should not be construed as limiting the present invention.
[0039] The first embodiment of the present application is:
[0040] See also Figures 1 to 8 ,in, Figure 1 It is the template image of the present invention. Figure 2 It is the target image of the present invention. Figure 3 It is the established measurement template of the present invention. Figure 4 It is the multi-objective matching result of the present invention. Figure 5 It is the IOU structure diagram of the present invention. Figure 6 It is the image multi-target and multi-angle matching result of the present invention. Figure 7 It is the measurement result of the present invention. Figure 8 The present invention provides a multi-target, multi-angle continuous measurement algorithm based on template matching, comprising the following steps:
[0041] S101: Establishing a reference measurement template;
[0042] Specifically, Figure 1 Take the workpiece to be measured as an example and register the measurement template. Figure 3 As shown, points pt1 and pt2 are connected into a straight line l1, points pt3 and pt4 are connected into a straight line l2, and the center of circle c is ptc and the radius is r. Now it is necessary to establish a template to measure the straight line distance d between l1 and l2, and the radius r of circle c. The established measurement template data is saved in the database for subsequent continuous measurement matching.
[0043] S102: Overlaying the reference measurement template image on the target image to perform multi-target and multi-angle template matching;
[0044] Specifically, template matching is to cover the known template image on the image to be searched, and calculate the similarity between the template and the partial area covered by the template. The partial area covered by the template is called a sub-image or template. Figure 1 is the template image T, Figure 2 The target image is I. The template image T is moved pixel by pixel in the target image I for matching, and the similarity between the template image and the image to be matched is calculated based on certain similarity criteria and related discriminant functions.
[0045] The present invention uses the standard correlation matching function R(x, y) as the basis for determination, where R(x, y)=1 represents a complete match, and the closer it is to 1, the higher the degree of matching.
[0046]
[0047] According to the cv::matchTemplate interface provided by OpenCV, this interface can be used for single target matching. If there is a difference in the rotation angle between the target image and the template image, the accuracy will be very poor when using cv::match Template for template matching, and even cause mismatching. Therefore, a multi-angle template matching must be performed based on the original algorithm. There are two implementation methods for multi-angle template matching. 1. When matching, rotate the template image 360° with a step size of 1°, and then match it with the target image. 2. When matching, rotate the target image 360° with a step size of 1°, and then match it with the template image.
[0048] After completing multi-angle matching, in order to achieve workpiece matching measurement and improve measurement efficiency, we also need to perform multi-target matching. When using cv::matchTemplate for single-target matching, we often use the position with the highest score as the matching result. When performing multi-target matching, we only need to set a threshold Th. If the score is greater than the threshold Th, we can save all the matching results as candidate matching results. Some of these candidate matching areas are multiple matching results for the same target, such as Figure 4 As shown in the figure, b1 is the best matching area. At this time, we need to filter out the overlapping areas (b2, b3) and only keep b1. The NMS (Non-maximum-suppresion) non-maximum suppression algorithm is used in it.
[0049] IOU (intersection over union) is the ratio of the intersection of two box areas to their union, such as Figure 5 As shown, it is used to determine the pixel distance between the positions of two boxes.
[0050] NMS algorithm steps:
[0051] 1. Select the box with the largest score, recorded as bbest.
[0052] 2. Calculate the IOU between bbest and the remaining boxes.
[0053] 3. If its IOU>nms_th (usually set to 0.5), then discard this box.
[0054] 4. Repeat the above steps to complete the NMS operation.
[0055] In this way, multi-target and multi-angle matching of images is completed, and the results are as follows: Figure 6 shown.
[0056] S103: Calculate the translation reference point;
[0057] Specifically, the essence of continuous measurement is to perform translation and rotation transformation on the target image and to match it with the template image. To calculate the translation relationship of the image, we have to calculate the translation reference point of the image. In the present invention, the center point of the target matching image is used as the translation reference point.
[0058] S104: Measure the size pairing to obtain the reference template measurement size corresponding to the target.
[0059] Specifically, the multi-target, multi-angle template matching algorithm performed in step S102 can calculate the angle θ (θ1, θ2, θ3...) of each target workpiece matching the template workpiece and the matching center position pCenter (pCenter1, pCenter2, pCenter3...). The measurement dimensions of the reference template corresponding to all targets can be calculated by formula (1), where formula (1) is: In a plane, the coordinate position (x1, y1) of a point (x, y) after rotating counterclockwise around an arbitrary point p (dx, dy) by an angle θ is:
[0060] x1=dx+(x-dx)·cos(θ)-(y-dy)·sin(θ)
[0061] y1=dy+(x-dx)·sin(θ)+(y-dy)·cos(θ)(1)
[0062] Take the calculation point pt1 as an example. Point pt1 is a point in the template image, and point pt1' is a point in the matching target. Then:
[0063] pt1'.x=pCenter.x+(pt1.x-pCenter.x)·cos(θ)-(pt1.y-pCenter.y)·sin(θ)
[0064] pt1'.y=pCenter.y+(pt1.x-pCenter.x)·sin(θ)+(pt1.y-pCenter.y)·cos(θ)(3)
[0065] The measurement results are as follows Figure 7 shown.
[0066] Continuous measurement technology can help companies improve production efficiency and product quality, reduce measurement errors and production losses, and thus increase competitiveness and market share.
[0067] Continuous measurement technology is an important part of the intelligent and digital transformation of manufacturing. It can realize real-time monitoring and control of the production process and promote the development of manufacturing towards intelligence, flexibility and customization.
[0068] What is disclosed above is only one or more preferred embodiments of the present application, and cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments and equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A multi-target, multi-angle continuous measurement algorithm based on template matching, characterized in that: The following steps are involved: Establishing a benchmark measurement template; Overlay the reference measurement template image on the target image to perform multi-target and multi-angle template matching; Calculate the translation reference point; The measured dimensions are matched to obtain the measured dimensions of the reference template corresponding to the target.
2. The multi-target, multi-angle continuous measurement algorithm based on template matching as claimed in claim 1, characterized in that: Establishing a reference measurement template, the steps further include: A standard workpiece is used for template image registration. When registering and measuring the template image, the size parameters of the workpiece that need to be measured are clarified. The registered template parameters are saved in the software database for subsequent matching measurements.
3. The multi-target, multi-angle continuous measurement algorithm based on template matching as claimed in claim 2, characterized in that: Overlaying the reference measurement template image on the target image to perform multi-target and multi-angle template matching, the steps further include: When performing multi-angle template matching, the template image is rotated 360° with a step size of 1° and then matched with the target image.
4. The multi-target, multi-angle continuous measurement algorithm based on template matching as claimed in claim 2, characterized in that: Overlaying the reference measurement template image on the target image to perform multi-target and multi-angle template matching, the steps further include: When performing multi-angle template matching, the target image is rotated 360° with a step size of 1° and then matched with the template image.
5. The multi-target, multi-angle continuous measurement algorithm based on template matching as claimed in claim 2, characterized in that: Overlaying the reference measurement template image on the target image to perform multi-target and multi-angle template matching, the steps further include: When performing multi-target matching, a threshold is set. If the score value is greater than the threshold, all the matched results are saved as candidate matching results; When the candidate matching area is the same target and multiple matching results are obtained, the non-maximum suppression algorithm is used to filter out the overlapping areas and only retain the best matching area.
6. The multi-target, multi-angle continuous measurement algorithm based on template matching as claimed in claim 5, characterized in that: Calculate the translation reference point, the step also includes The center point of the target image is used as the translation reference point.
7. The template matching-based multi-target, multi-angle continuous measurement algorithm according to claim 6, characterized in that: The measurement size is matched to obtain the reference template measurement size corresponding to the target, and the step further includes: The translation and rotation transformation parameters required for matching the target image with the template image are calculated, and the size coordinates of the target image relative to the template image that need to be measured are obtained using the rotation transformation formula.
8. The template matching-based multi-target, multi-angle continuous measurement algorithm as claimed in claim 7, characterized in that: The rotation transformation formula is: The coordinate position of a point (x, y) after rotating counterclockwise by angle θ around an arbitrary point p (dx, dy) is (x1, y1): x1=dx+(x-dx)·cos(θ)-(y-dy)·sin(θ) y1=dy+(x-dx)·sin(θ)+(y-dy)·cos(θ).
Citation Information
Patent Citations
Pneumatic control valve angular displacement online measurement method based on low-difference sampling image template matching
CN113505819A
Polygonal target segmentation method based on Hough transform and template matching
CN113989308A
Rapid multi-target multi-angle template matching method
CN114842212A
Image matching method and device and computer equipment
CN115115857A
Workpiece identifying and counting method based on target detection and template matching in complex scene
CN115830359A
Cited By
Matching measurement method and image measurement equipment
CN121383857A
A matching measurement method and an image measurement device
CN121383857B
