A target orientation detection method based on YOLO and template matching

By combining the YOLO neural network and the template matching algorithm, the image pyramid is used to calculate the pixel average, which solves the accuracy and performance problems of the traditional target orientation detection method, and achieves efficient and fast detection of complex feature objects and accurate orientation determination.

CN118470360BActive Publication Date: 2024-09-24YALONG INTELLIGENT EQUIP GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410937276.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-12
Publication Date
2024-09-24
Estimated Expiration
2044-07-12

AI Technical Summary

Technical Problem

Traditional target orientation detection methods are ineffective when dealing with objects that lack obvious features or complex features. Template matching methods are easily affected by ambient light and are time-consuming. Object orientation detection methods based on AI algorithms are time-consuming and have unsatisfactory accuracy.

Method used

Combined with the YOLO neural network and template matching algorithm, the pixel average is calculated by generating an image pyramid, the global YOLO detection framework is used to quickly locate the target object position, and then the local template matching algorithm is used to accurately detect the orientation of the target object, and parallel computing is used to improve the detection speed. .

Benefits of technology

It achieves efficient and rapid detection of objects with complex features, accurately determines the position and orientation of target objects, and solves the accuracy and performance problems of traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118470360B
    Figure CN118470360B
Patent Text Reader

Abstract

The present application discloses a target orientation detection method based on YOLO and template matching, which relates to the field of target detection technology, including: using the YOLO neural network detection framework to roughly locate the target object in the input plane image, determine the category of the target object and the position and size of the preliminary detection frame, then intercept the image in the obtained detection frame, gray it, use it as the matching source image for fast template matching, start from the top layer of the template image pyramid to rotate the template image with a preliminary angle step, then perform template matching with the corresponding layer of the matching source image pyramid, determine the best angle, and then rotate and match the template of the next layer of the template image pyramid with a finer angle until the expected angle accuracy is obtained. The method of the present invention effectively shortens the time required for target orientation detection by using the image pyramid to detect rough angles on a small scale and accurately match and detect a small angle range on a large scale.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of target detection, and in particular to a target orientation detection method based on YOLO and template matching. Background Art

[0002] At present, in industrial applications, visual detection, positioning, and orientation determination of objects on a plane are usually carried out by extracting specific features (such as a single color, a circular hole, a rectangular frame, etc.). This is not very complicated to implement for simple object detection, but if the object to be detected lacks obvious features or has complex features, the traditional feature extraction detection method cannot be effectively applied. The template matching method can accurately detect target objects with complex features or no obvious features, but it is easily affected by ambient light, and considering that the target objects have different orientations, it is extremely time-consuming to perform template matching of multiple categories of target objects in the entire image. The AI ​​detection method based on deep neural networks can solve the problem of complex object recognition and positioning, but the current object orientation detection method based on AI algorithms has the problem of being time-consuming or having unsatisfactory detection accuracy. Summary of the invention

[0003] In view of this, the present application provides a target direction detection method based on YOLO and template matching, which solves the technical problems that the traditional target direction detection method has poor detection effect on objects to be detected that lack obvious features or have complex features, the template matching method is easily affected by ambient light and is relatively time-consuming, and the current object direction detection method based on AI algorithm is relatively time-consuming or has unsatisfactory detection accuracy.

[0004] To achieve the above object, the present invention provides the following technical solutions:

[0005] A target orientation detection method based on YOLO and template matching includes the following steps:

[0006] Obtaining original image information of the target object to be detected;

[0007] Construct a training sample set, train a target detector based on the YOLO neural network based on the training sample set, and specify one or more labeled samples as templates;

[0008] The original image information of the target object to be detected is input into the trained target detector to obtain the classification label and rough position information of the target object to be detected, and the detected target object area is extracted from the original image as the matching source of the template matching method;

[0009] Generate an image pyramid based on the matching source and the template, and calculate the pixel average of each image in the image pyramid;

[0010] Starting from the top layer of the image pyramid, template matching is performed at an initial angle, and then the lower layer image is used to perform template matching at another angle, and this process is repeated until the target's precise position angle information that meets the requirements is obtained.

[0011] Furthermore, constructing a training sample set includes:

[0012] Label the target objects in the training image and generate a label data file in YOLO format. The label data of the target object includes the position, width, height, and rotation angle of the target object in the image.

