Capsule production quality detection method and system based on machine vision

Through machine vision-based detection methods, image processing technology is used to detect cracks on the capsule surface, which solves the problem of low detection accuracy of traditional methods, and achieves higher detection accuracy and capsule quality evaluation capabilities.

CN120163774AInactive Publication Date: 2025-06-17DONGYING ZOUNING BIOTECHNOLOGY CO LTD
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202510209050.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-25
Publication Date
2025-06-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional image processing methods are difficult to accurately detect cracks on the capsule surface, resulting in a decrease in the accuracy of capsule production quality detection results.

Method used

The detection method based on machine vision is used to detect the quality of the capsule by collecting capsule surface images, greyscale processing, obtaining edge pixel points, and calculating the crack edge degree and chaos degree.

Benefits of technology

It improves the accuracy of the capsule production quality test results, reduces the interference of ambient light and shadow and reflection, and enhances the ability to identify crack areas.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120163774A_ABST
    Figure CN120163774A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image processing, in particular to a capsule production quality detection method and system based on machine vision, and the method comprises the steps: collecting a grayscale image of any capsule, and obtaining edge pixel points in the grayscale image according to the gradient value of each pixel point in the grayscale image; for any edge pixel point, obtaining neighborhood pixel points of the edge pixel point, obtaining a crack edge degree of the edge pixel point according to the gray value difference and the gradient value difference between the neighborhood pixel points, and obtaining a crack edge pixel point according to the crack edge degree of each edge pixel point; according to the method, the suspected crack area is obtained according to each crack edge pixel point, the confusion degree of each suspected crack area is obtained according to the gray value and the gradient direction of each pixel point in each suspected crack area, the quality of the capsule is detected according to the confusion degree of all the suspected crack areas, and the accuracy of a capsule production quality detection result is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular, to a method and system for detecting the production quality of capsules based on machine vision. Background Art

[0002] During the processing of capsules, if the capsule rubber is too thick or the process parameters (such as temperature, pressure, time, etc.) are set improperly, it will cause excessive pressure or tension at the interface during processing or forming, resulting in quality problems such as cracks. Once cracks appear on the capsule shell, the drug may be released prematurely, causing the drug to decompose in an inappropriate environment (such as the gastric acid environment), thus affecting the stability and efficacy of the drug. Therefore, it is essential to detect whether the capsule contains cracks.

[0003] In the traditional method, image processing is used to detect whether the capsule contains cracks. However, due to the good smoothness of the capsule surface, it will reflect objects in the environment, forming environmental light and shadow and specular reflection on the capsule surface, resulting in the inability to distinguish normal specular reflection, light and shadow on the capsule from abnormal cracks during detection, thereby reducing the accuracy of the detection results of the capsule production quality.

[0004] Therefore, how to accurately detect cracks on the capsule surface to improve the accuracy of the detection results of the capsule production quality has become an urgent problem to be solved. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and system for detecting the production quality of capsules based on machine vision to solve the problem of how to accurately detect cracks on the capsule surface to improve the accuracy of the detection results of the capsule production quality.

[0006] In a first aspect, embodiments of the present invention provide a method for detecting the production quality of capsules based on machine vision, the method comprising the following steps:

[0007] Collect the surface image of any capsule, perform grayscale processing on the surface image to obtain a corresponding grayscale image, and obtain at least one edge pixel point in the grayscale image according to the gradient value of each pixel point in the grayscale image;

[0008] For any edge pixel point, obtain a preset number of neighborhood pixel points of the any edge pixel point, obtain the crack edge degree of the any edge pixel point according to the grayscale value difference and gradient value difference between each neighborhood pixel point, obtain the crack edge degree of each edge pixel point, and obtain at least one crack edge pixel point in the grayscale image according to the crack edge degree of each edge pixel point;

[0009] Based on each of the crack edge pixel points, at least one suspected crack region in the grayscale image is obtained. According to the complexity of the grayscale values and gradient directions of each pixel point in each suspected crack region, the degree of chaos of each suspected crack region is obtained. According to the degrees of chaos of all suspected crack regions, the quality of any one of the capsules is detected.

[0010] Further, obtaining at least one edge pixel point in the grayscale image according to the gradient value of each pixel point in the grayscale image includes:

[0011] According to the gradient value of each pixel point in the grayscale image, the maximum gradient value is obtained. The maximum gradient value multiplied by a first preset multiple is used as the gradient threshold. The pixel points in the grayscale image whose gradient values are greater than or equal to the gradient threshold are used as suspected edge pixel points;

[0012] For any suspected edge pixel point, a first window with a first preset size is established centered on the any suspected edge pixel point. The other pixel points in the first window except the any suspected edge pixel point are used as the first neighborhood pixel points of the any suspected edge pixel point;

[0013] The number of first neighborhood pixel points whose gradient values are greater than or equal to the gradient threshold is counted. If the number is greater than a preset target number threshold, the any suspected edge pixel point is marked as an edge pixel point.

[0014] Further, obtaining a preset number of neighborhood pixel points of the any edge pixel point, and obtaining the crack edge degree of the any edge pixel point according to the grayscale value difference and gradient value difference between each of the neighborhood pixel points includes:

[0015] A second window with a second preset size is established centered on the any edge pixel point. The other pixel points in the second window except the any edge pixel point are used as the second neighborhood pixel points of the any edge pixel point;

[0016] In the second window, the pixel points whose gradient values are greater than or equal to the gradient threshold are connected to obtain the regional segmentation line of the second window. According to the regional segmentation line, the second window is divided into at least one sub-region;

