Image detection methods, apparatus, equipment and storage media
By performing coordinate alignment processing and feature point screening on printed images and template images, the calculation amount is reduced, the problem of inefficient detection in the prior art is solved, and fast and accurate detection on high-speed production lines is achieved.
Patent Information
- Application Number
- CN202410061711.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-15
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-01-15
AI Technical Summary
The prior art has huge calculation amount when printing images on the detection production line, resulting in low detection efficiency, especially in a high-speed transmission environment, which is difficult to detect the qualification of printed images in real time.
By performing coordinate alignment of the printed image and template image, print feature points and template feature points are extracted, and feature points with the same coordinates are filtered out through coordinate matching. Only the selected feature points combinations are calculated to reduce unnecessary The matching calculation.
It effectively reduces the calculation amount and improves the detection efficiency, so that the qualification of printed images can be quickly and accurately detected on high-speed production lines.
Smart Images

Figure CN117893502B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of printer technology, and in particular to an image detection method, device, equipment and storage medium. Background Art
[0002] There are many different patterns including text, numbers or QR codes on different products or packages. By identifying the patterns, relevant information of the products can be quickly found. In practical applications, when the products are transmitted on the production line, the printer is used to print on the product packaging in transmission to form the above-mentioned different printed images. When the printed image is formed on the production line, it is necessary to quickly identify the printed image to detect whether the printed image is qualified. However, the printer may usually print on the packaging surface of different sizes and proportions, and due to the influence of lighting conditions and environmental noise and the high-speed transmission on the production line, the brightness, contrast and clarity of the printed image will change, which makes it difficult to detect the printed image.
[0003] In the prior art, SIFT (Scale Invariant Feature Transform) is usually used to realize the recognition and detection of the printed images formed on the production line. However, when using SIFT to detect the image, it is necessary to calculate the similarity between each feature point in the printed image and all feature points in the template image, resulting in a huge amount of calculation. Figure 1 As shown in the figure, there are many feature points. The existing detection method will calculate all pixels that are not in the same coordinates, and will perform matching calculations for pixels in different coordinates, which will significantly increase the complexity and amount of calculation. On the production line, image detection usually needs to be performed in real time or at high speed, and the detection of printed images needs to be completed in a very short time to determine unqualified printed images. Therefore, the above-mentioned image detection method has a huge amount of calculation, resulting in low efficiency in detecting printed images on the production line. Summary of the invention
[0004] Based on this, the object of the present invention is to provide an image detection method, device, equipment and storage medium that can reduce the amount of calculation and improve detection efficiency.
[0005] In a first aspect, the present invention provides an image detection method, comprising:
[0006] S1: extracting printing feature points after performing coordinate alignment processing on the printed image; and extracting template feature points after performing coordinate alignment processing on the template image;
[0007] S2: performing coordinate matching on the printing feature points and the template feature points, and selecting printing feature points and template feature points with the same coordinates as feature point combinations;
[0008] S3: Calculate the similarity between the printing feature points and the template feature points in each feature point combination;
[0009] S4: taking a feature point combination whose similarity is greater than a first threshold as a matching feature point combination;
[0010] S5: Determine whether the number of matching feature point combinations is greater than a second threshold; if so, determine that the printed image is qualified; if not, determine that the printed image is unqualified.
[0011] Furthermore, step S1 specifically includes:
[0012] S1_1: performing grayscale processing and binarization processing on the printed image in sequence to obtain a processed binary printed image;
[0013] S1_2: performing filtering processing on the binary printed image to obtain a processed first filtered image;
[0014] S1_3: performing morphological dilation on the processed first filtered image to obtain a target printing area of the first filtered image, and obtaining an optimized first printing image by intercepting the first filtered image based on the target printing area;
[0015] S1_4: Binarize the template image to obtain a processed first template image;
[0016] S1_5: performing alignment processing on the first printing image and the first template image to obtain an optimized printing image and an optimized template image;
[0017] S1_6: Extracting the printing feature points from the optimized printing image, and extracting the template feature points from the optimized template image.
[0018] Furthermore, in step S16, the printing feature points are extracted from the optimized printing image according to a preset extraction algorithm, and the template feature points are extracted from the optimized template image according to a preset extraction algorithm.
[0019] Furthermore, the preset extraction algorithm includes SIFT.
[0020] Furthermore, in step S3, the similarity calculation formula is:
[0021]
[0022] Among them, cosθ is the similarity, A is the feature vector corresponding to the printed feature point, and B is the feature vector corresponding to the template feature point.
[0023] Furthermore, the first threshold is 0.8.
[0024] Furthermore, the second threshold is 30.
[0025] In a second aspect, the present invention further provides an image detection device, comprising:
[0026] An extraction module, used to extract printing feature points after performing coordinate alignment processing on the printed image; and to extract template feature points after performing coordinate alignment processing on the template image;
[0027] A first matching module is used to match the coordinates of the printing feature points and the template feature points, and select the printing feature points and template feature points with the same coordinates as feature point combinations;
[0028] A calculation module, used for calculating the similarity between the printing feature points and the template feature points in each feature point combination;
[0029] A second matching module uses a feature point combination whose similarity is greater than a first threshold as a matching feature point combination;
[0030] The determination module is used to determine whether the number of matching feature point combinations is greater than a second threshold; if so, the printed image is determined to be qualified; if not, the printed image is determined to be unqualified.
[0031] In a third aspect, the present invention further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and wherein the processor is used to implement any of the above-mentioned image detection methods when executing the computer program.
[0032] In a fourth aspect, the present invention further provides a computer storage medium, characterized in that it includes a computer program, characterized in that when the computer program is executed by a processor, it implements any of the above-mentioned image detection methods.
[0033] Compared with the prior art, the image detection method provided by the present invention first performs coordinate alignment processing on the printed image and the standard image when detecting the printed image, and after extracting corresponding feature points in the obtained optimized printed image and optimized template image using a preset recognition algorithm, further screens out feature point combinations with the same coordinates through coordinate matching. Only the similarity calculation needs to be performed on the feature point combinations with matched coordinates, reducing unnecessary matching calculations, thereby effectively improving the calculation speed and further improving the detection efficiency of the printed image.
[0034] In order to understand the present invention more clearly, the specific implementation of the present invention will be described below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of the matching effect during image detection in the prior art;
[0036] Figure 2 A schematic diagram of the overall process of the image detection method provided by the present invention;
[0037] Figure 3 It is a schematic diagram of an image after grayscale conversion of a printed image in the present invention;
[0038] Figure 4 This is a schematic diagram of an image after filtering a grayscale image according to the present invention;
[0039] Figure 5 This is a schematic diagram of an image after secondary denoising of a filtered image according to the present invention;
[0040] Figure 6 This is a schematic diagram of an image obtained after optimization processing of the present invention;
[0041] Figure 7 A schematic diagram of a standard printing image and a standard template image obtained after alignment processing of the present invention;
[0042] Figure 8 A schematic diagram of coordinate matching of printing feature points and template feature points in the present invention;
[0043] Fig. 9 is a probability distribution diagram of the detection accuracy of the printed image according to the present invention;
[0044] Fig.10 A schematic diagram of the matching effect of the image detection method provided by the present invention. DETAILED DESCRIPTION
[0045] In order to improve the detection efficiency of printed images, the present invention first performs coordinate alignment processing on the printed image and the template image when detecting the printed image, and respectively extracts printing feature points and template feature points from the optimized printed image and the optimized template image after the coordinate alignment processing by using a preset recognition algorithm, and then screens out feature point combinations with the same coordinates through coordinate matching. It is only necessary to perform similarity calculation on the printing feature points and the template feature points in the screened feature point combinations with the same coordinates, instead of the existing method of calculating the similarity between each feature point descriptor in the first image and all feature point descriptors in the second image, thereby achieving the improvement of the detection efficiency of the printed image under the premise of greatly reducing the amount of calculation.
[0046] Please refer to Figure 2The present invention provides an image detection method. When a printer prints on a product or package on a production line to form a printed image, a processor uses the image detection method provided by the present application to detect the printed image. It can quickly detect whether the printed image is qualified while reducing the amount of calculation, thereby improving the detection efficiency of the printed image.
[0047] Specifically, in this embodiment, the processor performs image detection through the following steps:
[0048] S1: extracting printing feature points after performing coordinate alignment processing on the printed image; and extracting template feature points after performing coordinate processing on the template image.
[0049] Specifically, after the product is produced, it is transmitted through the production line. After the printer detects the product packaging, it starts to print on the product packaging to obtain the printed image. The industrial camera obtains the printed image from the product packaging and simultaneously obtains the pre-stored template image. Preferably, the printer can be a jet printer or a code printer, and the printed image can be a code image including numbers, letters or a QR code. The industrial camera can read the printed image through opencv.
[0050] After obtaining the print image and the template image, firstly, coordinate alignment processing is performed on the obtained print image and the template image, and corresponding feature points are extracted from the optimized print image and the optimized template image after the coordinate alignment processing. Therefore, this step is in the preprocessing process of the print image and the template image, and the print feature points are extracted based on the optimized print image obtained after the preprocessing, and the template feature points are extracted based on the obtained optimized template image. Specifically, the following steps S1_1 to S1_5 are included:
[0051] S1_1: performing grayscale processing and binarization processing on the printed image in sequence to obtain a processed binary printed image;
[0052] After reading the printed image, the processor can use a conventional grayscale image conversion function to perform grayscale processing on the printed image and convert it into a grayscale image. Figure 3 As shown; the obtained grayscale image is further binarized using a binarization function to obtain a binary printed image.
[0053] S1_2: performing filtering processing on the binary printed image to obtain a processed first filtered image;
[0054] Specifically, in the binary printed image obtained by sequentially performing grayscale processing and binarization processing on the printed image, there may be noise caused by product packaging or printing paper, as shown in FIG. Figure 4Therefore, after obtaining the binary printed image, the binary printed image is further filtered and denoised to obtain a processed first filtered image, as shown in FIG. Figure 5 Optionally, a Gaussian kernel function is used to perform Gaussian filtering on the binary printed image.
[0055] S1_3: performing morphological dilation on the processed first filtered image to obtain a target printing area of the first filtered image, and obtaining an optimized first printing image by intercepting the first filtered image based on the target printing area;
[0056] Specifically, when filtering and denoising the binary image, most of the noise can be eliminated in general. However, there may be some noise areas with particularly large noise that cannot be eliminated after a single preliminary filtering. Therefore, when the processed first filtered image is obtained, the first filtered image is further subjected to secondary filtering, and morphological dilation is performed using a Gaussian kernel to remove all noise in the non-printing area, find the outline of the target printing image in the first filtered image, and draw a rectangular frame outside the outline to identify the target printing area of the first filtered image, and further obtain the optimized first printing image based on the target printing area from the first filtered image, as shown in the following example. Figure 6 shown.
[0057] S1_4: Binarize the template image to obtain a processed first template image;
[0058] Specifically, the template image is an image pre-stored in the processor for detecting the printed image. It can be understood that the template image only records the key point information of the image, so the template image is much smaller than the printed image. After the template image is acquired, the template image is binarized to obtain a binary template image after black and white processing as the first template image for comparison.
[0059] S1_5: performing alignment processing on the first printing image and the first template image to obtain an optimized printing image and an optimized template image;
[0060] Specifically, since the first print image and the first template image have different sizes, after obtaining the first print image and the first template image, the first print image and the first template image are further aligned so that the optimized print image and the optimized template image obtained after the processing have the same size and aligned coordinates. The optimized print image and the optimized template image obtained can be found in Figure 7 shown.
[0061] S1_6: Extracting the printing feature points from the optimized printing image, and extracting the template feature points from the optimized template image.
[0062] In this step S1, before acquiring the print image and the template image and extracting the feature points of the print image and the template image, the print image and the template image are first pre-coordinate aligned so that the coordinates of the obtained optimized print image and the optimized template image are basically aligned, and the print feature points are extracted from the optimized print image after the coordinate alignment and the template feature points are extracted from the optimized template image. Therefore, the present application improves the matching efficiency of the feature points by correcting the coordinates of the print image and the template image to obtain print feature points and template feature points with the same coordinates.
[0063] S2: performing coordinate matching on the printing feature points and the template feature points, and selecting printing feature points and template feature points with the same coordinates as feature point combinations.
[0064] Specifically, the optimized printing image and the optimized template image after the coordinate alignment process have the same size, so after obtaining the optimized printing image and the optimized template image after the alignment process, the corresponding printing feature points and template feature points are extracted based on the optimized printing image and the optimized template image after the alignment process, wherein it can be understood that there can be multiple extracted printing feature points and there can also be multiple template feature points. In this step, the extracted multiple printing feature points and multiple template feature points are coordinate matched, and the printing feature points and template feature points with the same coordinates are screened to form corresponding multiple feature point combinations.
[0065] In one example, a plurality of printing feature points can be extracted from the standard printing image and a plurality of template feature points can be extracted from the standard template image according to a preset extraction algorithm. Specifically, the preset extraction algorithm includes a SIFT algorithm. For example, the printing feature point d1 extracted from the optimized printing image using the SIFT algorithm can be expressed as: [A, a1], and the template feature point d2 extracted from the optimized template image can be expressed as: [B, b1], where A is used to characterize the feature vector of the printing feature point, and a1 is used to characterize the coordinate of the printing feature point; B is used to characterize the feature vector of the template feature point, and b1 is used to characterize the coordinate of the template feature point. Specifically, the printing feature point and the template feature point can be represented by a 128-dimensional feature vector.
[0066] Specifically, if the coordinate a1 of the printing feature point is the same as the coordinate b1 of the template feature point, then it is determined that the coordinates of the printing feature point d1 extracted from the optimized printing image and the template feature point d2 extracted from the optimized template image match. At this time, the printing feature point d1 and the template feature point d2 with the same coordinates form a feature point combination as a pair of coordinate-matched feature points. By matching the coordinates of multiple printing feature points and template feature points, multiple feature point combinations with matched coordinates can be obtained. And it can be understood that the printing feature point d1 and the template feature point d2 included in the feature point combination obtained at this time are only coordinate matched, which does not mean that the printing feature point d1 and the template feature point d2 match. Refer to Figure 8 , gives the coordinate matching effect diagram of the printing feature points and the template feature points. Figure 8 It can be seen that it treats the printed feature points and template feature points with the same coordinates as a feature point combination for subsequent similarity calculation, and will not match irrelevant feature points, thereby improving the subsequent calculation speed of feature point similarity.
[0067] S3: Calculate the similarity between the printing feature points and the template feature points in each feature point combination.
[0068] In this step, after obtaining multiple feature point combinations with coordinate matching, the similarity between the print feature point d1 and the template feature point d2 in each feature point combination with coordinate matching is calculated to characterize whether the corresponding print feature point d1 and the template feature point d2 match. Specifically, the cosine similarity between the feature vector A of the print feature point d1 and the feature vector B of the template feature point d2 can be used to determine whether the corresponding print feature point d1 and the template feature point d2 in the feature point combination with the same coordinates match. The specific calculation formula is:
[0069]
[0070] S4: Selecting a feature point combination whose similarity is greater than a first threshold as a matching feature point combination.
[0071] Specifically, it is determined whether the calculated similarity between the print feature point and the template feature point is greater than a first threshold value. When the similarity is greater than the first threshold value, it is determined that the print feature point and the template feature point in the feature point combination match, and the corresponding feature point combination is selected as the matching feature point combination. Preferably, the first threshold value may be 0.8. When the cosine similarity is greater than 0.8, it is considered that the print feature point and the template feature point are matched, and the corresponding feature point combination is selected as the matching feature point combination. When it is determined that the calculated similarity between the first feature point and the second feature point is less than the first threshold value, it means that the similarity between the first feature point and the second feature point whose coordinates match in the feature point combination does not match, and the feature point combination is abandoned.
[0072] S5: Determine whether the number of matching feature point combinations is greater than a second threshold value. If so, determine that the printed image is qualified; if not, determine that the printed image is unqualified.
[0073] In the above steps, the similarity calculation between the printed feature points and the template feature points in all feature point combinations matching the coordinates is completed, and the feature point combination with a similarity greater than the first threshold is determined as a matching feature point combination, and the number n of matching feature point combinations is obtained. In this step, it is further determined whether the number n of matching feature point combinations is greater than the second threshold. When it is determined that the number n of matching feature point combinations is greater than the second threshold, the printed image is determined to be qualified and is a positive sample; if the number n of matching feature point combinations is not greater than the second threshold, it means that there are too few matching feature points between the standard printed image and the standard template image, and it is a negative sample. The printed image detected as a negative sample can be recalled. Specifically, refer to Fig. 9 , gives a probability distribution diagram of the detection accuracy of printed images using the image detection method of the present application. Fig. 9 It can be seen that nearly 100% of the printed images detected do not match the standard template image and are determined to be unqualified and recalled have less than 20 matching feature points; while nearly 100% of the printed images detected match the standard template image and are determined to be qualified have more than 30 matching feature points. Therefore, in this embodiment, preferably, the second threshold can be set to 30, so as to quickly determine whether the printed image is qualified.
[0074] Compared with the prior art, the image detection method provided by the present invention, when detecting the image printed by the printer, the processor first performs coordinate correction on the printed image and the template image before extracting the image feature points to obtain the optimized printed image and the optimized template image after coordinate alignment, extracts the feature points of the optimized printed image and the optimized template image after coordinate alignment, and then screens the extracted feature points to obtain a coordinate matching feature point combination, and only performs similarity matching calculation on the feature points of the screened coordinate matching feature point combination, thereby reducing a large number of unnecessary calculations, effectively reducing the calculation complexity and amount during image detection, and improving the detection efficiency of the image. For details, please refer to Fig.10 , relative to Figure 1 It can be seen that the computational complexity and amount have been significantly improved.
[0075] Specifically, in one embodiment, the present invention further provides an image detection device, comprising:
[0076] An extraction module, used to extract printing feature points after performing coordinate alignment processing on the printed image; and to extract template feature points after performing coordinate alignment processing on the template image;
[0077] A first matching module is used to match the coordinates of the printing feature points and the template feature points, and select the printing feature points and template feature points with the same coordinates as feature point combinations;
[0078] A calculation module, used for calculating the similarity between the printing feature points and the template feature points in each feature point combination;
[0079] A second matching module uses a feature point combination whose similarity is greater than a first threshold as a matching feature point combination;
[0080] The determination module is used to determine whether the number of matching feature point combinations is greater than a second threshold; if so, the printed image is determined to be qualified; if not, the printed image is determined to be unqualified.
[0081] In one embodiment, the present invention further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and wherein the processor is used to implement any of the above-mentioned image detection methods when executing the computer program.
[0082] In one embodiment, the present invention further provides a computer storage medium, characterized in that it includes a computer program, characterized in that when the computer program is executed by a processor, it implements any of the above-mentioned image detection methods.
[0083] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. An image detection method, characterized in that: include: S1: After performing coordinate alignment processing on the printed image, extracting printing feature points; and extracting the template feature points after performing coordinate alignment processing on the template image; wherein the printed image after the coordinate alignment processing and the template image have the same size; S2: performing coordinate matching on the printing feature points and the template feature points, and selecting printing feature points and template feature points with the same coordinates to form a corresponding plurality of feature point combinations; wherein each feature point combination includes a pair of printing feature points and template feature points with matching coordinates; S3: Calculate the similarity between the printing feature points and the template feature points in each feature point combination; S4: taking a feature point combination whose similarity is greater than a first threshold as a matching feature point combination; S5: Determine whether the number of matching feature point combinations is greater than a second threshold; if so, determine that the printed image is qualified; if not, determine that the printed image is unqualified; Step S1 specifically includes: S1_1: performing grayscale processing and binarization processing on the printed image in sequence to obtain a processed binary printed image; S1_2: performing filtering processing on the binary printed image to obtain a processed first filtered image; S1_3: performing morphological dilation on the processed first filtered image to obtain a target printing area of the first filtered image, and obtaining an optimized first printing image by intercepting the first filtered image based on the target printing area; S1_4: Binarize the template image to obtain a processed first template image; wherein the template image records key point information of the image; S1_5: performing coordinate alignment processing on the first printing image and the first template image to obtain an optimized printing image and an optimized template image; S1_6: Extracting the printing feature points from the optimized printing image, and extracting the template feature points from the optimized template image.
2. The image detection method according to claim 1, characterized in that: In step S1_6, the printing feature points are extracted from the optimized printing image according to a preset extraction algorithm, and the template feature points are extracted from the optimized template image according to a preset extraction algorithm.
3. The image detection method according to claim 2, characterized in that: The preset extraction algorithm includes SIFT.
4. The image detection method according to claim 1, characterized in that: In step S3, the similarity calculation formula is: Among them, cosθ is the similarity, A is the feature vector corresponding to the printed feature point, and B is the feature vector corresponding to the template feature point.
5. The image detection method according to any one of claims 1 to 4, characterized in that: The first threshold is 0.
8.
6. The image detection method according to any one of claims 1 to 4, characterized in that: The second threshold is 30.
7. An image detection device, characterized in that: include: An extraction module is used to extract printing feature points according to a preset extraction algorithm after performing coordinate alignment processing on the printed image; and after performing coordinate alignment processing on the template image, extracting the template feature points according to a preset extraction algorithm; wherein the printed image after the coordinate alignment processing and the template image have the same size; A first matching module is used to match the coordinates of the printing feature points and the template feature points, and to select the printing feature points and template feature points with the same coordinates to form a corresponding plurality of feature point combinations; wherein each feature point combination includes a pair of printing feature points and template feature points with matching coordinates; A calculation module, used for calculating the similarity between the printing feature points and the template feature points in each feature point combination; A second matching module uses a feature point combination whose similarity is greater than a first threshold as a matching feature point combination; A determination module, used to determine whether the number of matching feature point combinations is greater than a second threshold; if so, determining that the printed image is qualified; if not, determining that the printed image is unqualified; The extraction module is specifically used for: S1_1: performing grayscale processing and binarization processing on the printed image in sequence to obtain a processed binary printed image; S1_2: performing filtering processing on the binary printed image to obtain a processed first filtered image; S1_3: performing morphological dilation on the processed first filtered image to obtain a target printing area of the first filtered image, and obtaining an optimized first printing image by intercepting the first filtered image based on the target printing area; S1_4: Binarize the template image to obtain a processed first template image; wherein the template image records key point information of the image; S1_5: performing coordinate alignment processing on the first printing image and the first template image to obtain an optimized printing image and an optimized template image; S1_6: Extracting the printing feature points from the optimized printing image, and extracting the template feature points from the optimized template image.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, it is used to implement the image detection method described in any one of claims 1 to 6.
9. A computer storage medium, characterized in that The method comprises a computer program, wherein when the computer program is executed by a processor, the image detection method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Image matching method, device, computer device and storage medium
CN109101867A
Feature point matching method and device, storage medium and electronic device
CN112419375A
Printed matter defect detection method based on feature registration and gradient shape matching fusion
CN112508826A
Cable printing quality real-time detection method based on image key point matching
CN113780167A