[0013] If the label data of the target object contains rotation angle information, the angle information of the target object is counted. If the difference between adjacent angles is greater than the preset threshold, it means that there is an angle missing. The sample image needs to be rotated to supplement the missing angle so that the sample of the target object covers 360 degrees and the difference between adjacent angles is less than the preset threshold.

[0014] If the label data of the target object does not contain rotation angle information, the image containing the target object is uniformly rotated in a series of steps with a preset threshold;

[0015] Perform data augmentation on the training data. If the sample images collected are small, perform one-step sample augmentation on the images. The augmentation methods include geometric transformation (scaling, cropping, translation, etc.), color transformation (image sharpness, brightness saturation, and contrast, etc.), image stitching, etc.

[0016] The detection image dataset (images and corresponding label files) is divided into a training set and a validation set, and the Yolo framework is input to train the model until the verification accuracy and recall reach the specified values, which means that the object detector training is completed.

[0017] Furthermore, an image pyramid is generated based on the matching source and the template, and the pixel average value of each image in the image pyramid is calculated, including:

[0018] Select an image in a zero-angle target object constraint rectangle from the dataset image as a template. If there is no zero-angle target object, it can be obtained by rotation. Calculate the average pixel value of the image for matching value calculation;

[0019] Use the trained target detector to detect the new input image, detect the target object, and obtain the corresponding constrained rectangular box, which describes the category, position and size of the detected target object, but cannot determine the orientation information of the target object;

[0020] Extract the rectangular frame of the detected target object as the matching source image, and calculate the pixel average value of the matching source image;

[0021] An image pyramid is established to match the source image and the template image. The image pyramid adopts downsampling mode with a sampling factor of 2. The image of the previous layer is half the size of the image of the next layer. The Gaussian convolution kernel is used to calculate the pixel value of the reduced image. The convolution kernel is:

[0022] ,

[0023] When the width or height of the template image is not greater than the preset pixel value, the number of layers of the current image pyramid is determined, and the image pyramid with the corresponding number of images is generated by matching the source image.

[0024] Further, starting from the top layer of the image pyramid, performing template matching at an initial angle, and then using the lower layer image to perform template matching at another angle includes:

[0025] Take the top layer of the template pyramid, align it with the center of the image as the origin, give a preliminary angle step and perform several groups of rotation tests within a 360-degree range. When the size of the rotated template exceeds the corresponding matching source image, the angle is considered invalid, and a rotation angle sequence is obtained.

[0026] The template image is rotated according to the rotation angle sequence to obtain a rotation template sequence;

[0027] The matching source image and the rotation template sequence are respectively matched with each other, and the matching value calculation formula used is:

[0028] ,

[0029] in, To rotate the template at the coordinate position The pixel value on is the pixel mean of the original template before rotation, To match the offset coordinates on the source image Starting coordinates The pixel value of is the pixel mean of the matching source image;

[0030] Furthermore, the step of performing template matching at an initial angle starting from the top layer of the image pyramid and then performing template matching at another angle using the lower layer image also includes: determining, based on the matching result, the angle corresponding to the maximum value as the orientation angle of the target object at the current step angle accuracy, taking a certain range with the orientation angle as the center, using a new angle step, taking the template image pyramid and the next layer of scale image of the matching source image pyramid, rotating the scale template according to the new range and step angle, and performing the template matching operation again.

[0031] The present invention uses the global YOLO detection framework to quickly detect the position of the target object, and then uses the local template matching algorithm to accurately detect the precise position and orientation of the target object. An effective way to reduce the amount of calculation of the present invention is to calculate the pixel average of the original template in advance to replace the pixel average of each rotated template itself to calculate the matching value, which is based on the average value of the rotated template and the average value of the original template. In addition, the fourth step of the present invention can be partly calculated by GPU / CPU parallel computing. If a parallel computing method is adopted, multiple target objects can also be processed simultaneously, thereby increasing the speed of detection.

[0032] It can be seen from the above technical solution that the advantages of the present invention are:

[0033] 1. This application combines the Yolo target detection algorithm based on a deep neural network framework with the template matching algorithm to obtain an efficient and fast planar target object detection method, which can accurately detect the position and orientation of the target object.