[0017] If there is only one sub-region in the second window, the average grayscale value of all second neighborhood pixel points in the sub-region is calculated. The average grayscale value multiplied by a second preset multiple is used as the grayscale distribution characteristic index of the second window. The sum of the grayscale distribution characteristic index of the second window and the reciprocal of the grayscale value of the any edge pixel point is linearly normalized to obtain the grayscale characteristic value of the any edge pixel point;

[0018] If there are more than one sub-region in the second window, calculate the average gray value of all the second neighborhood pixel points in each sub-region respectively, take the absolute value of the difference between all the average gray values as the gray difference degree of the second window, and perform linear normalization on the sum result of the gray difference degree of the second window and the reciprocal of the gray value of any edge pixel point to obtain the gray feature value of any edge pixel point;

[0019] In the grayscale image, obtain the gradient feature value of any edge pixel point according to the gradient value difference between any edge pixel point and its adjacent pixel points;

[0020] Perform linear normalization on the sum result of the gray feature value and the gradient feature value of any edge pixel point to obtain the crack edge degree of any edge pixel point.

[0021] Further, the obtaining the gradient feature value of any edge pixel point according to the gradient value difference between any edge pixel point and its adjacent pixel points includes:

[0022] Obtain the left adjacent pixel point and the right adjacent pixel point of any edge pixel point respectively, take any edge pixel point, the left adjacent pixel point and the right adjacent pixel point as horizontal target pixel points, and construct a horizontal direction gradient broken line graph according to the gradient values of each horizontal target pixel point, where the horizontal axis of the horizontal direction gradient broken line graph represents the position of each horizontal target pixel point in the grayscale image, and the vertical axis of the horizontal direction gradient broken line graph represents the gradient value of each horizontal target pixel point;

[0023] Obtain the upper adjacent pixel point and the lower adjacent pixel point of any edge pixel point respectively, take any edge pixel point, the upper adjacent pixel point and the lower adjacent pixel point as vertical target pixel points, and construct a vertical direction gradient broken line graph according to the gradient values of each vertical target pixel point, where the horizontal axis of the vertical direction gradient broken line graph represents the position of each vertical target pixel point in the grayscale image, and the vertical axis of the vertical direction gradient broken line graph represents the gradient value of each vertical target pixel point;

[0024] In the horizontal direction gradient broken line graph, obtain the left slope between any edge pixel point and its left adjacent pixel point, and the right slope between any edge pixel point and its right adjacent pixel point, calculate the ratio between the left slope and the right slope to obtain the horizontal gradient similarity between any edge pixel point and its adjacent pixel points;

[0025] In the vertical direction gradient broken line graph, obtain the vertical gradient similarity between any edge pixel point and its adjacent pixel points, and select the maximum value of the absolute value of the horizontal gradient similarity and the absolute value of the vertical gradient similarity as the gradient eigenvalue of any edge pixel point.

[0026] Further, obtaining at least one crack edge pixel point in the grayscale image according to the crack edge degree of each of the edge pixel points includes:

[0027] For any edge pixel point, if the crack edge degree of the any edge pixel point is greater than or equal to a preset crack edge degree threshold, then use the any edge pixel point as a crack edge pixel point.

[0028] Further, obtaining the degree of chaos of each of the suspected crack regions according to the complexity of the grayscale value and the gradient direction of each pixel point in each of the suspected crack regions includes:

[0029] For any suspected crack region, count the number of different grayscale values according to the grayscale values of each pixel point in the any suspected crack region, obtain the information entropy of the gradient direction in the any suspected crack region according to the gradient directions of each pixel point in the any suspected crack region, and normalize the summation result of the opposite of the reciprocal of the number of different grayscale values and the information entropy to obtain the degree of chaos of the any suspected crack region.

[0030] Further, detecting the quality of any capsule according to the degree of chaos of all the suspected crack regions includes:

[0031] For any suspected crack region, if the degree of chaos of the any suspected crack region is less than or equal to a preset degree of chaos threshold, then mark the any suspected crack region as a crack region;

[0032] If there is a crack region in the grayscale image, then determine that there is a quality problem with the capsule corresponding to the grayscale image;

[0033] If there is no crack region in the grayscale image, then determine that there is no quality problem with the capsule corresponding to the grayscale image.

[0034] Further, obtaining at least one suspected crack region in the grayscale image according to each of the crack edge pixel points includes:

[0035] According to all the crack edge pixel points in the grayscale image, use the Freeman chain code to extract the contour to obtain at least one region contour in the grayscale image;

[0036] For any area contour, a suspected crack area corresponding to the any area contour is obtained by using a morphological dilation operation.

[0037] In a second aspect, an embodiment of the present invention further provides a capsule production quality detection system based on machine vision, 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, a capsule production quality detection method based on machine vision as described in the first aspect is implemented.

[0038] The beneficial effects of the embodiment of the present invention compared with the prior art are as follows:

[0039] The present invention collects a surface image of any capsule, performs grayscale processing on the surface image to obtain a corresponding grayscale image, and obtains at least one edge pixel point in the grayscale image according to the gradient value of each pixel point in the grayscale image; for any edge pixel point, a preset number of neighborhood pixel points of the any edge pixel point are obtained, and the crack edge degree of the any edge pixel point is obtained according to the gray value difference and gradient value difference between each neighborhood pixel point. The crack edge degree of each edge pixel point is obtained, and at least one crack edge pixel point in the grayscale image is obtained according to the crack edge degree of each edge pixel point; according to each crack edge pixel point, at least one suspected crack area in the grayscale image is obtained, and the degree of chaos of each suspected crack area is obtained according to the gray value and the complexity of the gradient direction of each pixel point in each suspected crack area. The quality of any capsule is detected according to the degree of chaos of all suspected crack areas. Among them, edge pixel points are obtained through the gradient values of each pixel point in the grayscale image. However, due to the influence of the environment, the environmental light and shadow area is highly similar to the crack area, and the obtained edge pixel points also include the edge pixel points of other areas except the edge of the crack area. Therefore, the crack edge degree of each edge pixel point is obtained through the gray value and gradient value of the neighborhood pixel points of each edge pixel point to reduce the interference of the edge pixel points of other areas and obtain edge pixel points that are more in line with the crack area, that is, crack edge pixel points, so as to improve the accuracy of crack area detection; further, at least one suspected crack area is obtained according to the crack edge pixel points. Considering that the edge of the environmental light and shadow area is similar to the edge of the crack area, the suspected crack area may include the environmental light and shadow area. Therefore, the degree of chaos in each suspected crack area is obtained according to the gray value and the complexity of the gradient direction in each suspected crack area, and then it is judged whether it is a crack area according to the degree of chaos in each suspected crack area to exclude the interference of the environmental light and shadow area and improve the accuracy of crack area detection. Description of the Drawings

[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0041] Figure 1 is a flowchart of a method for detecting the quality of capsule production based on machine vision provided in Embodiment 1 of the present invention;

[0042] Figure 2 is a schematic diagram of dividing the pixel points in a window into two regions by using a region dividing line provided in the embodiments of the present invention. Detailed implementation manners

[0043] The following details the embodiments of the present disclosure, and the examples of the embodiments are shown in the drawings. The embodiments described below with reference to the drawings are exemplary and are intended to explain the present disclosure, and should not be construed as limiting the present disclosure.

[0044] It should be noted that the terms "first", "second", etc. in the specification of the present disclosure and the above drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present disclosure. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present disclosure.

[0045] To illustrate the technical solutions of the present invention, the following will be described through specific embodiments.

[0046] See Figure 1 , which is a flowchart of a method for detecting the quality of capsule production based on machine vision provided in Embodiment 1 of the present invention. As Figure 1 shown, the method may include:

[0047] Step S101, collect the surface image of any capsule, perform grayscale processing on the surface image to obtain the corresponding grayscale image, and obtain at least one edge pixel point in the grayscale image according to the gradient value of each pixel point in the grayscale image.

[0048] After capturing the surface image of any capsule, the surface image is converted into a grayscale image. Here, converting the surface image into a grayscale image is a prior art and will not be elaborated here. Since there may be noise in the grayscale image, in order to reduce the unnecessary calculations and interferences brought by the noise, bilateral filtering is used to reduce the noise. Here, using bilateral filtering to reduce the noise is a prior art and will not be elaborated here. Use OpenCV to read the denoised grayscale image to obtain the grayscale value and coordinates of each pixel point in the grayscale image, and then use the Sobel operator to obtain the gradient value and gradient direction of each pixel point in the grayscale image. Here, OpenCV and the Sobel operator are prior arts and will not be elaborated here.

[0049] When detecting the crack area of the capsule, the edge of the crack area usually has a large gradient value. However, if simply judging whether a pixel point is an edge pixel point based on the gradient value, many pixel points affected by environmental factors, that is, discontinuous noise points, will also be determined as edge pixel points. Therefore, it is also necessary to judge whether it is an edge pixel point through the continuity of the pixel points.

[0050] In the embodiment of the present invention, first, set a threshold to obtain the pixel points in the grayscale image that conform to the edge characteristics, and use these pixel points as suspected edge pixel points. Then, according to the continuity of each suspected edge pixel point, obtain the edge pixel points in the grayscale image. The specific way to obtain the edge pixel points is as follows:

[0051] According to the gradient value of each pixel point in the grayscale image, obtain the maximum gradient value, use the first preset multiple of the maximum gradient value as the gradient threshold, and use the pixel points in the grayscale image whose gradient value is greater than or equal to the gradient threshold as suspected edge pixel points;

[0052] For any suspected edge pixel point, take the any suspected edge pixel point as the center to establish a first window with a first preset size, and use the other pixel points in the first window except the any suspected edge pixel point as the first neighborhood pixel points of the any suspected edge pixel point;

[0053] Count the number of first neighborhood pixel points whose gradient value is greater than or equal to the gradient threshold. If the number is greater than the preset target number threshold, mark the any suspected edge pixel point as an edge pixel point.

[0054] In one embodiment, set the first preset multiple to There is no limitation here, and the implementer can implement according to the specific scenario. Obtain the maximum gradient value in the grayscale image, denoted as D max , then the gradient threshold is Since the edge of the crack area of the capsule usually has a large gradient value, so the gradient value in the grayscale image is greater than or equal to The corresponding pixel points are regarded as suspected edge pixel points.

[0055] Since the edge pixel points in the crack area are continuous, if there are at least two neighborhood pixel points with gradient values greater than or equal to within the eight-neighborhood range of any suspected edge pixel point, then the suspected edge pixel point is considered to be continuous. Therefore, the size of the first window is set to 3×3, which is not limited here, and the implementer can set it according to the specific scenario. For any suspected edge pixel point, a first window is established with the suspected edge pixel point as the center, and the other pixel points in the first window except the suspected edge pixel point are used as the first neighborhood pixel points of the suspected edge pixel point. The preset target quantity threshold is set to 2, which is not limited here, and the implementer can set it according to the specific scenario. If the number of first neighborhood pixel points with gradient values greater than or equal to in the first window is greater than or equal to 2, then the suspected edge pixel point is considered to be continuous, and the suspected edge pixel point is marked as an edge pixel point.

