Disclosure of Invention
In order to solve the problems, the invention aims to provide a machine vision detection method for defects of instant noodle packages, which has better stability and robustness, reduces the omission factor and the false detection rate, improves the detection efficiency, has high detection speed, realizes nondestructive detection, saves labor resources, reduces the cost for enterprises, and makes the instant noodle packages more refined.
The technical scheme adopted by the invention for solving the problems comprises the following steps:
A. establishing an automatic detection device model for the packaging defects of the instant noodles, collecting an image of the packaging of the instant noodles on a conveyor belt, preprocessing the image, and enhancing the image characteristics;
B. selecting an image segmentation center pixel point, establishing a similarity measurement standard according to the continuity between pixel grayscales, and segmenting all pixels into different regions;
C. convolving the segmented packaging image by a Gaussian kernel function to obtain a Gaussian difference image, and extracting the defect characteristics of the packaging image of the instant noodle by solving the gray extreme value of the image;
D. classifying by measuring the similarity between the defect characteristics and the sample, detecting the defect type and kicking off, and completing the automatic detection of the instant noodle packaging defects.
Further, the step a comprises:
(1) establishing an automatic detection device for the packaging defect of the instant noodles, collecting an image of the instant noodles on a conveyor belt by a camera, transmitting the image to a main control device, digitizing the image, and performing equalization processing on the gray value of the image by utilizing a histogram, wherein the gray value of the image after the equalization processing is as follows:
wherein, l is the gray level of the image, f (t) is the probability density function of the gray level of the image, t is a pixel point, the normalization processing is carried out on the gray level of the image, and when l belongs to [0,1], the probability density function value is 1; otherwise, the value is 0;
(2) if the gray value of the image pixel point (x, y) is g (x, y), the gray range is [ g [ ]1 ,g2 ]Mapping the gray value to g' (x, y) by a mapping function, and performing gray conversion:
where (α, β) is a gradation range after gradation conversion.
Further, the step B includes:
(1) color space processing of instant noodle packaging imagePerforming inter-conversion, performing initial segmentation on the image by a watershed method, and if a certain region is Vr Neighborhood of Vi (i ═ 1, 2.., n), then the similarity function is:
where ω is the weight coefficient, n is the number of neighborhoods, x
i Is the mean value of the gray levels of each region,
obtaining a threshold value by a maximum inter-class variance method according to the gray level mean value of all the regions, wherein the similarity function value is larger than the threshold value, and the region is selected as a seed region;
(2) marking the selected seed region, traversing all seed regions and neighborhoods thereof, checking the neighborhood of the region if the seed region is not marked, and marking the same in the region if the neighborhood marks are the same; if the neighborhood marks are different, calculating the gray mean value difference between the region and the neighborhood, selecting the neighborhood with the minimum difference to carry out the same marking, traversing all the regions until all the regions are marked, combining adjacent pixels with similar gray values to the seed region into one region, combining a plurality of small fragmented regions in the segmented region, setting a region range threshold, and combining the regions smaller than the threshold into the neighborhood with the minimum gray mean value difference, thereby completing the image segmentation.
Further, the step C includes:
(1) constructing a Gaussian function of the instant noodle packaging image:
wherein, sigma is the standard deviation of the image normal distribution, (x, y) are the pixel coordinates, and (x)0 ,y0 ) Is the coordinates of the seed point, the scale space function of the image I (x, y) is:
S(x,y)=h(x,y)*I(x,y)
wherein, the more the convolution is represented, the smaller the σ is, the smaller the image scale is, and the more obvious the detail feature is;
(2) the packaging image is convolved by a Gaussian function to generate a group of images, and the images are separated by a constant k in a scale space to obtain a Gaussian difference function:
D(x,y)=[h(x,y)-h(k(x,y))]*I(x,y)
=S(k(x,y))-S(x,y)
comparing pixel points in the image through a Gaussian difference function, setting a gray threshold, searching pixel points with gray values larger than the threshold, searching gray extreme points in the remaining pixel points as feature points to be selected, and performing Taylor expansion on the Gaussian difference function:
wherein, (x, y)
T Is the offset of the pixel point, order
And finally, obtaining extreme points, removing pixel points at the edges in the candidate feature points, and extracting stable feature points.
Further, the step D includes:
calculating the Euclidean distance between the extracted characteristic image f (x, y) and the detection sample s (x, y):
wherein f isj And (x, y) is the jth characteristic, m is the number of the characteristics, min (d) and classification are carried out by searching the characteristic with the minimum Euclidean distance, the main control device counts the defect types and sends a signal to the kicking-off device for kicking off, and the package without the defect continues the next procedure, so that the automatic detection of the package defect of the instant noodles is completed.
The beneficial effects of the invention are:
under the condition that the packaging quality of the instant noodles is higher and higher, the method has better stability and robustness, reduces the omission factor and the false detection rate, improves the detection efficiency, has high detection speed, realizes nondestructive detection, saves labor resources, reduces the cost for enterprises, and makes the packaging of the instant noodles more refined.
Detailed Description
Referring to fig. 1, the method of the present invention comprises the steps of:
A. establishing an automatic detection device model for the packaging defects of the instant noodles, collecting an image of the packaging of the instant noodles on a conveyor belt, preprocessing the image, and enhancing the image characteristics;
(1) and establishing an automatic detection device for the defects of the instant noodle package, as shown in figure 2. The camera gathers the instant noodle package image on the conveyer belt, conveys to master control set. The original image acquired in the field may have various noises, so that preprocessing is required. The image is digitized, and the histogram is used for carrying out equalization processing on the gray value of the image, so that the visual effect is enhanced. The gray scale of the image after the equalization processing is as follows:
wherein l is the gray level of the image, f (t) is the probability density function of the image gray level, and t is the pixel point. Normalizing the image gray level, and when l belongs to [0,1], the probability density function value is 1; otherwise it is 0.
(2) If the gray scale value of the image pixel point (x, y) is g (x, y), the gray scale range is [ g ]1 ,g2 ]Mapping the gray value to g' (x, y) by a mapping function, and performing gray conversion:
where (α, β) is a gradation range after gradation conversion. Thereby enlarging the gray scale range of the image and making the image clearer.
B. Selecting an image segmentation center pixel point, establishing a similarity measurement standard according to the continuity between pixel grayscales, and segmenting all pixels into different regions;
(1) and (4) performing color space conversion on the convenient surface packaging image, and performing initialization segmentation on the image by a watershed method. If a certain region is Vr With a neighborhood of Vi (i ═ 1, 2.., n), then the similarity function is:
where ω is the weight coefficient, n is the number of neighborhoods, x
i Is the mean value of the gray levels of each region,
is the mean of the gray levels of all the regions. And obtaining a threshold value through a maximum inter-class variance method, wherein the similarity function value is larger than the threshold value, and the region is selected as a seed region.
(2) And marking the selected seed region, and traversing all the seed regions and the neighborhoods thereof. If the region is not marked, checking the neighborhood of the region, and if the neighborhood marks are the same, marking the region in the same way; if the adjacent domains are different in mark, the gray average value difference between the region and the adjacent domains is calculated, and the adjacent domains with the minimum difference are selected to carry out the same mark. All regions are traversed until all regions are marked. Thereby merging adjacent pixels having similar gray values as the seed region into one region. And setting a region range threshold value, and combining the regions smaller than the threshold value into a neighborhood with the minimum gray mean difference, thereby completing image segmentation.
C. Convolving the packaging image by a Gaussian kernel function to obtain a Gaussian difference image, and extracting the defect characteristics of the instant noodle packaging image by solving the gray extreme value of the image (as shown in figure 3);
(1) constructing a Gaussian function of the instant noodle packaging image:
wherein, sigma is the standard deviation of the image normal distribution, (x, y) is the pixel point coordinate, (x)0 ,y0 ) Are the coordinates of the seed points. The scale-space function of image I (x, y) is then:
S(x,y)=h(x,y)*I(x,y)
where denotes convolution. The smaller sigma, the smaller the image scale, and the more prominent the detail features.
(2) The packaging image is convolved by a Gaussian function to generate a group of images, and the images are separated by a constant k in a scale space to obtain a Gaussian difference function:
D(x,y)=[h(x,y)-h(k(x,y))]*I(x,y)
=S(k(x,y))-S(x,y)
comparing pixel points in the image through a Gaussian difference function, setting a gray threshold, searching pixel points with gray values larger than the threshold, searching gray extreme points in the remaining pixel points as feature points to be selected, and performing Taylor expansion on the Gaussian difference function:
wherein, (x, y)
T Is the offset of the pixel. Order to
Thereby obtaining an extreme point. And removing the pixel points at the edge in the candidate feature points, and extracting stable feature points.
D. Classifying by measuring the similarity between the defect characteristics and the sample, detecting the defect category and kicking off, and completing the automatic detection of the defects of the instant noodle packaging.
Calculating the Euclidean distance between the extracted characteristic image f (x, y) and the detection sample s (x, y):
wherein f isj And (x, y) is the jth characteristic, m is the number of the characteristics, min (d) and classification are carried out by searching the characteristic with the minimum Euclidean distance, the main control device counts the defect types and sends a signal to the kicking-off device for kicking off, and the package without the defect continues the next procedure, so that the automatic detection of the package defect of the instant noodles is completed.
In conclusion, the instant noodle packaging defect machine vision detection method is completed. The method has the advantages of good stability and robustness, low omission factor and false detection rate, high detection efficiency, high detection speed, nondestructive detection, labor resource saving, cost reduction for enterprises and more fine instant noodle packaging.