[0034] 2. This application uses the global YOLO detection framework to quickly detect the approximate position of the target object, and uses the local template matching algorithm to accurately detect the precise position and orientation of the target object, which effectively solves the accuracy and performance problems of existing methods when simultaneously detecting the target position and orientation. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application.

[0036] Figure 1 A schematic diagram of the steps of this application.

[0037] Figure 2 This is a schematic diagram of step S4 of the present application.

[0038] Figure 3 This is a schematic diagram of step S5 of the present application. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the implementation modes and the accompanying drawings. Here, the illustrative implementation modes and descriptions of the present application are used to explain the present application, but are not intended to limit the present application.

[0040] refer to Figures 1 to 3 ,like Figure 1As shown, this embodiment provides a target orientation detection method based on YOLO and template matching, which is a high-performance target positioning and orientation detection method that combines a deep learning framework with classic template matching. Specifically, it includes:

[0041] Step S1: Acquire the original image information of the target object to be detected.

[0042] Step S2: Construct a training sample set, train a target detector based on the YOLO neural network based on the training sample set, and specify one or more labeled samples as templates.

[0043] Specifically, constructing a training sample set includes:

[0044] The target objects in the training images are labeled and a label data file in YOLO format is generated. The label data of the target objects includes the position, width, height, and rotation angle of the target objects in the image.

[0045] If the label data of the target object contains rotation angle information, the angle information of the target object is counted. If the difference between adjacent angles is greater than the preset threshold, it means that there is an angle missing. The sample image needs to be rotated to supplement the missing angle so that the sample of the target object covers 360 degrees and the difference between adjacent angles is less than the preset threshold.

[0046] If the label data of the target object does not contain rotation angle information, the image containing the target object is uniformly rotated in a series of steps with a preset threshold. A series of rotations refers to angles formed in a certain step amount within 360 degrees, such as 0, 30, 60, 90, etc.;

[0047] Perform data augmentation on the training data.

[0048] In this embodiment, when training the target detector, a large number of planar images containing the target object are collected by a fixed camera, and the size of the image can be 800*600 or 1280*720.

[0049] The target object in the image is annotated and a label data file in YOLO format is generated. Each line in the file records the rectangular frame of the target object sample in the image in the format of (category index / category name, center x coordinate, center y coordinate, width, height, rotation (optional)). If the target object label data contains rotation angle information, the angle information of the target object is counted. If the difference between adjacent angles is greater than Theta=30 degrees, it is considered that there is an angle missing, and the sample image is rotated to supplement the missing angle, so that the sample of the target object covers 360 degrees and the difference between adjacent angles is less than Theta=30 degrees. If the target object label data does not contain rotation angle information, the image containing the target object is uniformly rotated in a series of steps of Theta=30 degrees. If the sample images collected are small, the image is augmented with only one step of sample augmentation. The augmentation methods include geometric transformation (scaling, cropping and translation, etc.), color transformation (image sharpness, brightness saturation and contrast, etc.), image stitching, etc. For the image augmented by geometric transformation, the position information of its label also needs to be transformed accordingly so that the corresponding target object can still be correctly annotated in the image. The detection image dataset (images and corresponding label files) is divided into a training set and a validation set, and the model is trained by the Yolo framework until the validation accuracy and recall reach the specified value (usually 0.95), which means that the YOLO model training is complete.

[0050] Step S3: Input the original image information of the target object to be detected into the trained target detector to obtain the classification label and rough position information of the target object to be detected, and extract the detected target object area from the original image as the matching source of the template matching method.

[0051] Step S4: Generate an image pyramid based on the matching source and the template, and calculate the pixel average of each image in the image pyramid.

[0052] Generate an image pyramid based on the matching source and template, and calculate the pixel average of each image in the image pyramid including:

[0053] Step S41: Select an image in a rectangular frame of a target object with a zero angle from the image in the data set as a template. If there is no target object with a zero angle, it can be obtained by rotation. The average pixel value of the image is calculated for matching value calculation.

[0054] Step S42: Use the trained target detector to detect the new input image, detect the target object therein, and obtain the corresponding constrained rectangular box, which describes the category, position and size of the detected target object, but cannot determine the orientation information of the target object;

[0055] Step S43: extracting the rectangular frame of the detected target object as a matching source image, and calculating the pixel average value of the matching source image for matching value calculation;