[0056] Similarly, all edge pixel points in the grayscale image are obtained.

[0057] Step S102: For any edge pixel point, obtain a preset number of neighborhood pixel points of the any edge pixel point, and obtain the crack edge degree of the any edge pixel point according to the gray value difference and gradient value difference between each neighborhood pixel point. Obtain the crack edge degree of each edge pixel point, and obtain at least one crack edge pixel point in the grayscale image according to the crack edge degree of each edge pixel point.

[0058] Due to the high similarity between the environmental light and shadow area and the crack area caused by the complex environment, among the edge pixel points obtained through step S101, there are not only crack edge pixel points, but also edge pixel points in other areas, such as edge pixel points in the reflection area and edge pixel points in the environmental interference area. Considering that there is a large gray value difference on both sides of the crack edge, and at the same time, the gray value of the pixel points at the crack edge is low, and the gradient change between the pixel points in its neighborhood has a symmetric feature, so the crack edge degree of each edge pixel point can be obtained through the gray value and gradient value of the pixel points within the neighborhood range of each edge pixel point, and then all crack edge pixel points can be obtained according to the crack edge degree of each edge pixel point, so as to reduce the interference of edge pixel points in other areas on the detection of the capsule crack area. Taking the i-th edge pixel point as an example, the method for obtaining the crack edge degree of the i-th edge pixel point is as follows:

[0059] (1) Obtain the gray feature value of the i-th edge pixel point according to the gray value difference of each pixel point within the neighborhood range of the i-th edge pixel point.

[0060] Taking any one of the edge pixel points as the center, a second window with a second preset size is established, and the other pixel points in the second window except the any one edge pixel point are used as the second neighborhood pixel points of the any one edge pixel point;

[0061] In the second window, the pixel points with gradient values greater than or equal to the gradient threshold are connected to obtain the region dividing line of the second window, and the second window is divided into at least one sub-region according to the region dividing line;

[0062] If there is more than one sub-region in the second window, the average gray value of all the second neighborhood pixel points in each sub-region is calculated respectively, the absolute value of the difference between all the average gray values is used as the gray difference degree of the second window, and the sum of the gray difference degree of the second window and the reciprocal of the gray value of the any one edge pixel point is linearly normalized to obtain the gray feature value of the any one edge pixel point.

[0063] In one embodiment, the size of the second window is set to 3×3, which is not limited here, and the implementer can set it according to the specific scenario. Since there is a large gray difference between the two sides of the crack edge, and the pixel points with gradient values greater than or equal to are more likely to be the pixel points at the crack edge, so the pixel points with gradient values greater than or equal to in the second window are connected to obtain the region dividing line of the second window, and the second window is divided into at least one sub-region according to the region dividing line. Referring to Figure 2 , which is a schematic diagram of dividing the pixel points in the second window into two regions by using the region dividing line. Figure 2 In it, Q3, Q5, and Q7 are pixel points with gradient values greater than or equal to , and the straight line connected by Q3, Q5, and Q7 is the Figure 2 gray diagonal line in, that is, the region dividing line. Q1′, Q2′, and Q4′ form one sub-region, denoted as the first sub-region, and Q6″, Q8″,

[0064] Q9″ form another sub-region, denoted as the second sub-region.

[0065] The pixel points on both sides of the edge are represented by the pixel points in the two sub-regions. Since there is a large gray difference between the two sides of the crack edge, the gray feature value of the i-th edge pixel point is obtained according to the average gray values of all the pixel points in the two sub-regions in the second window corresponding to the i-th edge pixel point. Then the calculation formula for the gray feature value of the i-th edge pixel point is:

[0066]

[0067] Among them, β idenotes the grayscale feature value of the $i$-th edge pixel point, $x$ represents the number of edge pixel points in the first sub-region, $y$ represents the number of edge pixel points in the second sub-region, $Q$ m denotes the grayscale value of the $m$-th edge pixel point in the first sub-region, $Q$ n denotes the grayscale value of the $n$-th edge pixel point in the second sub-region, $Q$ i The grayscale value of the $i$-th edge pixel point, $norm()$ represents the linear normalization function, and $||$ represents the absolute value symbol.

[0068] It should be noted that denotes the average grayscale value of all pixel points in the first sub-region, denotes the average grayscale value of all pixel points in the second sub-region, That is the grayscale difference degree of the second window. The greater the grayscale difference degree of the second window, the greater the grayscale value difference between the two sub-regions in the second window, and thus the larger the value of $\beta$ i The larger the value, the greater the possibility that the $i$-th edge pixel point is a pixel point at the crack edge; since the pixel points at the crack edge and within the crack region have lower grayscale values, so the smaller the value of $Q$ i the larger the value, the larger the value, the more the grayscale value of the $i$-th edge pixel point conforms to the pixel points at the crack edge, and thus the larger the value of $\beta$ i the larger the value, the greater the possibility that the $i$-th edge pixel point is a pixel point at the crack edge.

