A pesticide bottle cap flaw detection method and system on a quality inspection production line
Patent Information
- Application Number
- CN202611088620.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-22
- Publication Date
- 2026-08-21
AI Technical Summary
但是由于农药瓶盖侧面通常具有竖向条纹,导致传统方法对于图像中瓶盖轮廓的分析不准确,比如将瓶盖的纹理细节作为异常的形变,以及对应的纹理缺失,都会干扰对于瓶盖轮廓的提取,由于对于瓶盖轮廓的异常提取导致对于轮廓的形状出现误判(不呈现为圆形,从而认为存在瓶盖形变缺陷)
本申请通过对待测农药瓶盖顶部拍摄图像,得到待测瓶盖图像,提取图像中瓶盖区域图像,并确定瓶盖区域图像中的纹理特征像素点;通过纹理特征像素点在极坐标系下的分布情况对纹理特征像素点进行筛选,可以确定图像中属于瓶盖边缘纹理位置的像素点;对筛选出的纹理特征像素点进行瓶盖轮廓更新,并进行多次迭代得到最终的轮廓曲线,并获取其在待测瓶盖图像中所围区域内的图像,记为测试图像,能够逐步去除瓶盖边缘纹理区域的图像;对标准瓶盖图像进行相同处理得到其最终的轮廓曲线,并将轮廓曲线所围区域内的图像记为掩膜图像,将测试图像与掩膜图像进行相似度比较,以判断瓶盖是否存在如瓶盖形变等瑕疵缺陷,避免瓶盖边缘的纹理导致瓶盖轮廓提取不准确,对图像匹配结果产生干扰的问题,提高瓶盖瑕疵检测结果可靠性。
Smart Images