[0056] Step S44: Establish an image pyramid that matches the source image and the template image. The image pyramid adopts a downsampling method with a sampling factor of 2. The image of the previous layer is half the size of the image of the next layer. A Gaussian convolution kernel is used to calculate the pixel value of the reduced image. The convolution kernel is:

[0057] ,

[0058] When the width or height of the template image is not greater than the preset pixel value, the number of layers of the current image pyramid is determined, and the image pyramid with the corresponding number of images is generated by matching the source image.

[0059] Create a pyramid of matching source image and template image, and the number of pyramids is determined so that one of the width or height of the template size is less than or equal to a given value. If the original sizes of the template and the matching source are [210,33] and [224,111] respectively, the image sizes in the template pyramid are [9,53], [105,17], [210,33] from top to bottom, and the image sizes in the matching source pyramid are [28,56], [112,56], [224,111] from top to bottom.

[0060] Step S5: Start from the top layer of the image pyramid and perform template matching at an initial angle, then use the lower layer image to perform template matching at another angle, and iterate until the target precise position angle information that meets the requirements is obtained.

[0061] Starting from the top layer of the image pyramid, template matching is performed at the initial angle, and then the lower layer image is used to perform template matching at another angle, including:

[0062] Step S51: Take the top layer of the template pyramid, align it with the center of the image as the origin, give a preliminary angle step and perform several groups of rotation tests within a range of 360 degrees. When the size of the rotated template exceeds the corresponding matching source image, the angle is determined to be invalid, and a rotation angle sequence is obtained;

[0063] Step S52: rotating the template image according to the rotation angle sequence to obtain a rotation template sequence;

[0064] Step S53: template matching is performed on the matching source image and the rotation template sequence respectively, and the matching value calculation formula used is:

[0065] ,

[0066] in, To rotate the template at the coordinate position The pixel value on is the pixel mean of the original template before rotation, To match the offset coordinates on the source image Starting coordinates The pixel value of is the pixel mean of the matching source image;

[0067] Step S54: According to the matching result, the angle corresponding to the maximum value is determined as the orientation angle of the target object at the current step angle accuracy, and a certain range is taken with the orientation angle as the center. The new angle step is used to take the next level of scale image of the template image pyramid and the matching source image pyramid, and the scale template is rotated according to the new range and step angle, and the template matching operation is performed again.

[0068] In this embodiment, when accurate detection is performed based on rotation template matching, the top layer of the template pyramid is taken, aligned with the image center as the origin, and a number of rotation tests are performed within a range of 360 degrees with a given preliminary angle step. When the size of the rotated template exceeds the corresponding matching source image, the angle is determined to be invalid, because the matching source image is generally larger than the template image in the template pyramid. The template image is rotated step by step according to a certain step amount, and when the size after rotation exceeds the corresponding matching source image, it stops, and the previous series of rotation angles are valid. This step obtains a series of rotation angles.

[0069] The template image is rotated according to the rotation angle sequence to obtain a rotation template sequence;

[0070] Take the matching source image to perform template matching with the rotation template sequence respectively, and the matching value calculation formula used is:

[0071]

[0072] in, To rotate the template at the coordinate position The pixel value on is the pixel mean of the original template before rotation, To match the offset coordinates on the source image Starting coordinates The pixel value of is the pixel mean of the matching source image;

[0073] In the matching results of each angle, the angle corresponding to the maximum value can be determined as the orientation angle of the target object at the current step angle accuracy. Take a certain range with this angle as the center, use a new finer angle step, and take the template and the next level of the matching source image pyramid. Rotate the template according to the new range and step angle, and perform template matching again.

[0074] If the angle accuracy does not meet the requirements and the bottom layer of the image pyramid has been obtained, the next angle scale matching still uses the bottom layer image of the pyramid. When the angle meets the requirements, the matching process exits and finally returns the angle and position information of the target object.

[0075] The global YOLO detection framework is used to quickly detect the position of the target object, and then the local template matching algorithm is used to accurately detect the exact position and orientation of the target object.