[0069] Specifically, if there is only one sub-region in the second window, calculate the average grayscale value of all second neighborhood pixel points in the sub-region, take the second preset multiple of the average grayscale value as the grayscale distribution feature index of the second window, and perform linear normalization on the addition result of the grayscale distribution feature index of the second window and the reciprocal of the grayscale value of any edge pixel point to obtain the grayscale feature value of any edge pixel point. That is, if Figure 2 the $Q5$, $Q7$, $Q8″$ in are gradient values greater than or equal to but since there are no pixel points in the regions included in $Q5$, $Q7$, $Q8″$, the number of pixel points in one of the sub-regions in the second window is 0, that is, there is only one sub-region in the second window, that is, a sub-region composed of $Q3$, $Q1′$, $Q2′$, $Q4′$, $Q6″$, $Q9″$, then the calculation formula for the grayscale feature value of the $i$-th edge pixel point is:

[0070]

[0071] where, $\beta$ i denotes the grayscale feature value of the $i$-th edge pixel point, $z$ represents the number of edge pixel points in the sub-region, $Q$ pIt represents the grayscale value of the p-th edge pixel in the sub-region, Q i The grayscale value of the i-th edge pixel That is the grayscale distribution feature index of the second window. norm() represents the linear normalization function, and || represents the absolute value symbol That is the second preset multiple

[0072] (2) Obtain the gradient feature value of the i-th edge pixel according to the gradient value difference between the i-th edge pixel and its adjacent pixels

[0073] Respectively obtain the left adjacent pixel and the right adjacent pixel of any edge pixel. Take the any edge pixel, the left adjacent pixel, and the right adjacent pixel as horizontal target pixels. According to the gradient values of each horizontal target pixel, construct a horizontal gradient broken line graph, where the horizontal axis of the horizontal gradient broken line graph represents the position of each horizontal target pixel in the grayscale image, and the vertical axis of the horizontal gradient broken line graph represents the gradient value of each horizontal target pixel

[0074] Respectively obtain the upper adjacent pixel and the lower adjacent pixel of any edge pixel. Take the any edge pixel, the upper adjacent pixel, and the lower adjacent pixel as vertical target pixels. According to the gradient values of each vertical target pixel, construct a vertical gradient broken line graph, where the horizontal axis of the vertical gradient broken line graph represents the position of each vertical target pixel in the grayscale image, and the vertical axis of the vertical gradient broken line graph represents the gradient value of each vertical target pixel

[0075] In the horizontal gradient broken line graph, obtain the left slope between the any edge pixel and the left adjacent pixel, and the right slope between the any edge pixel and the right adjacent pixel. Calculate the ratio between the left slope and the right slope to obtain the horizontal gradient similarity between the any edge pixel and its adjacent pixels

[0076] In the vertical gradient broken line graph, obtain the vertical gradient similarity between the any edge pixel and its adjacent pixels. Select the maximum value of the absolute value of the horizontal gradient similarity and the absolute value of the vertical gradient similarity as the gradient feature value of the any edge pixel

[0077] In one embodiment, due to the symmetry of the gradient change among the pixel points within the local range of the edge pixel points in the crack region, that is, the ratio of the slopes between the \(i\)-th edge pixel point and its adjacent pixel points is close to -1. Therefore, in the grayscale image, two adjacent pixel points of the \(i\)-th edge pixel point are obtained along the horizontal direction, namely the left adjacent pixel point and the right adjacent pixel point, and a line graph is constructed based on the \(i\)-th edge pixel point, the left adjacent pixel point, and the right adjacent pixel point, denoted as the horizontal direction gradient line graph; in the grayscale image, two adjacent pixel points of the \(i\)-th edge pixel point are obtained along the vertical direction, namely the upper adjacent pixel point and the lower adjacent pixel point, and a line graph is constructed based on the \(i\)-th edge pixel point, the upper adjacent pixel point, and the lower adjacent pixel point, denoted as the vertical direction gradient line graph, where the abscissa of the line graph represents the position of each pixel point in the grayscale image, and the ordinate represents the gradient value of each pixel point.

[0078] In the horizontal direction gradient line graph, the slopes between the \(i\)-th edge pixel point and its two adjacent pixel points are calculated respectively, and the ratio of the two slopes is used as the horizontal gradient similarity of the \(i\)-th edge pixel point; similarly, in the vertical direction gradient line graph, the vertical gradient similarity of the \(i\)-th edge pixel point is obtained. Then, based on the horizontal gradient similarity and the vertical gradient similarity, the gradient feature value of the \(i\)-th edge pixel point is obtained. The calculation formula for the gradient feature value of the \(i\)-th edge pixel point is as follows:

[0079] Ki = max(|Ki h |,|Ki v |)

