Intelligent distinguishing system for surface defects of benzalkonium chloride disinfectant bottle
By using boundary characterization curves and normal grayscale profile analysis in the surface inspection of benzalkonium chloride disinfectant bottles, chemical deposition and mechanical damage can be distinguished, solving the misjudgment problem in visual inspection and achieving efficient defect identification and localization.
Patent Information
- Application Number
- CN202511281248.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-12-19
AI Technical Summary
Existing visual inspection technologies struggle to distinguish between chemical deposits and mechanical damage on the surface of benzalkonium chloride disinfectant bottles, leading to misjudgments or incorrect assessments and affecting the accuracy of bottle quality evaluation.
The data acquisition module acquires images of the bottle, and candidate points on the shoulder are screened through boundary characterization curves. A local coordinate system is established for normal grayscale profile analysis, and intensity geometric correlation index and width asymmetry index are calculated. The defect results are output by fusing the discrimination index and the defects are output by combining the brightness peak location.
It effectively distinguishes liquid film artifacts from real scratches, reduces false positives and false negatives, improves the reliability and automation level of pharmaceutical glass bottle quality inspection, and ensures production safety and consistency.
Smart Images

Figure CN121169853A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of defect detection, more particularly, it relates to a benzalkonium chloride disinfectant bottle surface defect intelligent discrimination system. BACKGROUND
[0002] Benzalkonium chloride is a kind of cationic surfactant, which is widely used as an effective ingredient in disinfectant products. In order to ensure the safety and stability of the pharmaceutical glass bottle in the process of high-speed filling, transportation and labeling, the existing process generally uses hot end SnO2 treatment and cold end wax coating on the surface of the bottle. The former improves the wear resistance and strength of the bottle body, and the latter improves the lubricity and labeling performance. However, this treatment changes the optical reflection and scattering properties of the bottle surface, making it more likely to show irregular light bands or color spots under special lighting conditions.
[0003] In the production environment of filling benzalkonium chloride disinfectant, after the liquid medicine is left in the bottle neck and shoulder area, it will form a ring or half-moon shaped deposition mark at the contact line position during the evaporation process. This deposition is caused by the edge effect during solution drying, especially the benzalkonium chloride molecules which are easily adsorbed on the glass surface, leaving a very thin film layer. The deposition mark is consistent with the geometric curvature of the bottle body, often showing an arc-shaped dark or bright band along the shoulder.
[0004] Industrial visual inspection is generally carried out under white light conditions, but in order to improve the sensitivity to small cracks or contamination, UVA (365nm) illumination is often introduced. UVA can significantly enhance the development effect of organic residues, making the benzalkonium chloride deposition mark more clearly shown in the image. However, this enhancement effect also makes its appearance very similar to real scratches and cracks. Since the detection results are difficult to distinguish between chemical deposition and mechanical damage, false positives or false negatives often occur, affecting the accurate evaluation of the quality of the bottle body. SUMMARY
[0005] The present application provides a benzalkonium chloride disinfectant bottle surface defect intelligent discrimination system to solve the technical problems raised in the background art.
[0006] The present application provides a benzalkonium chloride disinfectant bottle surface defect intelligent discrimination system, which comprises: A data acquisition module acquires the surface image of the disinfectant bottle, extracts the bottle region from the surface image and generates the bottle contour, and determines the outer boundary of the bottle based on the bottle contour to generate a boundary representation curve; A candidate point screening module screens the shoulder candidate points based on the boundary representation curve; A profile generation module establishes a local coordinate system at the shoulder candidate point, samples the surface image at equal intervals along the inside normal, and obtains the corresponding normal gray profile; wherein the inside normal points to the inside of the bottle contour; The index calculation module performs extreme point analysis on the normal gray profile, locates the light peak, the upstream stagnation point and the downstream stagnation point respectively, and further calculates the intensity geometric correlation index and the width asymmetry index; The defect recognition module fuses and calculates the intensity geometric correlation index and the width asymmetry index to obtain a discrimination index, outputs a defect discrimination result according to the discrimination index, and outputs a defect based on the light peak positioning.
[0007] Further, a surface image of the disinfectant liquid bottle is acquired, a bottle region is extracted from the surface image and a bottle contour is generated, an outer boundary of the bottle is determined based on the bottle contour to generate a boundary representation curve, The surface image is denoised by using a Gaussian smoothing algorithm to obtain a denoised image; The gray value of the denoised image is converted to the interval of 0 to 1 by using a linear normalization algorithm to obtain a standardized image; After morphological gradient processing is performed on the standardized image, connected domain analysis is applied, all connected clusters composed of non-zero pixels are screened out, and the connected cluster with the largest number of pixels is selected as the bottle region; The boundary pixels of the bottle region are extracted to obtain the outer boundary of the bottle; For the pixels of the outer boundary of the bottle, starting from any pixel, the cumulative arc length of each pixel point is calculated by accumulating the Euclidean distance between adjacent two pixels in segments; the pixel point coordinates of the outer boundary of the bottle are interpolated based on the cumulative arc length as the independent variable to obtain the boundary representation curve.
[0008] Further, the shoulder candidate points are selected based on the boundary representation curve, including: The area of the enclosed region of the boundary representation curve is calculated by using a polygon area algorithm; The center of the enclosed region of the boundary representation curve is calculated by using a polygon centroid algorithm; The second-order central moment matrix of the enclosed region of the boundary representation curve is calculated, the second-order central moment matrix includes the second-order x-direction central moment, the second-order y-direction central moment and the mixed second-order central moment; wherein the second-order x-direction central moment, the second-order y-direction central moment and the mixed second-order central moment are calculated based on the area of the enclosed region and the center of the enclosed region; The second-order central moment matrix is subjected to eigenvalue decomposition, and the feature vector corresponding to the maximum eigenvalue is selected as the shape principal axis unit vector; For each point on the boundary representation curve, the first derivative of the point in the direction of the shape principal axis unit vector is calculated to obtain the first derivative vector containing the horizontal coordinate derivative and the vertical coordinate derivative, and the horizontal coordinate derivative and the vertical coordinate derivative of the first derivative vector are divided by the modulus of the first derivative vector to obtain the tangent unit vector; For each point on the boundary representation curve, a horizontal difference between the horizontal coordinate of the point and the horizontal coordinate of the center of the surrounding area, and a vertical difference between the vertical coordinate of the point and the vertical coordinate of the center of the surrounding area are calculated; the horizontal difference is multiplied by the horizontal coordinate component of the shape principal axis unit vector to obtain a first component product; the vertical difference is multiplied by the vertical coordinate component of the shape principal axis unit vector to obtain a second component product; the first component product and the second component product are added to obtain an axial coordinate corresponding to the point; According to the horizontal difference and the vertical difference of each point on the boundary representation curve, a first vector is formed; the product of the axial coordinate of the point and the shape principal axis unit vector is calculated to obtain a second vector; the modulus of the difference vector between the first vector and the second vector is taken as the radius of the corresponding point; The axial coordinates of each point on the boundary representation curve are divided into monotonic intervals that are monotonically increasing or monotonically decreasing; within each monotonic interval, a functional relationship between the axial coordinate and the corresponding radius is established by an interpolation method to obtain a radius-axial function; For each point on the radius-axial function, a first derivative in the axial coordinate direction is calculated, and then a second derivative in the axial coordinate direction is calculated; from all points on the radius-axial function, a feature point is selected, which satisfies that the second derivative is equal to zero and the signs of the second derivatives of adjacent points before and after the point are opposite; the axial coordinates of all feature points are merged to form an axial turning candidate set; For each point on the boundary representation curve, a first derivative and a second derivative of the point are obtained; The absolute value of the product of the first derivative of the horizontal coordinate of the point and the second derivative of the vertical coordinate of the point, minus the product of the first derivative of the vertical coordinate of the point and the second derivative of the horizontal coordinate of the point, is taken as the numerator; The cubic root of the sum of the squares of the first derivative of the horizontal coordinate of the point and the first derivative of the vertical coordinate of the point is taken as the denominator; The numerator is divided by the denominator to obtain the curvature of the point; For the curvature of the point, a first derivative in the direction of the shape principal axis unit vector of the boundary representation curve is calculated to obtain a corresponding curvature change rate; According to the axial turning candidate set, a target range of points on the boundary representation curve corresponding to the axial coordinates belonging to the axial turning candidate set is determined; within the target range, a point with a local maximum absolute value of the curvature change rate is selected to obtain a curvature change rate local maximum point set; wherein the local maximum value is the absolute value of the curvature change rate of the point, which is greater than the absolute values of the curvature change rates of the corresponding adjacent two points before and after the point; From the curvature change rate local maximum point set, a candidate point is selected, which satisfies that the axial coordinate of the point belongs to the axial turning candidate set; The arc length position of each candidate point on the boundary representation curve is marked, and a shoulder candidate point set is formed by aggregation.
[0009] Further, a local coordinate system is established at the shoulder candidate point, the surface image is sampled at equal intervals along the inside normal direction to obtain a corresponding normal gray profile, including: For each candidate point in the shoulder candidate point set, boundary points corresponding to a predetermined arc length before and after the arc length position of the candidate point are taken, and the coordinate difference values of the corresponding boundary points are calculated to obtain a difference vector; the horizontal coordinate component and the vertical coordinate component of the difference vector are divided by the modulus of the difference vector to obtain a unit tangent vector; The unit tangent vector is rotated by ninety degrees in the opposite direction of the shape principal axis unit vector to obtain an initial normal vector; a pixel length is taken as a small offset, and an offset point obtained by offsetting the boundary point corresponding to the candidate point by a small offset along the opposite direction of the initial normal vector is calculated; If the offset point does not belong to the bottle body region, the inside normal vector is the opposite direction of the initial normal vector; If the offset point belongs to the bottle body region, the inside normal vector is the initial normal vector; A local coordinate mapping function is established with the boundary point corresponding to the candidate point as the base point, the unit tangent vector as the tangent coordinate axis, and the inside normal vector as the normal coordinate axis; With the boundary point corresponding to the candidate point as the starting point, the normal distance is gradually increased along the inside normal direction by a small offset until the normal distance is not in the bottle body region, and the maximum sampling depth is obtained by taking the normal distance in the bottle body region before; Starting from a normal distance of zero along the inside normal direction, the normal distance values are taken in turn by a small offset until the maximum sampling depth is reached; for each normal distance value, the corresponding image coordinates are obtained through the local coordinate mapping function, and the gray value of the image coordinates on the normalized image after morphological gradient processing is calculated using the bilinear interpolation method; the gray values are sorted in ascending order according to the normal distance to obtain the normal gray profile corresponding to the candidate point.
[0010] Further, the extreme point analysis is performed on the normal gray profile to locate the bright peak, the upstream stagnation point and the downstream stagnation point, including: A one-dimensional Gaussian convolution algorithm is used to denoise and smooth the normal gray profile to obtain a standard profile; The first and second derivatives of each gray value in the standard profile are calculated using the central difference method; In the standard profile, the candidate bright peak is selected, which satisfies: the first derivative of the previous gray value of the gray value is greater than 0, the first derivative of the next gray value of the gray value is less than 0, and the second derivative of the gray value is less than 0; If the number of candidate bright peaks is greater than 1, the maximum gray value in the candidate bright peak is selected as the bright peak; If the number of candidate bright peaks is equal to 1, the candidate bright peak is taken as the bright peak; The normal distance corresponding to the bright peak is taken as a target distance, a normal distance interval from zero to the target distance minus a small offset is taken as a first search interval, and each normal distance in the first search interval is traversed in descending order: if the first-order derivative of the normal distance is equal to 0, or the product of the first-order derivatives of the previous normal distance and the next normal distance of the normal distance is less than 0, and the second-order derivative of the normal distance is greater than or equal to 0, the corresponding normal distance is taken as an upstream stationary point. The normal distance corresponding to the bright peak is taken as a target distance, a normal distance interval from the target distance plus a small offset to the maximum sampling depth is taken as a second search interval, and each normal distance in the second search interval is traversed in ascending order: if the first-order derivative at the normal distance is equal to 0, or the product of the first-order derivatives of the previous normal distance and the next normal distance of the normal distance is less than or equal to 0, and the second-order derivative at the normal distance is greater than or equal to 0, the corresponding normal distance is taken as a downstream stationary point.
[0011] Further, the intensity-geometry correlation index and the width asymmetry index are calculated, including: A difference profile of the standard profile and the normal gray profile is calculated. The gray value difference in the difference profile and the corresponding normal distance are taken as the dependent variable and the independent variable respectively to construct a relative gray function. The normal distance corresponding to the upstream stationary point is taken as the integral starting point, the normal distance corresponding to the downstream stationary point is taken as the integral termination point, and an integral interval is obtained; for the normal distance in the integral interval, the normal distance corresponding to the bright peak is subtracted to obtain the corresponding relative normal distance; the product of each relative normal distance in the integral interval and the corresponding relative gray function value is calculated to obtain the corresponding coupling term; the integral interval is divided into a plurality of discrete subintervals according to a small offset; the average value of the coupling terms at both ends of the discrete subintervals is calculated, and the product of the average value and the small offset is taken as the corresponding integral value. The integral values of all discrete subintervals are summed to obtain the intensity-geometry correlation index. The normal distance corresponding to the downstream stationary point is subtracted from the normal distance corresponding to the bright peak to obtain a downstream half-width. The normal distance corresponding to the bright peak is subtracted from the normal distance corresponding to the upstream stationary point to obtain an upstream half-width. The difference between the downstream half-width and the upstream half-width is taken as the width asymmetry index.
[0012] Further, the intensity-geometry correlation index and the width asymmetry index are fused to obtain a discrimination index, including: The product of the intensity-geometry correlation index and the width asymmetry index is taken as the discrimination index.
[0013] Further, a defect discrimination result is output according to the discrimination index, and a defect is output based on the bright peak positioning, including: If the discrimination index is negative, it is determined that the defect of the corresponding candidate point is a liquid film artifact; If the discrimination index is non-negative, it is determined that the defect of the corresponding candidate point is a real scratch; In response to the real scratch, the bright peak pixel coordinates are calculated by a local mapping formula as follows: Bright peak pixel coordinates = boundary base point + tangent parameter × unit tangent vector - normal parameter × inside normal Wherein, the boundary base point is the cumulative arc length of the candidate point at the boundary representation curve, the normal parameter is the normal distance corresponding to the bright peak, and the tangent parameter is 0. Taking the tangent parameter 0 as the starting point, search is performed in the positive tangent direction with increasing tangent parameter and in the negative tangent direction with decreasing tangent parameter, and the search step is a small offset. For each search tangent parameter, the corresponding normal parameter search range is calculated by the local mapping formula, and the normal parameters in the normal parameter search range are determined to satisfy the target condition: The first-order derivative of the normalized image processed by the morphological gradient at the pixel corresponding to the normal parameter is zero along the inside normal direction, and the second-order derivative along the inside normal direction is negative. When there is no normal parameter satisfying the target condition after searching in the positive tangent direction or the negative tangent direction, the search in the corresponding tangent direction is stopped, and the last tangent parameter in the corresponding direction is marked as the positive termination tangent parameter and the negative termination tangent parameter respectively, to obtain the tangent effective interval. All tangent parameters and corresponding normal parameters in the tangent effective interval that satisfy the target condition are combined, converted into pixel coordinates corresponding to the normalized image processed by the morphological gradient by the local mapping formula, and the pixel coordinates are sequentially connected in ascending order of tangent parameter to form a continuous bright band center line. The normal distance corresponding to the upstream stationary point is taken as the lower bound of the normal width, and the normal distance corresponding to the downstream stationary point is taken as the upper bound of the normal width to form a normal interval. All tangent parameters in the tangent effective interval and all normal parameters in the normal interval are taken. The tangent parameters and corresponding normal parameters are converted into pixel coordinates corresponding to the normalized image processed by the morphological gradient by the local mapping formula, the pixel coordinates are marked as 1, and the non-pixel coordinates are marked as 0 to obtain a fine band mask. Output the defect, which includes: bright peak pixel coordinates, bright band center line and fine band mask.
[0014] The beneficial effects of the present application are that: by constructing a complete process from bottle body area extraction, shoulder candidate point screening, normal section sampling, extreme point analysis to discriminant index fusion, the liquid film artifact formed by benzalkonium chloride deposition and the real scratch on the bottle surface can be effectively distinguished, and the misjudgment and missed judgment in visual detection can be significantly reduced; at the same time, the system still maintains stable discrimination ability under different lighting conditions, can realize positioning of the defect position, boundary and center line, and improves the reliability and automation level of the quality inspection of medicinal glass bottles, so as to ensure the safety and consistency of the production link. BRIEF DESCRIPTION OF DRAWINGS
[0015] Fig. 1 is a module diagram of the present application; Fig. 2 is a flowchart of the present application. DETAILED DESCRIPTION
[0016] The subject matter described herein will now be discussed with reference to example implementations. It should be understood that the discussion of these implementations is merely meant to provide a better understanding of the subject matter described herein and can be changed in function and arrangement without departing from the scope of the present disclosure. Various processes or components can be omitted, substituted, or added according to desired implementations. Additionally, features described with respect to some examples can be combined in other examples.
[0017] As shown in Figs. 1-2 , a benzalkonium chloride disinfectant bottle surface defect intelligent discrimination system comprises: a data acquisition module, which acquires a surface image of a disinfectant bottle, extracts a bottle body area from the surface image and generates a bottle body contour, and determines a bottle body outer boundary based on the bottle body contour to generate a boundary representation curve; a candidate point screening module, which screens shoulder candidate points based on the boundary representation curve; a section generation module, which establishes a local coordinate system at the shoulder candidate point, samples the surface image at equal intervals along an inside normal to obtain a corresponding normal gray section; wherein the inside normal points to the inside of the bottle body contour; an index calculation module, which performs extreme point analysis on the normal gray section, respectively locates a bright peak, an upstream stagnation point and a downstream stagnation point, and further calculates a strength geometric correlation index and a width asymmetry index; a defect recognition module, which performs fusion calculation on the strength geometric correlation index and the width asymmetry index to obtain a discriminant index, outputs a defect discrimination result according to the discriminant index, and outputs a defect based on the bright peak positioning.
[0018] In an embodiment of the present application, a surface image of a disinfectant bottle is acquired, a bottle body area is extracted from the surface image and a bottle body contour is generated, a bottle body outer boundary is determined based on the bottle body contour to generate a boundary representation curve, The Gaussian smoothing algorithm is used to denoise the surface image to obtain a denoised image. The linear normalization algorithm is used to convert the gray value of the denoised image to the interval of 0 to 1 to obtain a standardized image. In detail, when shooting the surface image of the disinfectant bottle, it is easy to be affected by environmental stray light, image sensor self-interference and other factors, and high-frequency noise is generated. These noises can cause irregular fluctuations in the gray value of the image, interfering with the accuracy of subsequent bottle region extraction and contour recognition. By processing the surface image through the Gaussian smoothing algorithm, the transition of the image gray value can be smoother, effectively suppressing the above-mentioned high-frequency noise and retaining the key information of the bottle surface. Under different shooting scenes, there are differences in light intensity, camera exposure parameters, etc., which can cause the gray value range of the denoised image to be inconsistent. If the subsequent processing is directly based on the original gray value, the same feature may have different gray value performances in different images due to different gray value references, affecting the consistency of the analysis results. Using the linear normalization algorithm to convert the gray value to the interval of 0 to 1 can eliminate the influence of shooting conditions on the gray value.
[0019] The morphological gradient of the standardized image is calculated; wherein the morphological gradient is obtained by taking the difference value after respectively performing dilation operation and erosion operation on the standardized image, and the structure elements of the dilation operation and the erosion operation are both 3x3 squares; In detail, the morphological gradient is used to highlight the edge structure in the image. The dilation operation can expand the bright areas in the image, and the erosion operation can reduce the bright areas in the image. Taking the difference value after performing the two operations on the standardized image can strengthen the boundary between bright and dark areas, making the bottle contour edge clearer. A 3x3 square is selected as the structure element because this size can effectively highlight the bottle contour edge, avoid the loss of edge details due to a too large structure element, or the inability to fully suppress small noise and form a complete edge due to a too small structure element, and balance the edge detection accuracy and anti-interference ability.
[0020] The standardized image processed by the morphological gradient is subjected to connected domain analysis, and all connected clusters composed of non-zero pixels are screened out, and the connected cluster with the largest number of pixels is selected as the bottle region. In detail, in the standardized image processed by the morphological gradient, non-zero pixels not only include pixels related to the bottle contour and bottle region, but also may include pixels of interference regions such as impurities in the background and bottle labels. Connected domain refers to a set of adjacent non-zero pixels in the image. Since the bottle is the main target in the image, the area of the connected cluster of its corresponding non-zero pixels is usually much larger than that of the connected cluster of interference regions such as background impurities and labels. By screening the connected cluster with the largest number of pixels from all non-zero pixel connected clusters as the bottle region, background impurities, labels and other irrelevant interference regions can be excluded.
[0021] extracting the boundary pixels of the bottle body region to obtain a bottle body outer boundary; In detail, the boundary pixels of the bottle body region are the boundary pixels between the bottle body region and the background region, and the collection of these pixels directly reflects the external contour shape of the bottle body. Extracting the boundary pixels can clearly define the contour range of the bottle body, focus the subsequent analysis on the contour structure of the bottle body, and avoid the redundancy of the analysis object caused by including the internal region of the bottle body.
[0022] For the pixels of the bottle body outer boundary, starting from any pixel, the cumulative arc length of each pixel point is calculated by accumulating the Euclidean distance between two adjacent pixels in each section; and the coordinates of the pixels of the bottle body outer boundary are interpolated based on the cumulative arc length as the independent variable to obtain a boundary representation curve.
[0023] It should be noted that the pixels of the bottle body outer boundary are distributed discretely, and when subsequent geometric analysis (such as curvature calculation and candidate point screening) is directly based on discrete pixels, it is difficult to accurately describe the position relationship of the pixels on the contour and the continuous shape of the contour. By accumulating the Euclidean distance between adjacent pixels in each section to calculate the cumulative arc length, a parameter that can accurately describe the relative position of each boundary pixel on the contour can be established, which is not affected by the discreteness of the pixel arrangement and can better reflect the length characteristics of the contour. Interpolating the coordinates of the boundary pixels based on the cumulative arc length as the independent variable can convert the discrete boundary pixels into a continuous boundary representation curve, and the continuous curve can support mathematical operations such as derivative and curvature.
[0024] In an embodiment of the present application, the shoulder candidate points are screened based on the boundary representation curve, comprising: calculating the area of the enclosed region of the boundary representation curve using a polygon area algorithm; In detail, the area of the enclosed region of different specifications of the disinfectant bottle is different, and if the feature parameters are directly analyzed without normalization, the parameter reference will not be uniform due to the different sizes of the bottle body, which will affect the positioning accuracy of the shoulder.
[0025] calculating the center of the enclosed region of the boundary representation curve using a polygon centroid algorithm; In detail, the center of the enclosed region is a reference point for measuring the relative positions of all points on the boundary representation curve.
[0026] calculating the second-order central moment matrix of the enclosed region of the boundary representation curve, the second-order central moment matrix including a second-order x-direction central moment, a second-order y-direction central moment, and a mixed second-order central moment; wherein the second-order x-direction central moment, the second-order y-direction central moment, and the mixed second-order central moment are calculated based on the area of the enclosed region and the center of the enclosed region; In detail, the second-order central moment matrix is a core tool for quantifying the shape distribution characteristics of the bottle body surrounding area. Among them, the second-order x-direction central moment reflects the distribution dispersion degree of the boundary points in the horizontal direction relative to the center of the surrounding area, the second-order y-direction central moment reflects the distribution dispersion degree of the boundary points in the vertical direction, and the mixed second-order central moment reflects the distribution correlation degree of the boundary points in the horizontal and vertical directions. The second-order central moment matrix can completely describe the distribution characteristics of the bottle body shape.
[0027] Traverse each point on the boundary representation curve, calculate the square of the difference between the horizontal coordinate of the point and the horizontal coordinate of the center of the surrounding area, and then multiply it by the infinitesimal area formed with the adjacent point to obtain a first local result; sum all the first local results and divide by the area of the surrounding area to obtain the second-order x-direction central moment; In detail, the calculation of the second-order x-direction central moment by traversing the boundary points is a specific quantification of the distribution dispersion degree of the boundary points in the horizontal direction. By calculating the square of the horizontal distance deviation of each boundary point from the center of the surrounding area, and combining the weighted summation of the infinitesimal area and normalizing by the area of the surrounding area, the distribution concentration or dispersion degree of the boundary points in the horizontal direction can be reflected.
[0028] Traverse each point on the boundary representation curve, calculate the square of the difference between the vertical coordinate of the point and the vertical coordinate of the center of the surrounding area, and then multiply it by the infinitesimal area formed with the adjacent point to obtain a second local result; sum all the second local results and divide by the area of the surrounding area to obtain the second-order y-direction central moment; In detail, the calculation of the second-order y-direction central moment by traversing the boundary points is to quantify the distribution dispersion degree of the boundary points in the vertical direction. By calculating the square of the vertical distance deviation of each boundary point from the center of the surrounding area, combining the weighted summation of the infinitesimal area and normalizing, the distribution rule of the boundary points in the vertical direction can be captured.
[0029] Traverse each point on the boundary representation curve, calculate the vertical difference between the vertical coordinate of the point and the vertical coordinate of the center of the surrounding area, and the horizontal difference between the horizontal coordinate of the point and the horizontal coordinate of the center of the surrounding area; multiply the vertical difference and the horizontal difference by the infinitesimal area formed with the adjacent point to obtain a third local result; sum all the third local results and divide by the area of the surrounding area to obtain the mixed second-order central moment; In detail, the calculation of the mixed second-order central moment by traversing the boundary points is used to quantify the correlation degree of the distribution of the boundary points in the horizontal and vertical directions. By calculating the product of the horizontal and vertical distance deviations of each boundary point from the center of the surrounding area, combining the weighted summation of the infinitesimal area and normalizing, it can be reflected whether there is a trend of concentrated distribution of the boundary points along a certain diagonal direction.
[0030] wherein the infinitesimal area is an intermediate quantity of the polygon centroid algorithm; Perform eigenvalue decomposition on the second-order central moment matrix to select the eigenvector corresponding to the maximum eigenvalue as the shape principal axis unit vector; In detail, the shape principal axis unit vector is a reference for determining the main extension direction of the bottle body. The eigenvalue decomposition can extract the direction that best represents the extension trend of the bottle body from the shape distribution described by the second-order central moment matrix. The direction corresponding to the maximum eigenvalue is the direction in which the boundary point distribution is most dispersed, i.e., the main extension direction of the bottle body.
[0031] For each point on the boundary representation curve, the first derivative of the point in the direction of the shape principal axis unit vector is calculated to obtain a first derivative vector containing the horizontal coordinate derivative and the vertical coordinate derivative. The horizontal coordinate derivative and the vertical coordinate derivative of the first derivative vector are divided by the modulus of the first derivative vector to obtain the tangent unit vector. In detail, the tangent unit vector is used to establish a local tangent reference for the boundary point. The first derivative vector reflects the trend of the change of the boundary point in the direction of the principal axis. After normalization, the influence of the length difference of the vector is eliminated, and only the direction information is retained.
[0032] For each point on the boundary representation curve, the horizontal difference between the horizontal coordinate of the point and the horizontal coordinate of the center of the surrounding area, and the vertical difference between the vertical coordinate of the point and the vertical coordinate of the center of the surrounding area are calculated. The horizontal difference is multiplied by the horizontal component of the shape principal axis unit vector to obtain a first component product. The vertical difference is multiplied by the vertical component of the shape principal axis unit vector to obtain a second component product. The first component product and the second component product are added to obtain the axial coordinate corresponding to the point. In detail, the axial coordinate converts the two-dimensional position of the boundary point into a one-dimensional position in the direction of the principal axis. By quantifying the projection distance of the boundary point in the direction of the principal axis as the axial coordinate, the analysis of the complex two-dimensional boundary shape can be simplified to the analysis of the one-dimensional distribution in the direction of the principal axis. Thus, the position rule of the boundary point along the main extension direction of the bottle body is clearly presented, for example, the position change of the bottle body in the direction of the principal axis from the bottom to the top.
[0033] According to the horizontal difference and the vertical difference of each point on the boundary representation curve, a first vector is formed. The product of the axial coordinate of the point and the shape principal axis unit vector is calculated to obtain a second vector (the horizontal coordinate component of the second vector is the axial coordinate multiplied by the horizontal coordinate component of the shape principal axis unit vector, and the vertical coordinate component is the axial coordinate multiplied by the vertical coordinate component of the shape principal axis unit vector). The modulus of the difference vector obtained by subtracting the second vector from the first vector is taken as the radius of the corresponding point. In detail, the radius is a parameter for quantifying the perpendicular distance of the boundary point to the shape principal axis. In combination with the axial coordinate, the radius can construct a one-dimensional correspondence relationship between the axial coordinate and the radius, which can intuitively reflect the radial size change of the bottle body in the direction perpendicular to the principal axis. The radius of the shoulder of the bottle body, which is a transition region from the bottle body to the neck, will change significantly.
[0034] The axial coordinates of each point on the boundary representation curve are divided into monotonic intervals which are monotonically increasing or monotonically decreasing; in each monotonic interval, a function relationship between the axial coordinate and the corresponding radius is established by interpolation method to obtain a radius axial function; In detail, the radius axial function is used to realize continuous analysis of the radial dimension change. The monotonic interval of the axial coordinate ensures that the corresponding relationship between the axial coordinate and the radius in this range is continuous and has no reverse, and after the discrete radius and axial coordinate data are converted into a continuous function by interpolation method, the trend of the radius change (such as increasing, decreasing, turning) can be captured by mathematical operations such as derivation.
[0035] The first derivative of each point on the radius axial function in the axial coordinate direction is calculated, and then the second derivative of the first derivative in the axial coordinate direction is calculated; from all points on the radius axial function, a feature point is selected, which satisfies that the second derivative is equal to zero and the signs of the second derivatives of the adjacent points before and after the point are opposite; the axial coordinates of all feature points are merged to form an axial turning candidate set; In detail, the axial turning candidate set is used to preliminarily lock the potential position of the shoulder. The first derivative reflects the change rate of the radius, and the second derivative reflects the change of the change rate of the radius. The point where the second derivative is zero and the sign changes is the turning point of the change trend of the radius (such as the point where the radius changes from increasing to decreasing), which corresponds to the shoulder of the bottle body. By screening such feature points, the shoulder search range can be narrowed to a limited turning candidate position.
[0036] For each point on the boundary representation curve, the first derivative and the second derivative of the point are obtained; The absolute value of the product of the first derivative of the horizontal coordinate of the point and the second derivative of the vertical coordinate of the point minus the product of the first derivative of the vertical coordinate of the point and the second derivative of the horizontal coordinate of the point is calculated as the numerator; The cubic root of the sum of the square of the first derivative of the horizontal coordinate of the point and the square of the first derivative of the vertical coordinate of the point is calculated as the denominator; The numerator is divided by the denominator to obtain the curvature of the point; In detail, the curvature is used to quantify the bending degree of the boundary curve. The bending degree of the boundary curve of the shoulder of the bottle body, which is a transitional region in shape, is much larger than that of the bottle body (cylindrical, small bending degree) and the bottle neck (thin cylindrical, small bending degree), and the curvature value will significantly increase. By calculating the curvature, the bending degree of each point on the boundary can be quantified.
[0037] The first derivative of the curvature of the point in the direction of the shape principal axis unit vector of the boundary representation curve is calculated to obtain the corresponding curvature change rate; In detail, the curvature change rate is a parameter for quantifying the speed of curvature change. The shoulder position not only has large curvature, but also has more drastic change in curvature. For example, the curvature changes from small curvature of the bottle body to large curvature of the shoulder, and then to small curvature of the bottle neck, so the local maximum value of the curvature change rate is formed at this position. By calculating the curvature change rate, the region of drastic change in curvature can be captured, and the position of the shoulder with drastic transition is further located, and the non-shoulder region with large curvature but gentle change in curvature, such as the circular arc at the bottom of the bottle body, is excluded.
[0038] According to the axial turning candidate set, a target range of a point on the boundary representation curve corresponding to the axial coordinate belonging to the axial turning candidate set is determined; in the target range, a point with a local maximum value of the absolute value of the curvature change rate is selected to obtain a set of local maximum points of the curvature change rate; wherein the local maximum value is the absolute value of the curvature change rate of the point, which is greater than the absolute values of the curvature change rates of the two adjacent points before and after the point; In detail, the axial turning candidate set has reduced the range to the turning point of the radius change, and on this basis, the local maximum points of the curvature change rate are screened to ensure that the candidate points meet both the turning of the radius and the drastic change in the curvature, and exclude the non-shoulder points that meet only a single feature, such as the slight radius fluctuation points on the bottle body, thereby greatly improving the accuracy of the shoulder candidate points.
[0039] From the set of local maximum points of the curvature change rate, a candidate point is selected, and the candidate point meets that the axial coordinate of the point belongs to the axial turning candidate set; In detail, through the superposition of the double conditions, the interference points that are not shoulder points, such as the points with drastic change in curvature but without turning of the radius, or the points with turning of the radius but gentle change in curvature, can be completely excluded, and only the points with both turning of the radius and drastic change in curvature are retained, which are the candidate points of the shoulder of the bottle body.
[0040] The arc length position of each candidate point on the boundary representation curve is marked, and the candidate point set of the shoulder is formed by collection.
[0041] It should be noted that the shoulder candidate point set is the object set for subsequent defect analysis. The arc length position can accurately locate the specific position of each candidate point on the boundary representation curve, and the set formed after collection clearly indicates all shoulder positions that need to be analyzed for defects.
[0042] In an embodiment of the present application, a local coordinate system is established at the shoulder candidate point, and the surface image is sampled at equal intervals along the inside normal to obtain a corresponding normal gray profile, which includes: For each candidate point in the shoulder candidate point set, a boundary point corresponding to a preset arc length is taken before and after the arc length position of the candidate point, and the coordinate difference of the corresponding boundary point is calculated to obtain a difference vector; the horizontal coordinate component and the vertical coordinate component of the difference vector are divided by the modulus of the difference vector to obtain a unit tangent vector; In detail, the difference vector is used to capture the natural extension direction of the boundary near the candidate point, and the selection of the preset arc length before and after can ensure that the vector reflects the local rather than global boundary direction of the candidate point, avoiding the deviation of the direction caused by the overall bending of the boundary. The normalization process can eliminate the influence of the numerical difference of the preset arc length on the vector length, so that the tangent vectors of different candidate points have a unified length reference.
[0043] The unit tangent vector is rotated by ninety degrees in the opposite direction of the shape principal axis unit vector to obtain an initial normal vector; a pixel length is taken as a small offset, and the offset point obtained by offsetting the boundary point corresponding to the candidate point along the initial normal vector in the opposite direction by a small offset is calculated; In detail, rotating by ninety degrees is a basic requirement of the coordinate system construction, aiming to obtain a normal direction perpendicular to the tangent, meeting the core requirement of the local coordinate system tangent and normal being orthogonal; rotating in the opposite direction of the shape principal axis is based on the preliminary locking of the normal possibly pointing to the inside of the bottle body based on the morphological characteristics of the bottle body.
[0044] The initial normal may point to the outside of the bottle body due to local fluctuations of the boundary, and by detecting whether the offset point is in the bottle body region, the normal direction can be corrected to ensure that the final inside normal vector strictly points to the inside of the bottle body.
[0045] If the offset point does not belong to the bottle body region, the inside normal vector is in the opposite direction of the initial normal vector; If the offset point belongs to the bottle body region, the inside normal vector is the initial normal vector; A local coordinate mapping function is established with the boundary point corresponding to the candidate point as the base point, the unit tangent vector as the tangent coordinate axis, and the inside normal vector as the normal coordinate axis; In detail, the local coordinate mapping function is used to connect the local tangent, normal coordinates and global image coordinates. The base point (the boundary point corresponding to the candidate point) provides the origin of the coordinate system, the tangent and normal axes determine the direction of the coordinate system, and the mapping function can convert any (tangent parameter, normal parameter) in the local coordinate system into accurate global image coordinates, avoiding the deviation of the normal sampling position caused by the complex bending of the global coordinates, and ensuring that each sampling point along the normal can accurately correspond to the actual position of the bottle body surface.
[0046] The boundary point corresponding to the candidate point is taken as the starting point, and the normal distance is gradually increased along the inside normal by a small offset until the normal distance is not in the bottle body region, and the maximum sampling depth is obtained by taking the previous normal distance in the bottle body region; In detail, the maximum sampling depth is used to define the effective range of normal sampling. Since the bottle body has a fixed wall thickness, the position beyond the bottle body region along the normal direction is the background, and the gray value thereof is irrelevant to the bottle body surface and will seriously interfere with the profile analysis. By gradually increasing the distance and judging whether it is in the bottle body region, the last distance in the bottle body interior in the normal direction can be found, and the sampling range is strictly limited in the bottle body interior, so that the gray values collected all reflect the gray value change of the bottle body surface and the near surface, and the interference of the background gray value on the normal gray profile is avoided.
[0047] Starting from the normal distance of zero along the inside normal direction, the normal distance values are sequentially taken with a small offset until the maximum sampling depth is reached; for each normal distance value, the corresponding image coordinates are obtained through a local coordinate mapping function, and the gray values of the image coordinates on the normalized image after morphological gradient processing are calculated by using a bilinear interpolation method; the gray values are sorted in ascending order according to the normal distance to obtain the normal gray profile corresponding to the candidate points.
[0048] It should be noted that the equidistant sampling can make the horizontal coordinates (normal distance) of the normal gray profile uniformly distributed, and ensure that the change rule of the gray value with the normal distance has consistent resolution. The bilinear interpolation is used to improve the calculation accuracy of the gray value: the sampling points may not coincide with the image pixel centers, and directly taking the gray values of the adjacent pixels will produce errors, and the interpolation can calculate the accurate gray value of the sampling point through the weighted calculation of the gray values of the surrounding pixels, so as to ensure that the profile gray value can truly reflect the actual optical characteristics of the position. The discrete sampling gray values are sorted in ascending order according to the normal distance, and are organized into a continuous distance and gray curve to form a complete normal gray profile.
[0049] In an embodiment of the present application, extreme point analysis is performed on the normal gray profile, and the light peak, the upstream stagnation point and the downstream stagnation point are respectively located, including: A one-dimensional Gaussian convolution algorithm is used to denoise and smooth the normal gray profile to obtain a standard profile. In detail, the original data of the normal gray profile may contain high-frequency noise introduced in the sampling process, and these noises will cause irregular small fluctuations in the gray value. The one-dimensional Gaussian convolution algorithm can filter out high-frequency noise by weighted smoothing processing on the profile gray value, so that the change trend of the gray value with the normal distance is more continuous, and the main features of the gray change are retained.
[0050] The central difference method is used to calculate the first derivative and the second derivative of each gray value in the standard profile. In detail, the first derivative is used to quantify the rate of change of the gray value with the normal distance, and the second derivative is used to quantify the trend of the rate of change, both of which are core indicators for identifying extreme points. The central difference method calculates the difference by selecting points symmetrically before and after a certain point, which can reduce the endpoint error and improve the accuracy of derivative calculation compared with single-sided difference. Accurate first and second derivatives can accurately reflect the increasing or decreasing trend of gray value change and the turning point of the trend (such as from increasing speed to decreasing speed).
[0051] In the standard profile, the candidate bright peak is screened to meet: the first derivative of the gray value before the gray value is greater than 0, the first derivative of the gray value after the gray value is less than 0, and the second derivative of the gray value is less than 0; If the number of candidate bright peaks is greater than 1, the maximum gray value in the candidate bright peak is selected as the bright peak; If the number of candidate bright peaks is equal to 1, the candidate bright peak is taken as the bright peak; In detail, the screening condition of the candidate bright peak directly points to the local maximum value of the gray value. The first derivative is positive before and negative after, indicating that the gray value increases with the increase of distance before the point and decreases with the increase of distance after the point, i.e. the point is the turning point of local increasing to decreasing; the second derivative is less than 0, which further confirms that the point is a convex point (local maximum value). Such points are the most prominent gray peaks in the normal gray profile, usually corresponding to the core area of defects or artifacts (such as the strongest scattering of scratches, the high-light deposition area of liquid film artifacts).
[0052] The normal gray profile may have multiple local peaks due to local noise or complex optical features, but only the peak with the largest gray value is the most prominent feature point (corresponding to the most obvious optical change). By selecting the maximum gray value or the only peak as the bright peak, interference from secondary peaks can be avoided.
[0053] The normal distance corresponding to the bright peak is taken as the target distance, and the normal distance interval from zero to the target distance minus a small offset is taken as the first search interval. Each normal distance in the first search interval is traversed in descending order: if the first derivative of the normal distance is equal to 0, or the product of the first derivative of the previous normal distance and the first derivative of the next normal distance is less than 0, and the second derivative of the normal distance is greater than or equal to 0, then the corresponding normal distance is taken as the upstream stationary point. In detail, the first search interval is limited to the left side of the bright peak (normal distance less than the bright peak), focusing on the gray change area upstream of the bright peak. Traversing in descending order (searching from the bright peak to the starting point) can preferentially capture the stationary point closest to the bright peak, avoiding interference from irrelevant flat points far away. The conditions of the stationary point (first derivative is 0 or sign changes, second derivative is greater than or equal to 0) point to flat points or local minimum points where the gray change rate is 0, which are the boundaries of the gray value tending to be stable upstream of the bright peak, used to define the influence range on the left side of the bright peak.
[0054] The normal distance corresponding to the bright peak is taken as a target distance, and a normal distance interval of the target distance plus a slight offset to the maximum sampling depth is taken as a second search interval, and each normal distance in the second search interval is traversed in ascending order: if the first derivative at the normal distance is equal to 0, or the product of the first derivative of the previous normal distance and the first derivative of the next normal distance is less than or equal to 0, and the second derivative at the normal distance is greater than or equal to 0, the corresponding normal distance is taken as a downstream stationary point.
[0055] It should be noted that the second search interval is limited to the right side of the bright peak (the normal distance is greater than the bright peak), and the gray scale change region downstream of the focused bright peak. Ascending traversal (searching from the bright peak to the maximum depth) can preferentially capture the stationary point closest to the bright peak, ensuring that the point can truly reflect the direct influence range downstream of the bright peak. The conditions of the stationary point are consistent with those upstream, pointing to a flat point or a local minimum point where the gray scale change rate is 0. Such points are the boundaries of the gray scale tending to be stable downstream of the bright peak, and are used to define the influence range to the right of the bright peak.
[0056] In an embodiment of the present application, the intensity geometric correlation index and the width asymmetry index are calculated, comprising: calculating a difference profile of the standard profile and the normal gray scale profile; In detail, the difference profile can highlight the local details (such as small gray scale fluctuations) that are smoothed out in the original profile. These details are key features for distinguishing defects from artifacts.
[0057] The gray scale value difference in the difference profile and the corresponding normal distance are taken as the dependent variable and the independent variable respectively to construct a relative gray scale function; In detail, the relative gray scale function directly links the local gray scale change of the difference profile to the normal distance, and converts the local details from gray scale values to functions that change with distance. This facilitates the quantification of the distribution characteristics of the details through mathematical operations (such as integration).
[0058] The normal distance corresponding to the upstream stationary point is taken as the starting point of integration, and the normal distance corresponding to the downstream stationary point is taken as the termination point of integration to obtain an integration interval; for the normal distance in the integration interval, the normal distance corresponding to the bright peak is subtracted to obtain the corresponding relative normal distance; the product of each relative normal distance in the integration interval and the corresponding relative gray scale function value is calculated to obtain the corresponding coupling term; the integration interval is divided into a plurality of discrete subintervals by a slight offset; the average value of the coupling terms at both ends of the discrete subintervals is calculated, and the product of the average value and the slight offset is taken as, to obtain the corresponding integral value; In detail, the upstream stationary point and the downstream stationary point are the boundaries where the grayscale changes on both sides of the bright peak tend to be stable, and the integral interval defined by the two is exactly the effective range of the bright peak influence (i.e. the grayscale change area related to defects or artifacts). By limiting the integral within the interval, the interference of irrelevant grayscale (such as the uniform grayscale of the normal surface of the bottle body) outside the interval can be excluded, and it is ensured that the index calculation is only for the key area related to the bright peak, thereby improving the pertinence and accuracy of the index.
[0059] The relative normal distance is obtained by subtracting the bright peak distance from the normal distance, converting the coordinate reference from absolute distance to relative distance with the bright peak as the origin, and intuitively distinguishing the upstream of the bright peak (negative distance) and the downstream of the bright peak (positive distance).
[0060] The coupling term combines the grayscale change amplitude of the local detail with the position of the detail relative to the bright peak, and quantifies the degree of association between the two. For example, a negative grayscale change downstream of the bright peak will produce a negative coupling term, and a positive change upstream of the bright peak will produce a positive coupling term. The distribution difference of the detail on both sides of the bright peak can be directly reflected through the coupling term.
[0061] The integral values of all discrete sub-intervals are summed to obtain the intensity geometric correlation index; In detail, the integral is the accumulation of the coupling term within the entire effective interval, and can reflect the overall distribution bias of the local detail relative to the bright peak. The division of discrete sub-intervals makes the continuous integral feasible in actual calculation, and the average value of the coupling term at both ends of the sub-interval multiplied by a small offset can ensure the calculation accuracy of the integral value. The final intensity geometric correlation index can quantify the overall asymmetry of the detail distribution.
[0062] The downstream half-width is obtained by subtracting the normal distance corresponding to the bright peak from the normal distance corresponding to the downstream stationary point; The upstream half-width is obtained by subtracting the normal distance corresponding to the upstream stationary point from the normal distance corresponding to the bright peak; In detail, the downstream half-width is the distance from the bright peak to the downstream stationary point, reflecting the width of the influence range downstream of the bright peak; the upstream half-width is the distance from the bright peak to the upstream stationary point, reflecting the width of the influence range upstream of the bright peak. Both of them quantize the spatial extension degree on both sides of the bright peak.
[0063] The difference between the downstream half-width and the upstream half-width is taken as the width asymmetry index.
[0064] It should be noted that the width asymmetry index directly quantizes the width difference of the influence range on both sides of the bright peak. The liquid film artifact has an extended dark tail downstream, so the downstream half-width is usually greater than the upstream half-width, and the index is positive; the scattering distribution of the real scratch is more symmetrical, and the half-widths on both sides are close, and the index is close to zero.
[0065] It should be noted that the liquid film artifact is a non-real defect optical illusion formed by benzalkonium chloride disinfectant liquid residue in the surface detection of the bottle. It is not a structural damage (such as scratch, crack) on the surface of the bottle, but a very thin liquid film (or concentrated solute film) formed by the residual benzalkonium chloride in the disinfectant on the surface of the bottle after evaporation and adsorption, which presents similar visual characteristics to real defects under certain light (such as white light, UVA), which is easy to lead to detection misjudgment.
[0066] It should be noted that the formation of liquid film artifact is directly related to the chemical properties of benzalkonium chloride, the surface state of the bottle and the evaporation process, and it mainly occurs on the shoulder of the bottle, the specific process is as follows: Liquid residue and adsorption retention: during disinfectant filling, sealing or transportation, a small amount of liquid is easy to be retained on the shoulder of the bottle. The area is the transition section of the bottle body and the neck, and the surface tension difference makes the liquid more easily adhere here; at the same time, benzalkonium chloride, as a cationic surfactant, has strong adsorption to the surface of plastic bottles such as PP / PET, and will be firmly fixed on the surface to form an initial liquid film.
[0067] Evaporation-driven liquid film remodeling: the solvent (such as water) of the residual liquid film in the environment will gradually evaporate, and during the evaporation process, two key effects will be triggered, leading to changes in the shape and composition distribution of the liquid film: Contact line pinning effect: the contact line (liquid film edge) between the liquid film and the bottle surface is "fixed" due to the small roughness or chemical heterogeneity of the bottle surface, and cannot shrink with the solvent evaporation, forcing the solute (benzalkonium chloride) in the liquid film to gather towards the contact line; Marangoni effect: the surface tension gradient is formed on the surface of the liquid film due to the difference in evaporation rate (such as the difference in local evaporation speed caused by the curvature of the shoulder), which drives the liquid film to flow from the area with high surface tension (slow evaporation, low solute concentration) to the area with low surface tension (fast evaporation, high solute concentration), further exacerbating the concentration of solute in a particular area.
[0068] Optical properties of thin film appear: the extremely thin film formed after the concentration of solute has a much smoother surface than the rough surface of the bottle itself. Smooth film will produce mirror reflection, while the rough surface of the bottle is mainly diffuse reflection. The optical difference between the two makes the thin film area appear high light appearance; at the same time, the unevenness of solute aggregation (such as high concentration near the contact line, low concentration in the downstream area or thin liquid film) will lead to local gray scale changes, eventually forming the characteristic combination of high light and dark tail.
[0069] In detail, the high light step and the downstream dark tail of the liquid film artifact are not isolated, but present a fixed spatial relationship, and are strongly related to the structure of the bottle: Position association: the dark tail is always adjacent to the downstream side of the high light step (along the normal direction of the inside of the bottle, i.e. the downstream direction of the liquid film flow), and the two are continuous without gap, forming a continuous gray scale combination of light and dark; Curvature correlation: all features only appear in the curvature mutation zone of the bottle shoulder. This area has the largest difference in liquid film retention and evaporation rate due to the change in curvature, and is most likely to cause solute concentration and liquid film remodeling; the bottle body (cylindrical, uniform curvature) or the bottle neck (thin cylinder, stable curvature) area is difficult to form such features because the liquid film is easy to flow and evaporate uniformly.
[0070] In detail, the real scratch is a physical damage on the surface of the bottle, and the gray profile of the scratch is nearly symmetrically distributed. The center of the scratch may have low gray (or high gray, depending on the light) due to scattering, and the gray on both sides gradually transitions to the normal surface without a dark tail on one side. The gray profile of the liquid film artifact is asymmetrically distributed, with a high-light step in the center. The gray on the upstream side quickly transitions to normal, and the gray on the downstream side extends a dark tail, with the gray slowly recovering. The overall gray depends on the optical reflection of the liquid film, and there is no physical damage rough structure.
[0071] In an embodiment of the present application, the intensity geometric correlation index and the width asymmetry index are fused to calculate a discrimination index, including: The product of the intensity geometric correlation index and the width asymmetry index is taken as the discrimination index.
[0072] In an embodiment of the present application, a defect discrimination result is output according to the discrimination index, and a defect is output based on bright peak positioning, including: If the discrimination index is negative, it is determined that the defect of the corresponding candidate point is a liquid film artifact; If the discrimination index is non-negative, it is determined that the defect of the corresponding candidate point is a real scratch; It should be noted that the intensity geometric correlation index reflects the eccentricity of the gray distribution relative to the bright peak, and the width asymmetry index reflects the width difference of the spatial range on both sides of the bright peak. The fusion of the two can integrate the two types of difference features of gray distribution and spatial range, and eliminate the discrimination ambiguity caused by noise or normal gradual change of a single index. When the liquid film artifact is negative, the intensity index is negative, the width index is positive, and the product is negative. The real scratch has near-symmetrical gray and spatial distribution, and the intensity and width indexes are near zero or small positive, and the product is non-negative. The product amplifies the difference between the two types of features through the sign, forming a clear boundary for differentiation.
[0073] In response to a real scratch, the bright peak pixel coordinates are calculated by a local mapping formula as follows: Bright peak pixel coordinates = boundary base point + tangent parameter x unit tangent vector - normal parameter x inside normal Wherein, the boundary base point is the cumulative arc length of the candidate point at the boundary representation curve, the normal parameter is the normal distance corresponding to the bright peak, and the tangent parameter is 0. The bright peak pixel coordinate is the accurate position of the most prominent feature point (gray peak value) of the scratch in the image. The local mapping formula converts the bright peak position in the local coordinate system into the image pixel coordinate through the boundary base point (the arc length position of the candidate point on the boundary curve, providing the reference origin), the tangent and normal parameters (the tangent parameter is 0, and the focused bright peak itself; the normal parameter is the distance of the bright peak, and the normal depth is determined). Thus, the bending interference of the global coordinate is eliminated, and the bright peak position is completely corresponding to the actual highlight center in the image.
[0074] Taking the tangent parameter 0 as the starting point, searching is performed in the positive tangent direction with the tangent parameter increasing and the negative tangent direction with the tangent parameter decreasing, and the search step is a small offset; In detail, the positive and negative searching aims to capture the complete range of the scratch along the tangent direction (boundary extension direction). The small offset ensures the search accuracy and avoids missing the scratch details due to the large step. The positive direction (tangent parameter increasing) and the negative direction (tangent parameter decreasing) correspond to two extension directions of the scratch along the boundary respectively, and all effective parts of the scratch in the tangent direction can be completely covered by gradually advancing.
[0075] For each search tangent parameter, the corresponding normal parameter search range is calculated through the local mapping formula, and the normal parameter in the normal parameter search range is determined to meet the target condition: After the morphological gradient processing, the first-order derivative of the normalized image at the pixel corresponding to the normal parameter along the inside normal direction is zero, and the second-order derivative along the inside normal direction is negative; In detail, the target condition is used to accurately identify the local gray peak value in the normal direction, and to ensure that the searched points are all bright peaks of the scratch at this tangent position. The zero first-order derivative indicates that the gray change rate is zero (peak point), and the negative second-order derivative confirms that the point is a local maximum (convex point). The combination of the two can exclude the non-peak points in the normal direction, and ensure that the normal parameter corresponding to each tangent parameter is an effective feature point of the scratch.
[0076] When the search of the positive tangent or the negative tangent is completed, if there is no normal parameter meeting the target condition, the search of the corresponding tangent is stopped, the last tangent parameter in the corresponding direction is marked as the positive termination tangent parameter and the negative termination tangent parameter respectively, and the tangent effective interval is obtained; In detail, the tangent effective interval is the actual existing range of the scratch in the tangent direction. When no normal parameter meeting the condition is searched in a certain tangent direction, it is indicated that the scratch boundary has been exceeded, and the termination tangent parameter marked at this time is the end point of the scratch in this direction. The interval defined by the positive and negative termination parameters accurately frames the complete extension range of the scratch along the tangent, and excludes irrelevant areas outside the boundary.
[0077] All tangent parameters and corresponding normal parameters in the tangent effective interval that meet the target conditions are combined, converted into pixel coordinates corresponding to the normalized image after morphological gradient processing through the local mapping formula, the pixel coordinates are sequentially connected in ascending order of tangent parameters to form a continuous bright band center line; In detail, the bright band center line is a direct presentation of the scratch core profile. By connecting all points in the effective interval that meet the conditions (in ascending order of tangent parameters, i.e. along the boundary extension direction), a continuous curve can be formed, which accurately reflects the trend, bending tendency and overall shape of the scratch. The center line retains the geometric characteristics of the scratch, providing a clear visual reference for intuitive identification of the scratch shape.
[0078] The normal distance corresponding to the upstream stationary point is taken as the lower bound of the normal width, and the normal distance corresponding to the downstream stationary point is taken as the upper bound of the normal width, to form a normal interval; In detail, the normal interval is the width range of the scratch in the normal direction (perpendicular to the boundary direction). The interval between the upstream stationary point (upstream gray stable boundary of the bright peak) and the downstream stationary point (downstream gray stable boundary of the bright peak) covers all effective gray level change regions of the scratch in the normal direction, excluding the normal surface region outside the interval. This interval ensures that the subsequent generated mask can accurately surround the lateral range of the scratch, without missing the core features or including irrelevant regions.
[0079] All tangent parameters in the tangent effective interval and all normal parameters in the normal interval are taken; The tangent parameters and corresponding normal parameters are converted into pixel coordinates corresponding to the normalized image after morphological gradient processing through the local mapping formula, the pixel coordinates are marked as 1, and the non-pixel coordinates are marked as 0, to obtain a fine strip mask; In detail, the fine strip mask is a region identifier of the scratch in the image. By converting all parameters in the tangent effective interval and the normal interval into pixel coordinates and marking them as 1 (non-coordinates are marked as 0), a binary scratch region mask can be formed. This mask can accurately frame the spatial range of the scratch, including the core of the center line and covering the entire width interval.
[0080] The output defect includes: bright peak pixel coordinates, bright band center line and fine strip mask.
[0081] It should be noted that the bright peak pixel coordinates provide accurate positioning of the most prominent points of the scratch, facilitating quick review and system integration; the bright band center line directly presents the overall shape of the scratch such as the trend and length, supporting severity assessment and distribution statistics; the fine strip mask defines the spatial range of the scratch, which is used for calculating area quantitative indicators and subsequent targeted processing. The three of them completely describe the defect from the point, line and surface dimensions, meeting the detection, evaluation and processing needs.
[0082] The above describes the embodiments of the present embodiment, but the present embodiment is not limited to the above-described specific embodiments, and the above-described specific embodiments are only illustrative but not restrictive, and those skilled in the art can make many forms under the inspiration of the present embodiment, which all belong to the protection of the present embodiment.
Claims
1. A smart system for identifying surface defects in benzalkonium chloride disinfectant bottles, characterized in that, include: The data acquisition module acquires surface images of disinfectant bottles, extracts bottle regions from surface images and generates bottle outlines, and determines the outer boundary of the bottle based on the bottle outline to generate boundary characterization curves. The candidate point filtering module obtains shoulder candidate points based on the boundary characterization curve. The profile generation module establishes a local coordinate system at the candidate points on the shoulder and samples the surface image at equal intervals along the inner normal to obtain the corresponding normal grayscale profile; wherein, the inner normal points to the inner side of the bottle outline. The index calculation module performs extreme point analysis on the normal grayscale profile, locates the bright peak, upstream stagnation point and downstream stagnation point respectively, and further calculates the intensity geometric correlation index and the width asymmetry index. The defect identification module fuses the strength geometric correlation index and the width asymmetry index to obtain the discrimination index, outputs the defect discrimination result based on the discrimination index, and outputs the defect based on the brightness peak location.
2. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 1, characterized in that, The surface image of the disinfectant bottle is acquired, the bottle body region is extracted from the surface image and the bottle body contour is generated, and the outer boundary of the bottle is determined based on the bottle body contour to generate a boundary characterization curve. The surface image is denoised using a Gaussian smoothing algorithm to obtain the denoised image. A linear normalization algorithm is used to convert the gray values of the denoised image to the range of 0 to 1, thus obtaining a standardized image; After performing morphological gradient processing on the standardized image, connected component analysis is applied to filter out all connected clusters composed of non-zero pixels, and the connected cluster with the largest number of pixels is selected as the bottle region. Extract the boundary pixels of the bottle body region to obtain the outer boundary of the bottle body; For the pixels on the outer boundary of the bottle, starting from any pixel, the cumulative arc length of each pixel is calculated by accumulating the Euclidean distance between adjacent pixels segment by segment; using the cumulative arc length as the independent variable, the coordinates of the pixels on the outer boundary of the bottle are interpolated to obtain the boundary characterization curve.
3. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 2, characterized in that, Candidate points for the shoulder were obtained based on the boundary characterization curve screening, including: The area of the enclosed region of the boundary characterization curve is calculated using a polygon area algorithm. The center of the enclosed region of the boundary characterization curve is calculated using the polygon centroid algorithm; Calculate the second-order central moment matrix of the enclosed region of the boundary characterization curve. The second-order central moment matrix includes the second-order central moment in the x-direction, the second-order central moment in the y-direction, and the mixed second-order central moment. The second-order central moment in the x-direction, the second-order central moment in the y-direction, and the mixed second-order central moment are all calculated based on the area and center of the enclosed region. Eigenvalue decomposition is performed on the second-order central moment matrix, and the eigenvector corresponding to the largest eigenvalue is selected as the unit vector of the shape principal axis. For each point on the boundary characterization curve, calculate the first derivative of the point along the unit vector direction of the principal axis of the shape to obtain the first-order guiding quantity containing the derivative of the horizontal coordinate and the derivative of the vertical coordinate. Divide the derivative of the horizontal coordinate and the derivative of the first-order guiding quantity by the magnitude of the first-order guiding quantity to obtain the tangential unit vector. For each point on the boundary characterization curve, calculate the lateral difference between the point's x-coordinate and the x-coordinate of the enclosed region's center, and the longitudinal difference between the point's y-coordinate and the y-coordinate of the enclosed region's center. Multiply the lateral difference by the x-coordinate component of the shape principal axis unit vector to obtain the first component product. Multiply the longitudinal difference by the y-coordinate component of the shape principal axis unit vector to obtain the second component product. Add the first and second component products to obtain the axial coordinates corresponding to the point. The first vector is constructed based on the horizontal and vertical differences of each point on the boundary characterization curve; the second vector is obtained by calculating the product of the axial coordinate of the point and the unit vector of the principal axis of the shape; the magnitude of the difference vector between the first vector and the second vector is used as the radius of the corresponding point. Divide the axial coordinates of each point on the boundary characterization curve into monotonically increasing or monotonically decreasing intervals; within each monotonically increasing interval, establish the functional relationship between the axial coordinates and the corresponding radius using interpolation to obtain the radius-axial function; For each point on the radius-axis function, calculate the first derivative along the axial coordinate direction, and then calculate the second derivative along the axial coordinate direction. From all points on the radius-axis function, select feature points that satisfy the following conditions: the second derivative is equal to zero, and the signs of the second derivatives of the points before and after the point are opposite. Merge the axial coordinates of all feature points to form a candidate set of axial turning points. For each point on the boundary characterization curve, obtain the first and second derivatives of that point; Calculate the first derivative of the x-coordinate of the point, multiply it by the second derivative of the y-coordinate of the point, and subtract the absolute value of the first derivative of the y-coordinate of the point multiplied by the second derivative of the x-coordinate of the point, and use this as the numerator; Calculate the cube root of the sum of the squares of the first derivatives of the x-coordinate and the first derivatives of the y-coordinate, and use it as the denominator. Divide the numerator by the denominator to obtain the curvature of the point; For the curvature of a point, calculate the first derivative along the principal axis unit vector direction of the boundary curve to obtain the corresponding rate of curvature change. Based on the candidate set of axial turning points, the target range of points on the boundary characterization curve whose corresponding axial coordinates belong to the candidate set of axial turning points is determined; within the target range, points whose absolute value of the rate of change of curvature is a local maximum are selected to obtain the set of local maximum points of the rate of change of curvature; where the local maximum is the absolute value of the rate of change of curvature of a point, which is greater than the absolute value of the rate of change of curvature of the two adjacent points. Candidate points are selected from the set of local maxima of the rate of change of curvature. The candidate points satisfy the following condition: the axial coordinates of the points belong to the axial turning candidate set. Mark the position of each candidate point on the arc length of the boundary characterization curve, and summarize them to form a set of candidate points for the shoulder.
4. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 3, characterized in that, A local coordinate system is established at the candidate points on the shoulder, and the surface image is sampled at equal intervals along the inner normal to obtain the corresponding normal grayscale profile, including: For each candidate point in the shoulder candidate point set; take boundary points corresponding to a preset arc length before and after the candidate point's arc length position, and calculate the coordinate difference between the corresponding boundary points to obtain the difference vector; divide the horizontal and vertical components of the difference vector by the magnitude of the difference vector to obtain the unit tangential vector; Rotate the unit tangential vector 90 degrees in the opposite direction of the shape principal axis unit vector to obtain the initial normal vector; take a pixel length as a small offset, and calculate the offset point obtained by shifting the boundary point corresponding to the candidate point in the opposite direction of the initial normal vector by the small offset. If the offset point does not belong to the bottle area, the inner normal vector is in the opposite direction of the initial normal vector; If the offset point belongs to the bottle area, then the inner normal vector is the initial normal vector; A local coordinate mapping function is established using the boundary points corresponding to the candidate points as base points, the unit tangential vector as the tangential coordinate axis, and the inner normal vector as the normal coordinate axis. Starting from the boundary point corresponding to the candidate point, gradually increase the normal distance along the inner normal direction with a small offset until the normal distance is no longer in the bottle area. Then take the previous normal distance in the bottle area to obtain the maximum sampling depth. Starting from zero normal distance along the inner normal direction, normal distance values are sequentially taken with small offsets until the maximum sampling depth is reached. For each normal distance value, the corresponding image coordinates are obtained through a local coordinate mapping function. The gray value of the image coordinates on the standardized image after morphological gradient processing is calculated using bilinear interpolation. The gray values are sorted in ascending order according to the normal distance to obtain the normal gray profile corresponding to the candidate point.
5. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 4, characterized in that, Extreme point analysis was performed on the normal grayscale profile to locate bright peaks, upstream stagnation points, and downstream stagnation points, including: A one-dimensional Gaussian convolution algorithm is used to denoise and smooth the normal grayscale profile to obtain a standard profile. The first and second derivatives of each gray value in the standard profile were calculated using the central difference method. Candidate bright peaks are selected in the standard profile to meet the following conditions: the first derivative of the previous gray value is greater than 0, the first derivative of the next gray value is less than 0, and the second derivative of the gray value is less than 0. If the number of candidate bright peaks is greater than 1, then the highest gray value among the candidate bright peaks is selected as the bright peak. If the number of candidate bright peaks is equal to 1, then the candidate bright peak is taken as a bright peak; The normal distance corresponding to the bright peak is taken as the target distance, and the normal distance interval from zero to the target distance minus the small offset is taken as the first search interval. The normal distance in the first search interval is traversed in descending order: if the first derivative of the normal distance is equal to 0, or the product of the first derivative of the previous normal distance and the first derivative of the next normal distance is less than 0, and the second derivative of the normal distance is greater than or equal to 0, then the corresponding normal distance is taken as the upstream stationary point. The normal distance corresponding to the bright peak is taken as the target distance, and the normal distance interval from the target distance plus a small offset to the maximum sampling depth is taken as the second search interval. The normal distance in the second search interval is traversed in ascending order: if the first derivative of the normal distance is equal to 0, or the product of the first derivative of the previous normal distance and the first derivative of the next normal distance is less than or equal to 0, and the second derivative of the normal distance is greater than or equal to 0, then the corresponding normal distance is taken as the downstream stationary point.
6. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 5, characterized in that, The calculated strength geometric correlation index and width asymmetry index include: Calculate the difference profile between the standard profile and the normal grayscale profile; The grayscale difference and the corresponding normal distance in the difference profile are used as the dependent and independent variables, respectively, to construct a relative grayscale function; Using the normal distance corresponding to the upstream stationary point as the starting point of integration and the normal distance corresponding to the downstream stationary point as the ending point of integration, the integration interval is obtained. For the normal distance within the integration interval, the normal distance corresponding to the bright peak is subtracted to obtain the corresponding relative normal distance. The product of each relative normal distance within the integration interval and the corresponding relative grayscale function value is calculated to obtain the corresponding coupling term. The integration interval is divided into multiple discrete sub-intervals according to a small offset. The average value of the coupling terms at both ends of the discrete sub-interval is calculated, and the product of the average value and the small offset is used as the corresponding integral value. The intensity geometric correlation index is obtained by summing the integral values over all discrete sub-intervals. Subtract the normal distance corresponding to the bright peak from the normal distance corresponding to the downstream stagnation point to obtain the downstream half-width; Subtract the normal distance corresponding to the upstream stagnation point from the normal distance corresponding to the bright peak to obtain the upstream half-width; The difference between the downstream half-width and the upstream half-width is used as an indicator of width asymmetry.
7. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 6, characterized in that, The discrimination index is obtained by fusing the strength geometric correlation index and the width asymmetry index, including: The product of the strength geometric correlation index and the width asymmetry index is used as the discrimination index.
8. The intelligent defect detection system for benzalkonium chloride disinfectant bottles according to claim 7, characterized in that, The defect discrimination results are output based on the discrimination index, and the defects are output based on the brightness peak location, including: If the discrimination index is negative, the defect of the corresponding candidate point is determined to be a liquid film artifact. If the discrimination index is non-negative, then the defect of the corresponding candidate point is determined to be a real scratch; In response to real scratches, the coordinates of bright peak pixels are calculated using a local mapping formula, as follows: Bright peak pixel coordinates = boundary base point + tangential parameter × unit tangential vector - normal parameter × inner normal vector Wherein, the boundary base point is the cumulative arc length of the candidate point at the boundary characterization curve, the normal parameter is the normal distance corresponding to the bright peak, and the tangential parameter is 0; Starting from tangential parameter 0, the search proceeds along the positive tangential direction where the tangential parameter increases and the negative tangential direction where the tangential parameter decreases, with a search step size of a small offset. For each search tangential parameter, the corresponding normal parameter search range is calculated using the local mapping formula. The normal parameters within the search range are then determined to satisfy the target condition. In the normalized image after morphological gradient processing, the first derivative along the inner normal direction is zero at the pixel corresponding to the normal parameter, and the second derivative along the inner normal direction is negative. After searching in the positive or negative tangential direction, if there is no normal parameter that satisfies the target condition, stop the search for the corresponding tangential direction, and mark the last tangential parameter of the corresponding direction as the positive termination tangential parameter and the negative termination tangential parameter respectively, to obtain the effective tangential range. All tangential parameters and corresponding normal parameters that meet the target conditions within the effective tangential range are combined and converted into pixel coordinates of the standardized image after morphological gradient processing using a local mapping formula. The pixel coordinates are then connected sequentially in ascending order of the tangential parameters to form a continuous bright band centerline. The normal distance corresponding to the upstream stationary point is used as the lower bound of the normal width, and the normal distance corresponding to the downstream stationary point is used as the upper bound of the normal width, forming a normal interval; Take all tangential parameters within the valid tangential interval and all normal parameters within the normal interval; The tangential parameters and the corresponding normal parameters are converted into pixel coordinates of the normalized image after morphological gradient processing using a local mapping formula. Pixel coordinates are marked as 1 and non-pixel coordinates are marked as 0 to obtain the thin band mask. Output defects include: bright peak pixel coordinates, bright band center line, and thin band mask.