[0076] The invention discloses a planar target positioning and orientation detection method based on YOLO and template matching. The method first uses the YOLO neural network detection framework to roughly locate the target object in the input plane image, and determines the category of the target object and the position and size of the rough detection frame. Then the image in the obtained detection frame is intercepted and grayed as a matching source image for fast template matching. The template is formed into an image pyramid until one of the width and height of the image of the smallest size reaches below the specified pixel, and the matching source image generates a pyramid of the corresponding number of images. Starting from the top layer of the template image pyramid, the template image is rotated with a preliminary angle step, and then template matching is performed with the corresponding layer of the matching source image pyramid. After determining the optimal angle, the template of the next layer of the template image pyramid is rotated and matched at a finer angle until the optimal angle or the expected angle accuracy is obtained.

[0077] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the embodiments of the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A target orientation detection method based on YOLO and template matching, characterized in that: The steps include: Obtaining original image information of the target object to be detected; Constructing a training sample set, training a target detector based on a YOLO neural network based on the training sample set, and specifying one or more labeled samples as templates; Input the original image information of the target object to be detected into the trained target detector to obtain the classification label and rough position information of the target object to be detected, and extract the detected target object area from the original image as the matching source for template matching; Generate an image pyramid based on the matching source and the template, and calculate the pixel average of each image in the image pyramid; Start from the top layer of the image pyramid and perform template matching at the initial angle, then use the lower layer image to perform template matching at another angle, and repeat this process until the target's precise position angle information that meets the requirements is obtained; The step of performing template matching from the top layer of the image pyramid at an initial angle and then performing template matching from another angle using the lower layer image includes: Take the top layer of the template pyramid, align it with the center of the image as the origin, give a preliminary angle step and perform several groups of rotation tests within a 360-degree range. When the size of the rotated template exceeds the corresponding matching source image, the angle is considered invalid, and a rotation angle sequence is obtained. The template image is rotated according to the rotation angle sequence to obtain a rotation template sequence; The matching source image and the rotation template sequence are respectively matched with each other, and the matching value calculation formula used is: , in, To rotate the template at the coordinate position The pixel value on is the pixel mean of the original template before rotation, To match the offset coordinates on the source image Starting coordinates The pixel value of is the pixel mean of the matching source image; The step of performing template matching at an initial angle starting from the top layer of the image pyramid and then performing template matching at another angle using the lower layer image further includes: determining, according to the matching result, an angle corresponding to a maximum value as the orientation angle of the target object at the current step angle accuracy, taking a certain range with the orientation angle as the center, using a new angle step, taking an image of the next level scale of the template image pyramid and the matching source image pyramid, rotating the scale template according to the new range and step angle, and performing the template matching operation again.

2. The target orientation detection method based on YOLO and template matching according to claim 1, characterized in that: The constructing of the training sample set comprises: Label the target objects in the training image and generate a label data file in YOLO format. The label data of the target object includes the position, width and height of the target object in the image, as well as the rotation angle of the target object; If the label data of the target object contains rotation angle information, the angle information of the target object is counted. If the difference between adjacent angles is greater than the preset threshold, it means that there is an angle missing. The sample image needs to be rotated to supplement the missing angle so that the sample of the target object covers 360 degrees and the difference between adjacent angles is less than the preset threshold. If the label data of the target object does not contain rotation angle information, the image containing the target object is uniformly rotated in a series of steps with a preset threshold; Perform data augmentation on the training data.

3. The target orientation detection method based on YOLO and template matching according to claim 1, characterized in that: The step of generating an image pyramid based on the matching source and the template and calculating the pixel average of each image in the image pyramid comprises: Select an image in a zero-angle target object constraint rectangle from the dataset image as a template. If there is no zero-angle target object, it can be obtained by rotation. Calculate the average pixel value of the image for matching value calculation; Use the trained target detector to detect the new input image, detect the target object in it, and obtain the corresponding constrained rectangular frame; Extracting a rectangular frame of the detected target object as a matching source image, and calculating a pixel average value of the matching source image; An image pyramid is established to match the source image and the template image. The image pyramid adopts a downsampling method with a sampling factor of 2. The image of the previous layer is half the size of the image of the next layer. A Gaussian convolution kernel is used to calculate the pixel value of the reduced image. The convolution kernel is: , When the width or height of the template image is not greater than the preset pixel value, the number of layers of the current image pyramid is determined, and the image pyramid with the corresponding number of images is generated by matching the source image.