[0080] where \(Ki\) represents the gradient feature value of the \(i\)-th edge pixel point, \(Ki h represents the horizontal gradient similarity between the \(i\)-th edge pixel point and its two adjacent pixel points in the horizontal direction, \(Ki v represents the vertical gradient similarity between the \(i\)-th edge pixel point and its two adjacent pixel points in the vertical direction, and max() represents the maximum value function.

[0081] It should be noted that the larger the value of |Ki h |, the more similar the slopes between the \(i\)-th edge pixel point and its two adjacent pixel points in the horizontal direction. Furthermore, the larger the value of \(Ki\), the more symmetric the gradient change between the \(i\)-th edge pixel point and the pixel points within its local range, and the greater the possibility that the \(i\)-th edge pixel point is a pixel point at the crack edge; the larger the value of |Ki v |, the more similar the slopes between the \(i\)-th edge pixel point and its two adjacent pixel points in the vertical direction. Furthermore, the larger the value of \(Ki\), the more symmetric the gradient change between the \(i\)-th edge pixel point and the pixel points within its local range, and the greater the possibility that the \(i\)-th edge pixel point is a pixel point at the crack edge.

[0082] (3) Combine the grayscale feature value and the gradient feature value of the i-th edge pixel to obtain the crack edge degree of the i-th edge pixel.

[0083] Specifically, perform linear normalization on the sum result of the grayscale feature value and the gradient feature value of any one of the edge pixels to obtain the crack edge degree of any one of the edge pixels.

[0084] In one embodiment, the calculation formula for the crack edge degree of the i-th edge pixel is:

[0085] χ i = norm(Ki + β i )

[0086] where χ i represents the crack edge degree of the i-th edge pixel, Ki represents the gradient feature value of the i-th edge pixel, β i represents the grayscale feature value of the i-th edge pixel, and norm() represents the linear normalization function.

[0087] It should be noted that the larger the value of Ki, the more symmetric the gradient change between the i-th edge pixel and the pixels within its local range. Furthermore, the larger the value of χ i , the greater the possibility that the i-th edge pixel is a pixel at the crack edge; the larger the value of β i , the more the grayscale values of the i-th edge pixel and its neighboring pixels conform to the characteristics of the pixels at the crack edge. Furthermore, the larger the value of χ i , the greater the possibility that the i-th edge pixel is a pixel at the crack edge.

[0088] Thus far, the crack edge degree of the i-th edge pixel has been obtained. Further, determine whether the i-th edge pixel is a crack edge pixel according to the crack edge degree of the i-th edge pixel. Set the preset crack edge degree threshold to 0.7, which is not limited here, and the implementer can set it according to the implementation scenario. If the crack edge degree of the i-th edge pixel is greater than or equal to 0.7, then regard the i-th edge pixel as a crack edge pixel.

[0089] Similarly, obtain the crack edge degree of each edge pixel, and then obtain all the crack edge pixels in the grayscale image.

[0090] Step S103, according to each of the crack edge pixels, obtain at least one suspected crack region in the grayscale image. According to the complexity of the grayscale value and the gradient direction of each pixel in each of the suspected crack regions, obtain the chaos degree of each of the suspected crack regions. According to the chaos degrees of all the suspected crack regions, detect the quality of any one of the capsules.

[0091] After obtaining all the crack edge pixel points through step S102, considering that there may be nearly closed graphic contours among them, at this time, it is necessary to extract the contours through a contour tracking algorithm (such as Freeman chain code) to obtain at least one regional contour. Although the contour is nearly closed, there may be small gaps. Therefore, morphological operations (dilation) are used on each regional contour to fill these gaps, so as to automatically supplement the missing pixel points, and finally obtain the suspected crack region corresponding to each regional contour. Among them, extracting the contour through a contour tracking algorithm (such as Freeman chain code) and using morphological operations (dilation) to fill the gaps are existing technologies and will not be elaborated here.

[0092] Considering that the surface of the capsule has a high smoothness, it will reflect the objects in the environment on the surface of the capsule, resulting in a high similarity between the environmental light and shadow area and the crack area. Therefore, there may still be environmental light and shadow areas in these closed areas. However, the environmental light and shadow area is affected by time, environment, etc., and the degree of chaos inside it is relatively high, that is, the number of different gray values of the pixel points in the environmental light and shadow area is large, and the gradient direction is complex and irregular. That is to say, the complexity of the gray value and gradient direction in the environmental light and shadow area is relatively high; while the gray value of the pixel points in the capsule crack area is relatively low, and due to the generation of cracks or fissures, it will not change greatly due to environmental light and shadow. Therefore, the degree of chaos in the area is relatively low, that is, the number of different gray values in the area is small, the gradient direction is simple and contains a certain rule. That is to say, the complexity of the gray value and gradient direction in the capsule crack area is relatively low. Therefore, it is necessary to analyze the complexity of the gray value and gradient direction of the pixel points in the suspected crack area to obtain the degree of chaos of the suspected crack area, and judge whether the suspected crack area is a real crack area according to the degree of chaos. Taking the jth suspected crack area as an example, the specific way to obtain the degree of chaos of the jth suspected crack area is as follows:

[0093] According to the gray value of each pixel point in any of the suspected crack areas, count the number of different gray values. According to the gradient direction of each pixel point in any of the suspected crack areas, obtain the information entropy of the gradient direction in any of the suspected crack areas, and normalize the sum of the negative reciprocal of the number of different gray values and the information entropy to obtain the degree of chaos of any of the suspected crack areas.

[0094] In an embodiment, the calculation formula for the degree of chaos of the jth suspected crack area is:

[0095]

[0096] Among them, H j represents the degree of chaos of the jth suspected crack area, and L jrepresents the number of different gray values in the j-th suspected crack region, P(F α° ) represents the probability that the pixel points with the gradient direction of α° appear in the j-th suspected crack region, and norm() represents the linear normalization function.

[0097] It should be noted that the smaller the value of L j , the fewer the number of different gray values in the j-th suspected crack region, the lower the complexity of the gray values in the j-th suspected crack region, and thus the larger the value of , the smaller the value of H j . The smaller the value of H, the smaller the possibility that the j-th suspected crack region is an environmental light and shadow region, that is, the greater the possibility that the j-th suspected crack region is a capsule crack region; -∑ α° P(F α° )log2[P(F α° )] is the information entropy of the gradient direction in the j-th suspected crack region. The larger the value of P(F α° ), the greater the probability that the pixel points with the gradient direction of α° appear in the j-th suspected crack region, that is, the larger the number of pixel points with the gradient direction of α° in the j-th suspected crack region, the lower the complexity of the gradient values in the j-th suspected crack region, and thus -∑ α° P(F α° )log2[P(F α° )] is smaller, and the smaller the value of H j . The smaller the value of H, the smaller the possibility that the j-th suspected crack region is an environmental light and shadow region, that is, the greater the possibility that the j-th suspected crack region is a capsule crack region.

[0098] Furthermore, set the preset chaos degree threshold to -0.7. If the chaos degree of the j-th suspected crack region is less than or equal to -0.7, then mark the j-th suspected crack region as a crack region.

[0099] Similarly, obtain the chaos degree of each suspected crack region in the grayscale image, and obtain all the crack regions in the grayscale image according to the chaos degree of each suspected crack region. If there are crack regions in the grayscale image, it is determined that the capsule has quality problems and mark it as a defective capsule for subsequent sorting; if there are no crack regions in the grayscale image, it is determined that the capsule has no quality problems.

[0100] In summary, the present invention captures the surface image of any capsule, performs grayscale processing on the surface image to obtain a corresponding grayscale image, and obtains at least one edge pixel point in the grayscale image according to the gradient value of each pixel point in the grayscale image; for any edge pixel point, obtains a preset number of neighborhood pixel points of the any edge pixel point, and obtains the crack edge degree of the any edge pixel point according to the gray value difference and gradient value difference between each of the neighborhood pixel points, obtains the crack edge degree of each of the edge pixel points, and obtains at least one crack edge pixel point in the grayscale image according to the crack edge degree of each of the edge pixel points; according to each of the crack edge pixel points, obtains at least one suspected crack region in the grayscale image, obtains the degree of chaos of each of the suspected crack regions according to the gray value and the complexity of the gradient direction of each pixel point in each of the suspected crack regions, and detects the quality of the any capsule according to the degree of chaos of all the suspected crack regions. Among them, edge pixel points are obtained through the gradient values of each pixel point in the grayscale image. However, due to the influence of the environment, the similarity between the environmental light and shadow region and the crack region is relatively high, and the obtained edge pixel points also include the edge pixel points of other regions except the edge of the crack region. Therefore, the crack edge degree of each edge pixel point is obtained through the gray value and gradient value of the neighborhood pixel points of each edge pixel point, so as to reduce the interference of the edge pixel points of other regions and obtain edge pixel points that are more in line with the crack region, that is, crack edge pixel points, and improve the accuracy of crack region detection; further, at least one suspected crack region is obtained according to the crack edge pixel points. Considering that the edge of the environmental light and shadow region is similar to the edge of the crack region, the suspected crack region may include the environmental light and shadow region. Therefore, the degree of chaos of each suspected crack region is obtained according to the gray value and the complexity of the gradient direction in each suspected crack region, and then it is judged whether each suspected crack region is a crack region according to the degree of chaos of each suspected crack region, so as to exclude the interference of the environmental light and shadow region and improve the accuracy of crack region detection.

[0101] Based on the same inventive concept as the above method, an embodiment of the present invention further provides a capsule production quality detection system based on machine vision, 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 methods of a capsule production quality detection method based on machine vision.

[0102] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A capsule production quality detection method based on machine vision, characterized in that: The capsule production quality detection method based on machine vision includes: Collecting a surface image of any capsule, graying the surface image to obtain a corresponding gray image, and obtaining at least one edge pixel in the gray image according to a gradient value of each pixel in the gray image; For any edge pixel point, a preset number of neighboring pixel points of the any edge pixel point is obtained, and the crack edge degree of the any edge pixel point is obtained according to the gray value difference and the gradient value difference between each of the neighboring pixel points, and the crack edge degree of each of the edge pixel points is obtained, and at least one crack edge pixel point in the grayscale image is obtained according to the crack edge degree of each of the edge pixel points; According to each of the crack edge pixels, at least one suspected crack region in the grayscale image is obtained, and according to the complexity of the grayscale value and gradient direction of each pixel in each of the suspected crack regions, the degree of disorder of each of the suspected crack regions is obtained, and according to the degree of disorder of all the suspected crack regions, the quality of any one of the capsules is detected.

2. The capsule production quality detection method based on machine vision according to claim 1 is characterized in that: The step of obtaining at least one edge pixel in the grayscale image according to the gradient value of each pixel in the grayscale image comprises: According to the gradient value of each pixel in the grayscale image, a maximum gradient value is obtained, the maximum gradient value of a first preset multiple is used as a gradient threshold, and the pixel points in the grayscale image corresponding to the gradient value greater than or equal to the gradient threshold are used as suspected edge pixels; For any suspected edge pixel point, a first window of a first preset size is established with the any suspected edge pixel point as the center, and other pixels in the first window except the any suspected edge pixel point are used as first neighborhood pixels of the any suspected edge pixel point; The number of first neighborhood pixel points whose gradient values ​​are greater than or equal to the gradient threshold is counted, and if the number is greater than a preset target number threshold, any suspected edge pixel point is marked as an edge pixel point.

3. The capsule production quality detection method based on machine vision according to claim 2 is characterized in that: The step of acquiring a preset number of neighboring pixel points of any edge pixel point, and obtaining the crack edge degree of any edge pixel point according to the gray value difference and gradient value difference between each of the neighboring pixel points, comprises: A second window of a second preset size is established with the any edge pixel point as the center, and other pixel points in the second window except the any edge pixel point are used as second neighborhood pixel points of the any edge pixel point; In the second window, connecting pixel points whose gradient values ​​are greater than or equal to the gradient threshold to obtain a region dividing line of the second window, and dividing the second window into at least one sub-region according to the region dividing line; If there is only one sub-region in the second window, the grayscale value mean of all second neighborhood pixels in the sub-region is calculated, the grayscale value mean of the second preset multiple is used as the grayscale distribution characteristic index of the second window, and the grayscale distribution characteristic index of the second window and the inverse of the grayscale value of any edge pixel are linearly normalized to obtain the grayscale characteristic value of any edge pixel; If there is more than one sub-region in the second window, the grayscale value means of all second neighborhood pixels in each of the sub-regions are calculated respectively, the absolute value of the difference between all the grayscale value means is used as the grayscale difference of the second window, and the addition result of the grayscale difference of the second window and the reciprocal of the grayscale value of any edge pixel is linearly normalized to obtain the grayscale feature value of any edge pixel; In the grayscale image, according to the difference in gradient values ​​between any edge pixel point and its adjacent pixel points, a gradient characteristic value of any edge pixel point is obtained; The addition result of the grayscale eigenvalue and the gradient eigenvalue of any edge pixel point is linearly normalized to obtain the crack edge degree of any edge pixel point.

4. The capsule production quality detection method based on machine vision according to claim 3 is characterized in that: The step of obtaining the gradient characteristic value of any edge pixel point according to the gradient value difference between any edge pixel point and its adjacent pixel points includes: Respectively obtain the left adjacent pixel point and the right adjacent pixel point of any edge pixel point, take the any edge pixel point, the left adjacent pixel point and the right adjacent pixel point as horizontal target pixel points, and construct a horizontal gradient line graph according to the gradient value of each horizontal target pixel point, wherein the horizontal axis of the horizontal gradient line graph represents the position of each horizontal target pixel point in the grayscale image, and the vertical axis of the horizontal gradient line graph represents the gradient value of each horizontal target pixel point; Respectively obtain the upper adjacent pixel point and the lower adjacent pixel point of any edge pixel point, take the any edge pixel point, the upper adjacent pixel point and the lower adjacent pixel point as vertical target pixel points, and construct a vertical gradient line graph according to the gradient value of each vertical target pixel point, wherein the horizontal axis of the vertical gradient line graph represents the position of each vertical target pixel point in the grayscale image, and the vertical axis of the vertical gradient line graph represents the gradient value of each vertical target pixel point; In the horizontal gradient line graph, the left slope between any edge pixel point and the left adjacent pixel point, and the right slope between any edge pixel point and the right adjacent pixel point are obtained, and the ratio between the left slope and the right slope is calculated to obtain the horizontal gradient similarity between any edge pixel point and its adjacent pixel point; In the vertical gradient line graph, the vertical gradient similarity between any edge pixel point and its adjacent pixel point is obtained, and the maximum value between the absolute value of the horizontal gradient similarity and the absolute value of the vertical gradient similarity is selected as the gradient feature value of any edge pixel point.

5. The capsule production quality detection method based on machine vision according to claim 1, characterized in that: The step of obtaining at least one crack edge pixel point in the grayscale image according to the crack edge degree of each edge pixel point comprises: For any edge pixel point, if the crack edge degree of any edge pixel point is greater than or equal to a preset crack edge degree threshold, then the any edge pixel point is taken as a crack edge pixel point.

6. The capsule production quality detection method based on machine vision according to claim 1, characterized in that: The step of obtaining the degree of disorder of each suspected crack region according to the complexity of the gray value and gradient direction of each pixel point in each suspected crack region comprises: For any suspected crack area, according to the grayscale value of each pixel in the suspected crack area, the number of different grayscale values ​​is counted, and according to the gradient direction of each pixel in the suspected crack area, the information entropy of the gradient direction in the suspected crack area is obtained. The inverse of the reciprocal of the number of different grayscale values ​​and the sum of the information entropy are normalized to obtain the degree of chaos in the suspected crack area.

7. The capsule production quality detection method based on machine vision according to claim 1, characterized in that: The method of detecting the quality of any capsule according to the disorder degree of all suspected crack areas comprises: For any suspected crack region, if the disorder degree of any suspected crack region is less than or equal to a preset disorder degree threshold, then mark any suspected crack region as a crack region; If there is a crack area in the grayscale image, it is determined that the capsule corresponding to the grayscale image has a quality problem; If there is no crack region in the grayscale image, it is determined that the capsule corresponding to the grayscale image has no quality problem.

8. The capsule production quality detection method based on machine vision according to claim 1, characterized in that: The step of obtaining at least one suspected crack region in the grayscale image according to each of the crack edge pixels includes: Extracting contours using a Freeman chain code according to all crack edge pixels in the grayscale image to obtain at least one regional contour in the grayscale image; For any region contour, a morphological dilation operation is used to obtain a suspected crack region corresponding to the any region contour.

9. A capsule production quality inspection system based on machine vision, 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, the steps of the capsule production quality detection method based on machine vision as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Pig ear tag automatic identification method and system based on high-resolution image

    CN120318867A

  • Crushing particle size measuring method for runway long-wave uneven resonance crushing

    CN120747150A

  • Tea wall breaking rate detection method, equipment and system

    CN120807490A

  • Brain small blood vessel image recognition and analysis method for cognitive function impairment analysis

    CN121170859A

  • Visual identification method and system for grinding quality of R corner of edge of cover plate glass

    CN121258944A