Figure CN122617876A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of digital image processing technology, specifically to a method and system for detecting defects in pesticide bottle caps on a quality inspection production line. Background Technology
[0002] Pesticide bottle caps are not ordinary packaging accessories. As the final sealing barrier and safety checkpoint for pesticide formulations, they are an indispensable core quality control link throughout the entire life cycle of pesticide products. The production process of pesticide bottle caps involves injection molding, edge cutting, film application, rubber ring clamping, and embossing, which falls under a typical assembly line. Due to the large-scale, standardized production, it is necessary to judge the defects of pesticide bottle caps on the quality inspection line to determine whether the production is qualified. Based on the quality inspection results, the production process and related parameters can be improved.
[0003] In the quality inspection of pesticide bottle caps, image matching is typically performed between standard bottle cap samples and test samples. The circular shape of the bottle cap and the matching results are used to determine if the currently produced bottle caps have defects, such as deformation. However, because pesticide bottle caps usually have vertical stripes on their sides, traditional methods are inaccurate in analyzing the bottle cap contour in the image. For example, misinterpreting the texture details of the bottle cap as abnormal deformation, or corresponding texture loss, interferes with the extraction of the bottle cap contour. This abnormal extraction of the bottle cap contour leads to misjudgments of its shape (e.g., not being circular, thus being considered a deformation defect). Inaccurate contour extraction results in unreliable image matching results, thus affecting the quality inspection results of the bottle caps. Summary of the Invention
[0004] To address the aforementioned technical problems, the purpose of this application is to provide a method and system for detecting defects in pesticide bottle caps on a quality inspection production line. The specific technical solution adopted is as follows: In a first aspect, embodiments of this application provide a method for detecting defects in pesticide bottle caps on a quality inspection production line, the method comprising the following steps: An image of the top of the pesticide bottle cap to be tested is obtained by taking an image of the bottle cap to be tested; an image of the top of the standard pesticide bottle cap is obtained by taking an image of the standard pesticide bottle cap. Extract the outer contour of the bottle cap from the image of the bottle cap to be tested, as the initial contour; obtain the texture feature pixels within the initial contour based on the gradient of each pixel in the region within the initial contour. A polar coordinate system is constructed with the center of the largest inscribed circle of the initial contour as the origin. The texture feature pixels are filtered based on the distribution of texture feature pixels within the range of the polar angle corresponding to the polar angle in the polar coordinate system. The filtered texture feature pixels are fitted to obtain the contour curve after the first iteration update of the initial contour. The final contour curve is obtained through multiple iterations, and its image within the area enclosed by the bottle cap image to be tested is obtained and recorded as the test image. Accordingly, the final contour curve obtained by iteratively acquiring the standard image is obtained, and the image within the area enclosed by the standard image is acquired, denoted as the mask image; the similarity between the test image and the mask image is analyzed to determine whether there are defects in the pesticide bottle cap.
[0005] In one embodiment, the process of obtaining the texture feature pixels is as follows: The region between the initial contour and its largest inscribed circle is defined as the texture region. The gradient of each pixel in the grayscale image of the bottle cap to be tested is calculated using a gradient detection algorithm. The average gradient of all pixels within the largest inscribed circle is used as the gradient threshold, and pixels in the texture region whose gradient is greater than the gradient threshold are defined as texture feature pixels.
[0006] In one embodiment, the process of filtering texture feature pixels is as follows: For any texture feature pixel, the set of texture feature pixels within the range of its polar angle is denoted as the edge texture pixel set of the given texture feature pixel; the edge texture pixel set whose element quantity ratio is greater than a preset ratio threshold is labeled as 1; Obtain the theoretical interval angle between two adjacent vertical lines on the edge of a standard pesticide bottle cap; among all texture feature pixels, obtain the set of edge texture pixels consisting of all texture feature pixels whose polar angles differ from the theoretical interval angle by an integer multiple, denoted as the edge texture information set; The proportion of edge texture pixels with label 1 in each edge texture information set is calculated as the accuracy of each edge texture information set. The set of edge texture information with the highest accuracy is used as the set of bottle cap texture information, and the pixels in the set of bottle cap texture information are the selected texture feature pixels.
[0007] In one embodiment, the multiple iterations further include: Except for the first iteration, in each subsequent iteration, the accuracy of each edge texture information set needs to be corrected. The edge texture information set corresponding to the maximum value of the corrected accuracy is used as the bottle cap texture information set in each iteration.
[0008] In one embodiment, the accuracy correction process is as follows: Calculate the pixel intersection-union ratio (IUGR) between the current iteration's edge texture information set and the previous iteration's bottle cap texture information set, and use the IUGR multiplied by the accuracy of the current iteration's edge texture information set as the corrected accuracy.
[0009] In one embodiment, the process of obtaining the contour curve after the first iteration update is as follows: Calculate the mean coordinates of all pixels in each edge texture pixel set, and fit the mean coordinates of all edge texture pixel sets in the bottle cap texture information set to a closed contour using a closed contour fitting algorithm. The resulting fitted contour curve is used as the contour curve after the first iteration update.
[0010] In one embodiment, the stopping condition for the iteration is: Based on the number of texture feature pixels obtained in the current iteration, and the difference between the polar angles corresponding to the edge texture pixel sets in the bottle cap texture information set of the current iteration and the previous iteration, the stopping coefficient of the current iteration is constructed. If the stopping coefficient of the current iteration is greater than the preset stability threshold, or if the current iteration count reaches the preset maximum iteration count, then the iteration stops.
[0011] In one embodiment, the expression for the stopping coefficient of the current iteration is: In the formula, is the stopping coefficient for the current iteration; z is the ratio of the number of texture feature pixels in the texture update region obtained in the current iteration to the number of texture feature pixels in the texture existence region obtained from the initial contour. It is the set of polar angles corresponding to all edge texture pixel sets in the bottle cap texture information set of the current iteration; It is the set of polar angles corresponding to all edge texture pixels in the bottle cap texture information set of the previous iteration; Indicate the difference between two sets; This is the normalization function.
[0012] In one embodiment, the analysis of the similarity between the test image and the mask image to determine whether there are defects in the pesticide bottle cap specifically involves: The test image and the mask image are respectively processed by an edge detection algorithm to obtain edge images of the test image and the mask image. The similarity between the two edge images is compared. If the similarity is less than a preset difference threshold, it is determined that the bottle cap corresponding to the test image has a defect; otherwise, it is determined that there is no defect.
[0013] Secondly, embodiments of this application also provide a pesticide bottle cap defect detection system on a quality inspection production line, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of any of the methods described above.
[0014] The embodiments of this application have at least the following beneficial effects: This application obtains an image of the top of a pesticide bottle cap by taking a picture of it, extracts the bottle cap region image from the image, and identifies the texture feature pixels in the bottle cap region image. By filtering the texture feature pixels according to their distribution in polar coordinates, pixels belonging to the bottle cap edge texture location in the image can be identified. The selected texture feature pixels are used to update the bottle cap contour, and multiple iterations are performed to obtain the final contour curve. The image within the region enclosed by this curve in the bottle cap image is obtained and recorded as the test image, which can gradually remove the image of the bottle cap edge texture region. The same processing is performed on a standard bottle cap image to obtain its final contour curve, and the image within the region enclosed by the contour curve is recorded as the mask image. The similarity between the test image and the mask image is compared to determine whether the bottle cap has defects such as deformation. This avoids the problem of inaccurate bottle cap contour extraction due to the texture of the bottle cap edge, which interferes with the image matching results, thus improving the reliability of the bottle cap defect detection results. Attached Figure Description
[0015] Figure 1 A flowchart illustrating the steps of a method for detecting defects in pesticide bottle caps on a quality inspection production line, as provided in one embodiment of this application; Figure 2 This is a schematic diagram illustrating the process of filtering texture feature pixels. Detailed Implementation
[0016] The following description, in conjunction with the accompanying drawings, details the specific scheme of the pesticide bottle cap defect detection method and system provided in this application.
[0017] Please see Figure 1 The document illustrates a flowchart of a method for detecting defects in pesticide bottle caps on a quality inspection production line, according to an embodiment of this application. The method includes the following steps: Step S1: Take an image of the top of the pesticide bottle cap to be tested to obtain the image of the bottle cap to be tested; take an image of the top of the standard pesticide bottle cap to obtain the standard image.
[0018] A camera is installed at the bottle cap inspection position on the quality inspection production line, surrounded by a shadowless light source. When the pesticide bottle cap to be tested is conveyed to the inspection position, the camera is activated to capture an image of the bottle cap. The image is then processed using image enhancement algorithms such as deblurring and delighting. In this embodiment, the Retinex algorithm is used for image enhancement. Many existing image enhancement algorithms exist, and implementers may use other image enhancement algorithms to enhance the captured images; this application does not impose specific limitations. The processed bottle cap image is used as the initial image. It should be noted that this application requires capturing a top view of the bottle cap.
[0019] A standard pesticide bottle cap without defects is placed at the inspection position to capture an image of the standard pesticide bottle cap, which is then processed using an image enhancement algorithm to obtain a standard image.
[0020] Step S2: Extract the outer contour of the bottle cap from the image of the bottle cap to be tested, as the initial contour; obtain the texture feature pixels in the initial contour based on the gradient of each pixel in the region within the initial contour.
[0021] Pesticide bottle caps typically have prominent vertical lines on their sides. These lines are used as the bottle cap's texture, but their texture features can interfere with the judgment of the entire bottle cap's outline. If the image captured during the detection process contains texture, it can cause the bottle cap's outline to appear uneven. Furthermore, in the top view, because the texture and the bottle cap are made of the same material, the features are not obvious. For example, sometimes the edge texture can be detected, leading to an uneven appearance, while other times it cannot be detected, thus interfering with the judgment of whether there are minor deformations in the outline.
[0022] Because the texture around the captured pesticide bottle cap image can interfere with the judgment of the bottle cap outline, for example, there may be missing textures, or the outline information of the bottle cap may not be accurately extracted due to interference from edge textures, resulting in inaccurate extraction of the bottle cap outline and thus inaccurate judgment of deformation.
[0023] The initial image is converted to grayscale. Edge detection algorithms are then used to detect edges in the grayscale image, obtaining the contour of the largest closed edge. This contour encompasses the entire bottle cap, and therefore includes the textured area at the bottle cap's edge. However, the vertical lines on the bottle cap's edge can interfere with the determination of the bottle cap's true shape. Therefore, this contour is used as the initial contour. In this embodiment, the edge detection algorithm used is the Sobel operator. There are many existing edge detection algorithms, and implementers can also use other edge detection algorithms to obtain edges in grayscale images. This application does not impose any specific restrictions.
[0024] Since the bottle cap image is circular, the largest inscribed circle within the initial contour is obtained. This circle does not contain the edge details and texture of the bottle cap, preventing the extracted contour from having a jagged shape due to texture factors. The area formed between the inscribed circle and the initial contour is considered the textured area of the image. Due to segmentation accuracy and contour edge texture recognition issues, such as some areas being considered noise, the largest inscribed circle of the image may not necessarily be the actual bottle cap area reflecting its true shape or position.
[0025] Within the textured areas, due to the presence of relatively obvious contour details, even though the bottle cap's texture belongs to the same material, it still exhibits certain grayscale differences under different lighting conditions. Therefore, a gradient detection algorithm is used to calculate the gradient of each pixel in the initial image's grayscale map. In this embodiment, the Sobel operator is used to obtain the gradient of each pixel in the grayscale map.
[0026] The gradient image of the pixels within the texture region is denoted as T1; the gradient image of the pixels within the largest inscribed circle is denoted as T2, which is used to represent the gradient change of a normal bottle cap; the average gradient value in the T2 image is used as the gradient threshold of the T1 image, and the pixels in the T1 image whose gradient is greater than the gradient threshold are obtained as texture feature pixels, which represent pixels with obvious gradients in the texture region, and the set of these pixels is used as the feature pixel set M.
[0027] Step S3: Construct a polar coordinate system with the center of the largest inscribed circle of the initial contour as the origin. Based on the distribution of texture feature pixels within the range of the polar angle corresponding to the texture feature pixels in the polar coordinate system, filter the texture feature pixels. Fit the filtered texture feature pixels to obtain the contour curve after the first iteration update of the initial contour. Iterate multiple times to obtain the final contour curve and obtain its image within the area enclosed by the bottle cap image to be tested, which is recorded as the test image.
[0028] Since the vertical lines on the edge of pesticide bottle caps are distributed at equal angles, the theoretical interval angle between adjacent vertical lines is first obtained by manually measuring the angle between the line connecting two adjacent vertical lines on a standard pesticide bottle cap and the center point of the standard pesticide bottle cap. .
[0029] Furthermore, taking any texture feature pixel q within the texture region as an example, we treat it as a vertical texture pixel on the edge of the bottle cap, and obtain the center position of the aforementioned largest inscribed circle. With the center of the circle Construct a polar coordinate system with the origin as the origin, the horizontal direction to the right of the origin as the polar axis, and the counterclockwise direction as the positive angle direction, and obtain the polar angle of the texture feature pixel in this polar coordinate system. Set the angle deviation amount Obtain polar angle All texture feature pixels within the angular deviation range, i.e., obtaining the polar angle. The set of all texture feature pixels within the range is taken as the corresponding angle of texture feature pixel q. The set of edge texture pixels at the location, denoted as If the texture feature pixel q is a pixel on the vertical stripe texture of the bottle cap edge, then the set This represents the set of pixels corresponding to the vertical ridge texture on the edge of the same bottle cap. (Get the set) The percentage of pixels in set M It is allowed to be an empty set, in which case the proportion is 0.
[0030] After that, if the polar angle The polar angle corresponds to the location of the vertical stripe. Theoretically, this corresponds to the position of the next vertical line. Therefore, the same method as above is used to calculate the polar angle. The edge texture pixel set below and the corresponding quantity percentage Repeat the above process to obtain the polar angles sequentially. , … The set of edge texture pixels and their corresponding proportions are shown below. Here, n is the number of vertical lines on the edge of a standard pesticide bottle cap. The polar angle corresponding to the texture feature pixel q is also shown. edge texture pixel set The set formed by combining the q with all other inferred edge texture pixel sets is used as the edge texture information set corresponding to the texture feature pixel q. .
[0031] Taking texture feature pixel q as an example, set the proportion threshold. ,in, The preset fault tolerance rate, The value ranges from 0 to 1. The smaller the value, the higher the accuracy requirement for edge texture detection. In this embodiment, The value is set to 0.9. In other embodiments of this application, the implementer may set the value according to the actual situation. The value. If the proportion p corresponding to a single edge texture pixel set m is less than the proportion threshold. If the vertical lines on the bottle cap edge do not actually exist at the corresponding polar angle position, the label of the edge texture pixel set is set to 0; otherwise, the label is set to 1.
[0032] The label of each edge texture pixel set in the edge texture information set T corresponding to the texture feature pixel point q is obtained through the above method, and the proportion of edge texture pixel sets with label 1 in set T is calculated. , which represents the accuracy of the set T for contour analysis.
[0033] Obtain the set of edge texture information corresponding to each texture feature pixel and the accuracy corresponding to that set. It can be understood that if any remaining texture feature pixel... polar angle The polar angle equal to the texture feature pixel q Add i times ,or Add i times equal Then the texture feature pixels The elements in the edge texture information set of texture feature pixel q are the same as those in the edge texture information set of texture feature pixel q. Therefore, if the edge texture information set of texture feature pixel q has already been obtained, it is not necessary to further refine the edge texture information set of texture feature pixel q. Perform the same calculations to reduce the amount of computation. Here, i is an integer between 0 and n.
[0034] Among all the edge texture information sets of texture feature pixels, the set of edge texture information with the highest accuracy is selected as the final determined set of bottle cap texture information, denoted as . .
[0035] For the final set of bottle cap texture information Given a set of edge texture pixels m, calculate the pixel corresponding to the mean polar coordinate of all texture feature pixels in the set, and use this as the updated pixel for the current iteration; then... A closed contour curve is fitted to the updated pixels corresponding to all edge texture pixels in the dataset. In this embodiment, a closed contour curve fitting method based on polar coordinate polynomials is used to fit the closed contour curve of the updated pixels. Many existing closed contour curve fitting methods exist, and implementers may also use other closed contour curve fitting methods to fit the closed contour curve of all updated pixels; this application does not impose specific limitations. This yields the first updated contour curve of the initial contour. The subsequent contour iteration process is as follows: For the updated contour curve, the updated position moves towards the inside of the bottle cap area. Therefore, the contour curve gradually approaches the contour that does not contain the bottle cap texture features. The updated contour is compared with the initial contour, and the area formed by the two is taken as the texture area that has been removed after the update.
[0036] For the first updated contour curve The updated contour curve was obtained using the same analytical method as described above. Specifically, obtaining the contour curve The largest inscribed circle is used to obtain the contour curve. The region between the maximum inscribed circle and the maximum inscribed circle is denoted as the texture update region. The mean gradient of all pixels within this maximum inscribed circle is used as the gradient threshold for the texture update region to obtain the texture feature pixels. Then, the edge texture information set and corresponding accuracy of all texture feature pixels are obtained, and the edge texture information set with the highest accuracy is selected as the new bottle cap texture information set. The updated pixels of the current iteration are then fitted with a closed contour curve using the new bottle cap texture information set to obtain the contour curve after the second update. And so on, to obtain the updated contour curves.
[0037] However, due to the removal of textured regions after each contour update, the texture feature analysis within the subsequent contour curve is more susceptible to noise interference due to the reduced number of relevant feature points. This leads to a lower accuracy of the bottle cap texture information set obtained through the above process. In other words, each set in the bottle cap texture information set may not necessarily represent the pixel set of each vertical texture region of the real bottle cap. Because it is easily affected by noise, the following corrections are needed: Obtain the polar angles corresponding to each set within the bottle cap texture information set during the previous iteration. Since the texture features of the entire bottle cap image do not change during the contour change process, the corresponding polar angle should remain consistent in each iteration. Therefore, the bottle cap texture existing in the current contour area should be consistent with the texture analysis of the entire bottle cap image.
[0038] As the contour is continuously updated, although the texture information within the corresponding contour decreases, the texture information of the removed texture areas increases. Therefore, to obtain the overlap between the pixels in the current iteration's set of edge texture information and the previous iteration's set of bottle cap texture information, this embodiment determines the overlap by calculating the intersection-union ratio (IUU) of the pixels in the two sets, and uses the IUU as a correction factor for the accuracy of the current iteration's set of edge texture information. The corrected accuracy rate is obtained. The set of edge texture information with the highest accuracy after correction is selected as the set of bottle cap texture information for the current iteration. It should be noted that since there is no previous iteration for the first iteration, the accuracy b of the first iteration does not need to be corrected.
[0039] The initial contour is updated iteratively using the above method. The stopping condition for the iteration is determined as follows: As the contour curve shrinks iteratively, the resulting contour tends to resemble the true bottle cap contour after removing texture interference. The angle corresponding to the texture in two adjacent iterations does not change, and the number of pixels representing the texture within the contour decreases with each iteration. Therefore, if the number of pixels representing the texture decreases to a certain level, and the similarity of pixel positions in the bottle cap texture information set extracted in two adjacent iterations exceeds a preset stability threshold, the texture extraction is considered to have converged, and the iteration stops. Therefore, based on the above analysis, the stopping coefficient for the current iteration is constructed, expressed as: In the formula, is the stopping coefficient for the current iteration; z is the ratio of the number of texture feature pixels in the texture update region obtained in the current iteration to the number of texture feature pixels in the texture existence region obtained from the initial contour. This is the set of polar angles corresponding to all edge texture pixel sets in the current iteration's bottle cap texture information set, where the edge texture pixel set... For example, its corresponding polar angle is ; It is the set of polar angles corresponding to all edge texture pixels in the bottle cap texture information set of the previous iteration; Indicate the difference between two sets; This is a normalization function. This embodiment uses the maximum-minimum value normalization method to... Normalization is performed, where the maximum and minimum values in the maximum-minimum normalization method are determined by using historical samples.
[0040] In this embodiment, Specifically: in the set Choose any polar angle and obtain the polar angle and the set. The minimum value of the actual difference between all polar angles is taken as For example, the actual difference between 0° and 370° is 10°; the actual difference between 0° and 355° is 5°. The smaller the value, the more consistent the polar angles are between two adjacent iterations.
[0041] The iteration stops if the stopping coefficient of the current iteration is greater than a preset stability threshold, or if the current iteration count reaches a preset maximum iteration count. In this embodiment, the stability threshold is set to 0.96, and the maximum contour iteration count is set to... In other embodiments of this application, the implementer may set the stability threshold and the maximum number of contour iterations according to the actual situation.
[0042] This yields the initial contour curve of the initial image at the point where iteration stops. The image within the region enclosed by this contour curve in the initial image is then recorded as the test image.
[0043] In step S4, the final contour curve of the standard image obtained through iteration is acquired, and the image within the area enclosed by the standard image is acquired and denoted as the mask image; the similarity between the test image and the mask image is analyzed to determine whether there are defects in the pesticide bottle cap.
[0044] The same processing method is applied to the standard image to obtain the initial contour curve of the standard image when the iteration stops. The image within the region enclosed by the contour curve in the standard image is recorded as the mask image.
[0045] Edge detection is performed on both the test image and the mask image using an edge detection algorithm, resulting in edge images of both the test image and the mask image. The similarity between these two edge images is calculated using the SSIM (Structural Similarity Index) algorithm. If the obtained SSIM value is less than a preset difference threshold, the bottle cap corresponding to the test image is determined to have a defect; otherwise, it is determined that there is no defect. The SSIM algorithm is a well-known technique, and its specific process will not be described in detail. In this embodiment, the difference threshold is set to 0.9. In other embodiments of this application, the implementer can set the difference threshold according to the actual situation.
[0046] It should be noted that this application only provides one similarity detection method for detecting the similarity between the test image and the mask image. There are many existing similarity detection methods, and implementers may also use other similarity detection methods to obtain the similarity between the test image and the mask image. This application does not impose any specific restrictions.
[0047] A schematic diagram illustrating the process of filtering texture feature pixels is shown below. Figure 2 As shown.
[0048] Based on the same inventive concept as the above method, this application embodiment also provides a pesticide bottle cap defect detection system on a quality inspection production line, including a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the steps of any one of the above-described pesticide bottle cap defect detection methods on a quality inspection production line.
[0049] In summary, this application provides a method for detecting defects in pesticide bottle caps on a quality inspection production line. The method involves capturing an image of the top of the pesticide bottle cap to be tested, extracting the bottle cap region image, and identifying texture feature pixels within the bottle cap region image. By filtering the texture feature pixels based on their distribution in polar coordinates, pixels belonging to the bottle cap edge texture location can be identified. The selected texture feature pixels are then used to update the bottle cap contour, and multiple iterations are performed to obtain the final contour curve. The image within the region enclosed by this curve in the bottle cap image is then captured as the test image, gradually removing the image of the bottle cap edge texture region. The same processing is applied to a standard bottle cap image to obtain its final contour curve, and the image within the region enclosed by the contour curve is captured as the mask image. The test image and the mask image are compared for similarity to determine if the bottle cap has defects such as deformation. This method avoids inaccurate bottle cap contour extraction due to the texture of the bottle cap edge, which could interfere with image matching results and improve the reliability of bottle cap defect detection.
Claims
1. A method for detecting defects in pesticide bottle caps on a quality inspection production line, characterized in that, The method includes the following steps: An image of the top of the pesticide bottle cap to be tested is obtained by taking an image of the bottle cap to be tested; an image of the top of the standard pesticide bottle cap is obtained by taking an image of the standard pesticide bottle cap. Extract the outer contour of the bottle cap from the image of the bottle cap to be tested, and use it as the initial contour; obtain the texture feature pixels in the initial contour based on the gradient of each pixel in the initial contour. A polar coordinate system is constructed with the center of the largest inscribed circle of the initial contour as the origin. The texture feature pixels are filtered based on the distribution of texture feature pixels within the range of the polar angle corresponding to the polar angle in the polar coordinate system. The filtered texture feature pixels are fitted to obtain the contour curve after the first iteration update of the initial contour. The final contour curve is obtained through multiple iterations, and its image within the area enclosed by the bottle cap image to be tested is obtained and recorded as the test image. Accordingly, the final contour curve obtained by iteratively acquiring the standard image is obtained, and the image within the area enclosed by the standard image is acquired, denoted as the mask image; the similarity between the test image and the mask image is analyzed to determine whether there are defects in the pesticide bottle cap.
2. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 1, characterized in that, The process of obtaining the texture feature pixels is as follows: The region between the initial contour and its largest inscribed circle is defined as the texture region. The gradient of each pixel in the grayscale image of the bottle cap to be tested is calculated using a gradient detection algorithm. The average gradient of all pixels within the largest inscribed circle is used as the gradient threshold, and pixels in the texture region whose gradient is greater than the gradient threshold are defined as texture feature pixels.
3. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 1, characterized in that, The process of filtering texture feature pixels is as follows: For any texture feature pixel, the set of texture feature pixels within the range of its polar angle is denoted as the edge texture pixel set of the given texture feature pixel; the edge texture pixel set whose element quantity ratio is greater than a preset ratio threshold is labeled as 1; Obtain the theoretical interval angle between two adjacent vertical lines on the edge of a standard pesticide bottle cap; among all texture feature pixels, obtain the set of edge texture pixels consisting of all texture feature pixels whose polar angles differ from the theoretical interval angle by an integer multiple, denoted as the edge texture information set; The proportion of edge texture pixels with label 1 in each edge texture information set is calculated as the accuracy of each edge texture information set. The set of edge texture information with the highest accuracy is used as the set of bottle cap texture information, and the pixels in the set of bottle cap texture information are the selected texture feature pixels.
4. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 3, characterized in that, The process of multiple iterations also includes: Except for the first iteration, in each subsequent iteration, the accuracy of each edge texture information set needs to be corrected. The edge texture information set corresponding to the maximum value of the corrected accuracy is used as the bottle cap texture information set in each iteration.
5. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 4, characterized in that, The process of correcting the accuracy is as follows: Calculate the pixel intersection-union ratio (IUGR) between the current iteration's edge texture information set and the previous iteration's bottle cap texture information set, and use the IUGR multiplied by the accuracy of the current iteration's edge texture information set as the corrected accuracy.
6. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 3, characterized in that, The process of obtaining the contour curve after the first iteration update is as follows: Calculate the mean coordinates of all pixels in each edge texture pixel set, and fit the mean coordinates of all edge texture pixel sets in the bottle cap texture information set to a closed contour using a closed contour fitting algorithm. The resulting fitted contour curve is used as the contour curve after the first iteration update.
7. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 3, characterized in that, The stopping condition for the iteration is: Based on the number of texture feature pixels obtained in the current iteration, and the difference between the polar angles corresponding to the edge texture pixel sets in the bottle cap texture information set of the current iteration and the previous iteration, the stopping coefficient of the current iteration is constructed. If the stopping coefficient of the current iteration is greater than the preset stability threshold, or if the current iteration count reaches the preset maximum iteration count, then the iteration stops.
8. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 7, characterized in that, The expression for the stopping coefficient of the current iteration is: In the formula, is the stopping coefficient for the current iteration; z is the ratio of the number of texture feature pixels in the texture update region obtained in the current iteration to the number of texture feature pixels in the texture existence region obtained from the initial contour. It is the set of polar angles corresponding to all edge texture pixel sets in the bottle cap texture information set of the current iteration; It is the set of polar angles corresponding to all edge texture pixels in the bottle cap texture information set of the previous iteration; Indicate the difference between two sets; This is the normalization function.
9. The method for detecting defects in pesticide bottle caps on a quality inspection production line as described in claim 1, characterized in that, The analysis of the similarity between the test image and the mask image is used to determine whether there are defects in the pesticide bottle cap. Specifically: The test image and the mask image are respectively processed by an edge detection algorithm to obtain edge images of the test image and the mask image. The similarity between the two edge images is compared. If the similarity is less than a preset difference threshold, it is determined that the bottle cap corresponding to the test image has a defect; otherwise, it is determined that there is no defect.
10. A pesticide bottle cap defect detection system for a quality inspection production line, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-9.