Label defect detection method based on template comparison
Technical Field
The invention relates to the field of label detection, in particular to a label defect detection method based on template comparison.
Background
In industrial detection, the detection requirements for labels are increasing day by day, and the label detection generally encounters the problems of complex background, more textures, more characters and the like, so that great challenges are brought to defect identification; the invention uses a template comparison mode to detect products from different degrees, and has the advantages of greatly inhibiting false detection caused by complex textures and flexibly customizing the defect detection size.
The traditional defect detection mode is generally to filter the information belonging to the label by analyzing the characteristics of the defect and then filtering the information in a filtering mode so as to highlight the defect; however, the method has a good effect on products with simple contents and uncomplicated backgrounds, and is easy to cause false detection on labels with a large amount of contents.
Disclosure of Invention
The invention aims to provide a label defect detection method based on template comparison, which has strong adaptability and simple operation.
The purpose of the invention is realized as follows: a label defect detection method based on template comparison comprises the following steps:
the method comprises the following steps: selecting a template image;
step two: making a template, generating a plurality of template characteristic images, and making a standard model of an object or a region to be detected;
step three: carrying out picture calibration on a sample to be detected;
step four: acquiring a template characteristic image, and comparing the template characteristic image with the sample characteristic image;
step five: and (4) testing the characteristic images of the multiple samples to be detected, judging whether the accuracy rate reaches the standard, and directly jumping to the step one to manufacture the template again if the accuracy rate does not reach the standard.
Preferably, the method for manufacturing the template in the second step is as follows:
step A: selecting a to-be-detected object without defects to take a picture, and selecting an area to be detected in the picture or the whole object to perform template manufacturing according to needs;
and B: the two filtered images are obtained by filtering the regions through low-pass filtering and high-pass filtering, the low-pass filtering is used for removing the defects of the regions with higher change frequency in the background and larger detection area, and the high-pass filtering is used for detecting the regions with more obvious change and smaller area.
And C: and (3) performing binarization processing on the two obtained filtered images, and performing binarization on the same region for multiple times according to a lighting condition, wherein if 85, 150 and 200 are set as threshold values in a region brightness range of 0-255, 6 template characteristic images can be generated.
Preferably, the low-pass filtering and the high-pass filtering adopt a low-pass filter based on a Gaussian operator and a high-pass filtering based on a Krisch operator.
Preferably, the method of the third step is as follows:
selecting a plurality of angular points with obvious characteristics on the template characteristic image, finding out corresponding angular points on a sample to be detected, carrying out affine and perspective transformation on the sample to be detected, and aligning the sample to be detected with the template.
Preferably, the method of the fourth step is as follows:
and (3) generating 6 sample characteristic images of the sample to be detected by the method of the second step, comparing the 6 sample characteristic images with the 6 template characteristic images generated by the second step, and restricting the precision of the defect by setting a gray difference threshold, a defect width threshold, a defect area threshold and the like because the sample characteristic images are not completely the same as the template characteristic images.
Preferably, the line scan camera is used to acquire the template feature image.
Compared with the prior art, the invention has the advantages that:
the invention mainly aims at detecting standard plane products with complex contents, has strong adaptability to the contents of the products, can be used by only creating different templates for different products, and is simple and convenient to operate.
A4096-point line scan camera is selected in the aspect of hardware, so that the illumination uniformity of images is guaranteed, the algorithm complexity is reduced greatly compared with that of a conventional algorithm, the operation speed is guaranteed, and the method is very suitable for scenes with high real-time requirements.
Drawings
FIG. 1 is a schematic flow chart of the present invention.
Detailed Description
As shown in fig. 1, a method for detecting a defect of a tag based on template comparison includes the following steps:
the method comprises the following steps: selecting a template image;
step two: making a template, generating a plurality of template characteristic images, and making a standard model of an object or a region to be detected;
step three: carrying out picture calibration on a sample to be detected;
step four: acquiring a template characteristic image, and comparing the template characteristic image with the sample characteristic image;
step five: and (4) testing the characteristic images of the multiple samples to be detected, judging whether the accuracy rate reaches the standard, and directly jumping to the step one to manufacture the template again if the accuracy rate does not reach the standard.
The method for manufacturing the template in the second step comprises the following steps:
step A: selecting a to-be-detected object without defects to take a picture, and selecting an area to be detected in the picture or the whole object to perform template manufacturing according to needs;
and B: the two filtered images are obtained by filtering the regions through low-pass filtering and high-pass filtering, the low-pass filtering is used for removing the defects of the regions with higher change frequency in the background and larger detection area, and the high-pass filtering is used for detecting the regions with more obvious change and smaller area.
And C: and (3) performing binarization processing on the two obtained filtered images, and performing binarization on the same region for multiple times according to a lighting condition, wherein if 85, 150 and 200 are set as threshold values in a region brightness range of 0-255, 6 template characteristic images can be generated.
The low-pass filtering and the high-pass filtering adopt a low-pass filter based on a Gaussian operator and a high-pass filtering based on a Krisch operator.
The method of the third step is as follows:
selecting a plurality of angular points with obvious characteristics on the template characteristic image, finding out corresponding angular points on a sample to be detected, carrying out affine and perspective transformation on the sample to be detected, and aligning the sample to be detected with the template.
The method of the fourth step is as follows:
and (3) generating 6 sample characteristic images of the sample to be detected by the method of the second step, comparing the 6 sample characteristic images with the 6 template characteristic images generated by the second step, and restricting the precision of the defect by setting a gray difference threshold, a defect width threshold, a defect area threshold and the like because the sample characteristic images are not completely the same as the template characteristic images.
The present invention is not limited to the above-mentioned embodiments, and based on the technical solutions disclosed in the present invention, those skilled in the art can make some substitutions and modifications to some technical features without creative efforts according to the disclosed technical contents, and these substitutions and modifications are all within the protection scope of the present invention.