Foreign matter detection method and system in milk powder can

By constructing the objective function to determine the grayscale target number and convert the milk powder jar image into a grayscale map, combining the non-impurity grayscale intervals of the milk powder area and the can wall area, the frequency, interval distance and area size vectors of each grayscale level are calculated. The accuracy and real-time problems of impurity detection in milk powder cans are solved, and high-accurate impurity detection of milk powder cans is achieved.

CN119206632BActive Publication Date: 2025-02-07SHAANXI YATAI DAIRY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411718859.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-02-07
Estimated Expiration
2044-11-28

AI Technical Summary

Technical Problem

It is difficult for the prior art to realize real-time and accurate detection of impurities in milk powder cans on the milk powder production line, especially distinguishing and identifying impurities in the milk powder area and the can wall area.

Method used

By collecting multiple images of impurities in milk powder jars, the objective function is constructed to determine the number of grayscale targets, convert the image into a grayscale map, and count the non-impurity grayscale intervals of the milk powder area and the can wall area, and apply it in real-time images These grayscale intervals calculate the frequency, interval distance and area size vectors of each grayscale level to obtain impurity detection results.

Benefits of technology

It improves the accuracy of impurities detection in milk powder cans, can accurately identify whether there are impurities in the milk powder area and the can wall area, and position the areas with impurities to meet the real-time detection needs on the milk powder production line.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119206632B_ABST
    Figure CN119206632B_ABST
Patent Text Reader

Abstract

The present application relates to the field of image processing, and in particular to a method and system for detecting foreign matter in a milk powder can. The method comprises: collecting multiple images of milk powder cans with impurities to obtain a milk powder can image set; constructing an objective function based on the milk powder can image set to determine the number of grayscale targets; counting the non-impurity grayscale intervals of the milk powder area and the can wall area under the number of grayscale targets; obtaining a real-time milk powder grayscale map and a real-time can wall grayscale map of a real-time image; respectively calculating the frequency of each grayscale in the real-time milk powder grayscale map and the real-time can wall grayscale map, the interval distance between each grayscale and the corresponding non-impurity grayscale interval, and the area size vector of each grayscale, and then constructing an impurity judgment index to obtain an impurity detection result. Through the technical solution of the present application, it is possible to accurately identify whether there are impurities in the milk powder area and the can wall area, and improve the accuracy of the impurity detection result of the milk powder can.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application generally relates to the field of image processing, and more particularly to a method and system for detecting foreign matter in a milk powder can. Background Art

[0002] As an important source of nutrition for infants and adults, the quality and safety of milk powder are of vital importance. However, during the production, storage and transportation of milk powder, various impurities such as metal fragments, glass slag, plastic particles or other contaminants may be mixed in, which pose a potential threat to consumers' health. Therefore, efficient and accurate detection of impurities in milk powder is an important means to ensure the quality and safety of milk powder.

[0003] Traditional milk powder impurity detection technology mainly relies on manual observation and chemical analysis methods. With the development of science and technology, some advanced detection technologies, such as near-infrared spectroscopy and gas chromatography-mass spectrometry, have gradually been applied to milk powder impurity detection. However, these technologies also have some limitations, such as expensive equipment, complex operation, and long detection time, which make it difficult to achieve real-time and rapid detection on the milk powder production line.

[0004] At present, a patent application document with publication number CN117522838A discloses a milk powder quality detection method and system based on convolutional neural network. First, an image of milk powder to be detected is obtained; the image of milk powder to be detected is preprocessed by image processing technology; a convolutional neural network model is constructed, and the convolutional neural network model is trained using a training set; the preprocessed milk powder image to be detected is passed into the trained convolutional neural network model for detection; and the milk powder quality assessment result is obtained according to the analysis result of the convolutional neural network model.

[0005] The above method can be used to achieve rapid detection through deep learning neural network technology. However, when there is milk powder in the milk powder can, it is impossible to accurately identify whether there are impurities in the milk powder area and the can wall area, resulting in inaccurate impurity detection results in the milk powder can. Summary of the invention

[0006] In order to solve the above technical problems in the prior art, the present application provides a method for detecting foreign matter in a milk powder can, which can accurately identify whether there are impurities in the milk powder area and the can wall area, thereby improving the accuracy of the impurity detection results of the milk powder can.

[0007] In a first aspect, the present invention provides a method for detecting foreign matter in a milk powder can, wherein the milk powder can includes a milk powder area and a can wall area, and the method includes: collecting multiple images of the milk powder can with impurities to obtain a milk powder can image set, wherein the image of the milk powder can with impurities includes an impurity area and a non-impurity area; constructing an objective function based on the milk powder can image set to determine the number of grayscale targets, wherein the number of grayscale targets can make the pixel values ​​of the impurity area and the non-impurity area be at different grayscale levels; converting the milk powder can images of the milk powder can image set into corresponding grayscale images based on the number of grayscale targets, and counting the non-impurity grayscale intervals of the milk powder area and the can wall area; obtaining the real-time milk powder area and the real-time can wall area in the real-time image of the milk powder can, and obtaining the real-time milk powder grayscale image and the real-time can wall grayscale image corresponding to the real-time milk powder area and the real-time can wall area according to the number of grayscale targets. ; Calculate the frequency of each gray level in the real-time milk powder gray level map and the real-time tank wall gray level map, the interval distance between each gray level and the corresponding non-impurity gray level interval, and the area size vector of each gray level, wherein the area size vector includes the frequency of occurrence of connected areas of different sizes of corresponding gray levels; Obtain impurity detection results based on the frequency, interval distance and area size vector of each gray level, wherein the impurity detection results include no impurities, impurities in the milk powder area, impurities in the tank wall area, and impurities in both the milk powder area and the tank wall area; Wherein, constructing an objective function based on the milk powder can image set to determine the target number of gray levels includes: setting an initial number of gray levels, converting the milk powder can image in the milk powder can image set into a corresponding gray level map according to the initial number of gray levels, the gray level map includes the gray level corresponding to each pixel, and the gray level satisfies the relationship:

[0008] ,in, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image The pixel value of is the initial gray level number, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image Gray level; based on the gray level map, the level evaluation value corresponding to the initial gray level number is calculated, and the level evaluation value satisfies the relationship:

[0009] ,in, This is the first image in the milk powder can image collection The impurity area of ​​the milk powder can image. This is the first image in the milk powder can image collection The non-impurity area of ​​the milk powder can image, For the Pixel points in the impurity area of ​​the milk powder can image The gray level, For the Pixel points in the non-impurity area of ​​the milk powder can image The gray level, For the The standard deviation of the gray level in the impurity area of ​​the milk powder can image is For the The standard deviation of the gray level in the non-impurity area of ​​the milk powder can image is is the number of all milk powder can images in the milk powder can image set, is the initial gray level number The series evaluation value; based on the series evaluation value, the objective function is constructed, and the objective function satisfies the relationship:

[0010] ,in, is the value of the objective function; the objective function is solved by the optimization algorithm, and the initial gray level number corresponding to the maximum value of the level evaluation value is taken as the gray level target number.

[0011] In this way, the determination of the number of gray levels is transformed into an optimization problem, and the target number of gray levels is automatically determined. The target number of gray levels can make the pixel values ​​in the impurity area at the same gray level as much as possible, the pixel values ​​in the non-impurity area at the same gray level as much as possible, and at the same time, make the pixel values ​​in the impurity area and the non-impurity area at different gray levels as much as possible.

[0012] In some embodiments, counting the non-impurity grayscale intervals of the milk powder area and the can wall area includes: for the grayscale map corresponding to any milk powder can image in the milk powder can image set, counting the number of occurrences corresponding to all grayscale levels in the non-impurity area in the target area, wherein the target area is the milk powder area or the can wall area; traversing the grayscale maps corresponding to all milk powder can images, calculating the sum of the number of occurrences to obtain the total number of occurrences of each grayscale level in the non-impurity area in the target area; calculating the mean and variance of all the total number of occurrences, and determining the normal interval based on the mean and variance; in response to the total number of occurrences being within the normal interval, deleting the grayscale level corresponding to the total number of occurrences; in response to the total number of occurrences not being within the normal interval, marking the grayscale level corresponding to the total number of occurrences as the non-impurity grayscale level, and all the non-impurity grayscale levels constitute the non-impurity grayscale interval of the target area.

[0013] In this way, the non-impurity grayscale intervals of the milk powder area and the tank wall area are obtained. The non-impurity grayscale interval of the milk powder area includes all grayscale levels corresponding to the non-impurity area.

[0014] In some embodiments, the normal range is ,in, is the mean of all the total number of occurrences, is the variance of the total number of occurrences.

[0015] In some embodiments, obtaining the real-time milk powder area and the real-time tank wall area in the real-time image of the milk powder can includes: obtaining a rectangular frame of the milk powder area and the tank wall area in the real-time image of the milk powder can based on a trained target detection network; and cropping the real-time image of the milk powder can based on the rectangular frame to obtain the real-time milk powder area and the real-time tank wall area in the real-time image of the milk powder can.

[0016] In some embodiments, for a gray level in a real-time milk powder gray level map, a method for calculating the interval distance between the gray level and the corresponding non-impurity gray level interval includes: obtaining the non-impurity gray level interval of the milk powder area, the non-impurity gray level interval including multiple non-impurity gray levels; calculating the Euclidean distance between the gray level and each non-impurity gray level, and taking the minimum value of the Euclidean distance as the interval distance between the gray level and the corresponding non-impurity gray level interval.

[0017] In some embodiments, for a gray level in a real-time milk powder gray level map, a method for calculating the region size vector of the gray level includes: in the real-time milk powder gray level map, counting the number of occurrences of connected regions of different gray levels; normalizing the number of occurrences to obtain the frequency of occurrence of connected regions of different gray levels; and constructing a region size vector corresponding to the gray level based on the frequency of occurrence of connected regions of different sizes.

[0018] In this way, the frequency, interval distance and region size vector of each gray level in the real-time milk powder gray level map are obtained. The frequency, interval distance and region size vector of each gray level in the real-time tank wall gray level map can be obtained in the same way.

[0019] In some embodiments, obtaining the impurity detection result based on the frequency, interval distance and area size vector of each gray level includes: calculating a first impurity judgment index based on the frequency of each gray level in the real-time milk powder gray level map, the interval distance from the non-impurity gray level interval of the milk powder area, and the area size vector, and comparing the first impurity judgment index with the first set threshold to obtain the milk powder area detection result, the milk powder area detection result includes the milk powder area with impurities and the milk powder area without impurities; calculating a second impurity judgment index based on the frequency of each gray level in the real-time tank wall gray level map, the interval distance from the non-impurity gray level interval of the tank wall area, and the area size vector, and comparing the second impurity judgment index and the second set threshold to obtain the tank wall area detection result, the tank wall area detection result includes the tank wall area with impurities and the tank wall area without impurities; obtaining the impurity detection result based on the milk powder area detection result and the tank wall area detection result.

[0020] In some embodiments, the first impurity judgment index satisfies the relationship:

[0021] ,in, is the number of all gray levels in the real-time milk powder gray level map, Grayscale The frequency, Grayscale The interval distance from the non-impurity gray interval in the milk powder area, Grayscale in the real-time milk powder grayscale image The information entropy of the corresponding region size vector, It is the first impurity judgment indicator.

[0022] In some embodiments, comparing the first impurity judgment index and the first set threshold to obtain the milk powder area detection result includes: in response to the first impurity judgment index being greater than the first set threshold, the milk powder area detection result is that there are impurities in the milk powder area; in response to the first impurity judgment index being not greater than the first set threshold, the milk powder area detection result is that there are no impurities in the milk powder area.

[0023] In a second aspect, a foreign matter detection system in a milk powder can is provided, characterized in that it comprises: a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-mentioned foreign matter detection method in the milk powder can is implemented.

[0024] The above-mentioned foreign matter detection method in the milk powder can provided by the embodiment of the present invention first determines the number of grayscale targets based on the image of the milk powder can with impurities, so that the pixel values ​​of the impurity area and the non-impurity area are at different grayscales, thereby enhancing the difference between impurities and non-impurities; further, after respectively counting the non-impurity grayscale intervals corresponding to the milk powder area and the can wall area, in the process of impurity detection, the frequency of each grayscale in the milk powder area, the interval distance between each grayscale and the non-impurity grayscale interval, and the area size vector of each grayscale are comprehensively considered to obtain the detection result of the milk powder area; at the same time, the frequency of each grayscale in the can wall area, the interval distance between each grayscale and the non-impurity grayscale interval, and the area size vector of each grayscale are comprehensively considered to obtain the detection result of the can wall area; the detection results of the milk powder area and the can wall area are combined to obtain accurate impurity detection results, and the area with impurities can be located at the same time, thereby improving the accuracy of the impurity detection result of the milk powder can. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become easy to understand. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:

[0026] Figure 1 is a flow chart of a method for detecting foreign matter in a milk powder can according to an embodiment of the present invention;

[0027] Figure 2 is a schematic diagram of a milk powder can according to an embodiment of the present invention;

[0028] Figure 3 is a schematic diagram of a real-time grayscale image of milk powder according to an embodiment of the present invention.

[0029] Description of the accompanying drawings: 200, milk powder can; 20, milk powder area; 30, tank wall area. DETAILED DESCRIPTION

[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0031] It should be understood that when the terms "first", "second", etc. are used in the claims, specification and drawings of the present application, they are only used to distinguish different objects, rather than to describe a specific order. The terms "include" and "comprise" used in the specification and claims of the present application indicate the presence of the described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.

[0032] See also Figure 1 The figure is a flow chart of the method for detecting foreign matter in a milk powder can provided by a preferred embodiment of the present application. According to different requirements, the order of the steps in the flow chart can be changed, and some steps can be omitted.

[0033] S11, collecting a plurality of images of milk powder cans with impurities to obtain a milk powder can image set, wherein the images of the milk powder cans with impurities include impurity areas and non-impurity areas.

[0034] In one embodiment, see Figure 2 , is a schematic diagram of a milk powder can according to an embodiment of the present invention. The milk powder can 200 includes a first area 20 and a second area 30. The first area 20 is a milk powder area, and the second area 30 is a can wall area.

[0035] In one embodiment, during the production and processing of milk powder, multiple images of milk powder cans with impurities are collected, and each image of the milk powder can with impurities is annotated, and each image of the milk powder can with impurities is divided into an impurity area and a non-impurity area, so as to obtain a set of milk powder can images. The impurity area can cover the pixel positions of all impurities, and the annotation process can be manually annotated. The image of the milk powder can with impurities is a single-channel grayscale image.

[0036] S12, constructing an objective function based on the milk powder can image set to determine the number of grayscale targets, where the number of grayscale targets can make the pixel values ​​of the impurity area and the non-impurity area at different grayscales.

[0037] In one embodiment, the milk powder can images in the milk powder can image set are all grayscale images, and their pixel values ​​range from 0 to 255, including a total of 256 gray levels; since there are differences in pixel values ​​between the impurity area and the non-impurity area in the milk powder can image, in order to reduce the amount of calculation for subsequent impurity and foreign matter detection in the milk powder can, while enhancing the difference between the impurity area and the non-impurity area, and improving the accuracy of impurity detection in the milk powder can, it is necessary to perform grayscale conversion on the 256 gray levels; in other words, by reducing the number of gray levels, the pixel values ​​in the impurity area are at the same gray level as much as possible, the pixel values ​​in the non-impurity area are at the same gray level as much as possible, and at the same time, the pixel values ​​in the impurity area and the non-impurity area are at different gray levels as much as possible.

[0038] Specifically, constructing an objective function based on the milk powder can image set to determine the target number of gray levels includes: setting an initial number of gray levels, converting the milk powder can images in the milk powder can image set into corresponding gray level images according to the initial number of gray levels, the gray level image including the gray level corresponding to each pixel, and the gray level satisfies the relationship:

[0039] ,in, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image The pixel value of is the initial gray level number, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image Gray level; based on the gray level map, the level evaluation value corresponding to the initial gray level number is calculated, and the level evaluation value satisfies the relationship:

[0040] ,in, This is the first image in the milk powder can image collection The impurity area of ​​the milk powder can image. This is the first image in the milk powder can image collection The non-impurity area of ​​the milk powder can image, For the Pixel points in the impurity area of ​​the milk powder can image The gray level, For the Pixel points in the non-impurity area of ​​the milk powder can image The gray level, For the The standard deviation of the gray level in the impurity area of ​​the milk powder can image is For the The standard deviation of the gray level in the non-impurity area of ​​the milk powder can image is is the number of all milk powder can images in the milk powder can image set, is the initial gray level number The series evaluation value; based on the series evaluation value, the objective function is constructed, and the objective function satisfies the relationship:

[0041] ,in, is the value of the objective function; the objective function is solved by the optimization algorithm, and the initial gray level number corresponding to the maximum value of the level evaluation value is taken as the gray level target number.

[0042] The optimization algorithm may be an existing optimization algorithm such as a hill climbing algorithm or a simulated annealing algorithm.

[0043] In this way, the determination of the number of gray levels is transformed into an optimization problem, and the target number of gray levels is automatically determined. The target number of gray levels can make the pixel values ​​in the impurity area at the same gray level as much as possible, the pixel values ​​in the non-impurity area at the same gray level as much as possible, and at the same time, make the pixel values ​​in the impurity area and the non-impurity area at different gray levels as much as possible.

[0044] S13, converting the milk powder can images in the milk powder can image set into corresponding grayscale images based on the number of grayscale targets, and counting the non-impurity grayscale intervals of the milk powder area and the can wall area.

[0045] In an optional embodiment, each milk powder can image in the milk powder can image set is converted into a corresponding grayscale image, that is, one milk powder can image corresponds to one grayscale image. Since the milk powder can includes a milk powder area and a can wall area, and there are obvious differences between the milk powder area and the can wall area, in order to improve the accuracy of the impurity detection result of the milk powder can, before counting the non-impurity grayscale intervals of the milk powder area and the can wall area, it also includes: obtaining the milk powder area and the can wall area in each milk powder can image based on the trained target detection network. Specifically, the target detection network can be implemented using existing target detection networks such as YOLOv2-tiny and YOLOv5 to obtain the milk powder area and the can wall area in each milk powder can image.

[0046] In one embodiment, counting the non-impurity grayscale intervals of the milk powder area and the can wall area includes: for the grayscale map corresponding to any milk powder can image in the milk powder can image set, counting the number of occurrences corresponding to all grayscale levels in the non-impurity area in the target area, wherein the target area is the milk powder area or the can wall area; traversing the grayscale maps corresponding to all milk powder can images, calculating the sum of the number of occurrences to obtain the total number of occurrences of each grayscale level in the non-impurity area in the target area; calculating the mean and variance of all the total number of occurrences, and determining the normal interval based on the mean and variance; in response to the total number of occurrences being within the normal interval, deleting the grayscale level corresponding to the total number of occurrences; in response to the total number of occurrences not being within the normal interval, marking the grayscale level corresponding to the total number of occurrences as the non-impurity grayscale level, and all the non-impurity grayscale levels constitute the non-impurity grayscale interval of the target area.

[0047] Among them, the non-impurity grayscale intervals of the milk powder area and the can wall area can be obtained; for the target area (milk powder area or can wall area), in order to obtain an accurate non-impurity grayscale interval, the grayscale levels with a small total number are deleted as statistical errors.

[0048] Among them, the normal interval is based on Obtain the rule and calculate the mean of all total occurrences and variance After that, the normal range is .

[0049] In this way, the non-impurity grayscale intervals of the milk powder area and the tank wall area are obtained. The non-impurity grayscale interval of the milk powder area includes all grayscale levels corresponding to the non-impurity area.

[0050] S14, obtaining a real-time milk powder area and a real-time tank wall area in the real-time image of the milk powder tank, and obtaining a real-time milk powder grayscale map and a real-time tank wall grayscale map corresponding to the real-time milk powder area and the real-time tank wall area according to the number of grayscale targets.

[0051] In an optional embodiment, obtaining the real-time milk powder area and the real-time tank wall area in the real-time image of the milk powder can includes: obtaining a rectangular frame of the milk powder area and the tank wall area in the real-time image of the milk powder can according to the trained target detection network; and cropping the real-time image of the milk powder can according to the rectangular frame to obtain the real-time milk powder area and the real-time tank wall area in the real-time image of the milk powder can. Among them, the target detection network can adopt existing target detection networks such as YOLO and Faster-RCNN.

[0052] In one embodiment, grayscale conversion is performed on the real-time milk powder area and the real-time tank wall area according to the grayscale target number, and pixel values ​​are converted into corresponding grayscales to obtain the real-time milk powder grayscale image and the real-time tank wall grayscale image.

[0053] S15, respectively calculating the frequency of each gray level in the real-time milk powder gray level map and the real-time tank wall gray level map, the interval distance between each gray level and the corresponding non-impurity gray level interval, and the region size vector of each gray level, wherein the region size vector includes the number of occurrences of connected regions of different sizes corresponding to the gray level.

[0054] In one embodiment, for the real-time milk powder grayscale image, the number of grayscales in the real-time milk powder grayscale image is counted, and the ratio of the number to the total number of pixels in the real-time milk powder grayscale image is used as the frequency of the grayscale.

[0055] Among them, for a gray level in the real-time milk powder gray level map, a method for calculating the interval distance between the gray level and the corresponding non-impurity gray level interval includes: obtaining the non-impurity gray level interval of the milk powder area, the non-impurity gray level interval includes multiple non-impurity gray levels; calculating the Euclidean distance between the gray level and each non-impurity gray level, and taking the minimum value of the Euclidean distance as the interval distance between the gray level and the corresponding non-impurity gray level interval.

[0056] Among them, for a gray level in the real-time milk powder gray level map, the calculation method of the gray level area size vector includes: in the real-time milk powder gray level map, counting the number of occurrences of connected areas of different gray levels; after normalizing the number of occurrences, obtaining the frequency of occurrence of connected areas of different gray levels; and constructing the area size vector corresponding to the gray level according to the frequency of occurrence of connected areas of different sizes.

[0057] For example, see Figure 3 , is a schematic diagram of a real-time milk powder grayscale map according to an embodiment of the present invention. For grayscale 2, the number of connected regions of size 1 (only one 2) is 1; the number of connected regions of size 2 (two 2s are adjacent) is 2; the number of connected regions of size 3 (three 2s are adjacent) is 0; the number of connected regions of size 4 (four 2s are adjacent) is 2; the maximum size of a connected region of grayscale 2 is 4, and the region size vector corresponding to grayscale 2 in the real-time milk powder grayscale map is [0.2, 0.4, 0, 0.4].

[0058] In this way, the frequency, interval distance and region size vector of each gray level in the real-time milk powder gray level map are obtained. The frequency, interval distance and region size vector of each gray level in the real-time tank wall gray level map can be obtained in the same way.

[0059] S16, obtaining impurity detection results based on the frequency, interval distance and area size vector of each gray level, wherein the impurity detection results include no impurities, impurities in the milk powder area, impurities in the can wall area, and impurities in both the milk powder area and the can wall area.

[0060] In one embodiment, for a gray level, the larger the interval distance is, the more the gray level deviates from the non-impurity area; for a gray level that deviates far from the non-impurity area, the larger the corresponding frequency is, the greater the possibility of impurities. At the same time, when there are no impurities, for a gray level, the values ​​in the corresponding region size vector should be concentrated in a region of a specific size. For example, if the region size vector of a gray level is [0,0,0,1], it means that the size of the connected domain of the gray level in the image is concentrated in size 4; when there are impurities, since the size and position of the impurities are irregular, the distribution of the connected regions of the gray level is chaotic, which increases the information entropy of the region size vector; therefore, the impurity detection result can be obtained based on the frequency, interval distance and region size vector of each gray level.

[0061] Specifically, obtaining the impurity detection result based on the frequency, interval distance and area size vector of each gray level includes: calculating a first impurity judgment index based on the frequency of each gray level in the real-time milk powder gray level map, the interval distance from the non-impurity gray level interval of the milk powder area, and the area size vector, and comparing the first impurity judgment index with the first set threshold to obtain the milk powder area detection result, the milk powder area detection result includes the milk powder area with impurities and the milk powder area without impurities; calculating a second impurity judgment index based on the frequency of each gray level in the real-time tank wall gray level map, the interval distance from the non-impurity gray level interval of the tank wall area, and the area size vector, and comparing the second impurity judgment index with the second set threshold to obtain the tank wall area detection result, the tank wall area detection result includes the tank wall area with impurities and the tank wall area without impurities; obtaining the impurity detection result based on the milk powder area detection result and the tank wall area detection result.

[0062] Among them, the first impurity judgment index satisfies the relationship:

[0063] ,in, is the number of all gray levels in the real-time milk powder gray level map, Grayscale The frequency, Grayscale The interval distance from the non-impurity gray interval in the milk powder area, Grayscale in the real-time milk powder grayscale image The information entropy of the corresponding region size vector, It is the first impurity judgment indicator.

[0064] It can be understood that the first impurity judgment index is used to judge whether there are impurities in the milk powder area. The larger the value of is, the farther the gray level in the milk powder area deviates from the non-impurity area, and the more chaotic the distribution of the connected areas of the gray level is, the greater the possibility that there are impurities in the milk powder area.

[0065] Wherein, comparing the first impurity judgment index and the first set threshold to obtain the milk powder area detection result includes: in response to the first impurity judgment index being greater than the first set threshold, the milk powder area detection result is that the milk powder area has impurities; in response to the first impurity judgment index being less than the first set threshold, the milk powder area detection result is that the milk powder area has no impurities. Wherein the first set threshold is artificially set based on experience, and in the embodiment of the present invention, the first set threshold is 0.25.

[0066] It should be noted that the second threshold is also set manually based on experience. Since the image features in the milk powder area and the tank wall area are different, the first threshold is different from the second threshold. In the embodiment of the present invention, the first threshold is 0.3.

[0067] It is understandable that the tank wall area detection result can be obtained by the same method, which will not be described in detail in this application.

[0068] In one embodiment, the milk powder area detection results include the presence of impurities in the milk powder area and the absence of impurities in the milk powder area, and the tank wall area detection results include the presence of impurities in the tank wall area and the absence of impurities in the tank wall area; based on the milk powder area detection results and the tank wall area detection results, four impurity detection results can be obtained, including no impurities, impurities in the milk powder area, impurities in the tank wall area, and impurities in both the milk powder area and the tank wall area.

[0069] In this way, the impurity detection of the milk powder can is completed, and an accurate impurity detection result of the milk powder can is obtained.

[0070] The above-mentioned foreign matter detection method in the milk powder can provided by the embodiment of the present invention first determines the number of grayscale targets based on the image of the milk powder can with impurities, so that the pixel values ​​of the impurity area and the non-impurity area are at different grayscales, thereby enhancing the difference between impurities and non-impurities; further, after respectively counting the non-impurity grayscale intervals corresponding to the milk powder area and the can wall area, in the process of impurity detection, the frequency of each grayscale in the milk powder area, the interval distance between each grayscale and the non-impurity grayscale interval, and the area size vector of each grayscale are comprehensively considered to obtain the detection result of the milk powder area; at the same time, the frequency of each grayscale in the can wall area, the interval distance between each grayscale and the non-impurity grayscale interval, and the area size vector of each grayscale are comprehensively considered to obtain the detection result of the can wall area; the detection results of the milk powder area and the can wall area are combined to obtain accurate impurity detection results, and the area with impurities can be located at the same time, thereby improving the accuracy of the impurity detection result of the milk powder can.

[0071] The embodiment of the present invention further discloses a foreign matter detection system in a milk powder can, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the foreign matter detection method in the milk powder can of the present invention is implemented.

[0072] The system also includes other components familiar to those skilled in the art, such as a communication bus and a communication interface. The configuration and functions of these components are known in the art and will not be described in detail here.

[0073] In the present invention, the aforementioned memory may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus or device. For example, a computer-readable storage medium may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory RRAM (Resistive Random Access Memory), a dynamic random access memory DRAM (Dynamic Random Access Memory), a static random access memory SRAM (Static Random-Access Memory), an enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), a high-bandwidth memory HBM (High-Bandwidth Memory), a hybrid memory cube HMC (Hybrid Memory Cube), etc., or any other medium that can be used to store the required information and can be accessed by an application, a module or both. Any such computer storage medium may be part of a device or accessible or connectable to a device.

[0074] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0075] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the patent application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent application shall be subject to the attached claims.

Claims

1. A method for detecting foreign matter in a milk powder can, wherein the milk powder can comprises a milk powder area and a can wall area, and wherein: Collecting multiple images of milk powder cans with impurities to obtain a milk powder can image set, wherein the milk powder can images with impurities include impurity areas and non-impurity areas; Based on the milk powder can image set, an objective function is constructed to determine the number of gray-level targets, which can make the pixel values ​​of the impurity area and the non-impurity area at different gray levels; The milk powder can images in the milk powder can image set are converted into corresponding grayscale images based on the number of grayscale targets, and the non-impurity grayscale intervals of the milk powder area and the can wall area are counted respectively; Acquire a real-time milk powder area and a real-time tank wall area in the real-time image of the milk powder tank, and acquire a real-time milk powder grayscale image and a real-time tank wall grayscale image corresponding to the real-time milk powder area and the real-time tank wall area according to the number of grayscale targets; Calculate the frequency of each gray level in the real-time milk powder gray level map and the real-time tank wall gray level map, the interval distance between each gray level and the corresponding non-impurity gray level interval, and the region size vector of each gray level, wherein the region size vector includes the occurrence frequency of connected regions of different sizes corresponding to the gray level; The impurity detection results are obtained based on the frequency, interval distance and area size vector of each gray level, wherein the impurity detection results include no impurities in the milk powder area and the tank wall area, impurities only in the milk powder area, impurities only in the tank wall area, and impurities in both the milk powder area and the tank wall area; Among them, constructing an objective function based on the milk powder can image set to determine the target number of gray levels includes: setting an initial number of gray levels, converting the milk powder can images in the milk powder can image set into corresponding gray level images according to the initial number of gray levels, the gray level image includes the gray level corresponding to each pixel point, and the gray level satisfies the relationship: ,in, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image The pixel value of is the initial gray level number, This is the first image in the milk powder can image collection Pixel points in the impurity area of ​​the milk powder can image Gray level; based on the gray level map, the level evaluation value corresponding to the initial gray level number is calculated, and the level evaluation value satisfies the relationship: ,in, This is the first image in the milk powder can image collection The impurity area of ​​the milk powder can image, This is the first image in the milk powder can image collection The non-impurity area of ​​the milk powder can image, For the Pixel points in the impurity area of ​​the milk powder can image The gray level, For the Pixel points in the non-impurity area of ​​the milk powder can image The gray level, For the The standard deviation of the gray level in the impurity area of ​​the milk powder can image is For the The standard deviation of the gray level in the non-impurity area of ​​the milk powder can image is is the number of all milk powder can images in the milk powder can image set, is the initial gray level number The series evaluation value; based on the series evaluation value, the objective function is constructed, and the objective function satisfies the relationship: ,in, is the value of the objective function; the objective function is solved by the optimization algorithm, and the initial grayscale number corresponding to the maximum value of the level evaluation value is taken as the grayscale target number.

2. A method for detecting foreign matter in a milk powder can according to claim 1, characterized in that: The grayscale intervals of non-impurities in the milk powder area and the tank wall area are counted separately: For the grayscale image corresponding to any milk powder can image in the milk powder can image set, count the number of occurrences of all grayscales corresponding to the non-impurity area in the target area, where the target area is the milk powder area or the can wall area; Traverse the grayscale images corresponding to all milk powder can images, calculate the sum of the number of occurrences to obtain the total number of occurrences of each grayscale in the non-impurity area of ​​the corresponding target area; Calculate the mean and variance of all occurrences, and determine the normal interval based on the mean and variance; In response to the total number of occurrences being within a normal interval, deleting the gray level corresponding to the total number of occurrences; In response to the total number of occurrences not being within the normal interval, the grayscale corresponding to the total number of occurrences is marked as a non-impurity grayscale, and all non-impurity grayscales constitute a non-impurity grayscale interval of the corresponding target area.

3. A method for detecting foreign matter in a milk powder can according to claim 2, characterized in that: The normal range is ,in, is the mean of all the total number of occurrences, is the variance of the total number of occurrences.

4. A method for detecting foreign matter in a milk powder can according to claim 1, characterized in that: The real-time milk powder area and the real-time tank wall area in the real-time image of the milk powder tank include: Obtain the rectangular frames of the milk powder area and the can wall area in the real-time image of the milk powder can based on the trained object detection network; The real-time image of the milk powder can is cropped according to the rectangular frame to obtain the real-time milk powder area and the real-time can wall area in the real-time image of the milk powder can.

5. A method for detecting foreign matter in a milk powder can according to claim 1, characterized in that: For a gray level in the real-time milk powder gray level image, the calculation method of the interval distance between the gray level and the corresponding non-impurity gray level interval includes: Acquire a non-impurity grayscale interval of a milk powder region, where the non-impurity grayscale interval includes a plurality of non-impurity grayscale levels; The Euclidean distance between the gray level and each non-impurity gray level is calculated, and the minimum value of the Euclidean distance is used as the interval distance between the gray level and the corresponding non-impurity gray interval.

6. A method for detecting foreign matter in a milk powder can according to claim 5, characterized in that: For a gray level in the real-time milk powder gray level image, the calculation method of the gray level area size vector includes: In the real-time grayscale image of milk powder, count the number of occurrences of connected regions of different grayscale sizes; After normalizing the number of occurrences, the occurrence frequencies of connected regions of different sizes at gray levels are obtained; The region size vector corresponding to the gray level is constructed according to the occurrence frequency of connected regions of different sizes.

7. A method for detecting foreign matter in a milk powder can according to claim 6, characterized in that: The impurity detection results based on the frequency, interval distance and region size vector of each gray level include: Calculate a first impurity judgment index based on the frequency of each gray level in the real-time milk powder gray level map, the interval distance from the non-impurity gray level interval of the milk powder area, and the area size vector, and compare the first impurity judgment index with the first set threshold to obtain a milk powder area detection result, the milk powder area detection result includes a milk powder area with impurities and a milk powder area without impurities; The second impurity judgment index is calculated based on the frequency of each gray level in the real-time tank wall gray level map, the interval distance from the non-impurity gray level interval of the tank wall area, and the area size vector, and the tank wall area detection result is obtained by comparing the second impurity judgment index with the second set threshold. The tank wall area detection result includes the presence of impurities in the tank wall area and the absence of impurities in the tank wall area; The impurity detection results are obtained based on the milk powder area detection results and the tank wall area detection results.

8. A method for detecting foreign matter in a milk powder can according to claim 7, characterized in that: The first impurity judgment index satisfies the relationship: ,in, is the number of all gray levels in the real-time milk powder gray level map, Grayscale The frequency, Grayscale The interval distance from the non-impurity gray interval in the milk powder area, Grayscale in the real-time milk powder grayscale image The information entropy of the corresponding region size vector, It is the first impurity judgment indicator.

9. A method for detecting foreign matter in a milk powder can according to claim 8, characterized in that: The milk powder area detection result obtained by comparing the first impurity judgment index with the first set threshold value includes: In response to the first impurity judgment index being greater than the first set threshold, the milk powder area detection result is that there are impurities in the milk powder area; In response to the first impurity judgment index being not greater than the first set threshold, the milk powder area detection result is that the milk powder area is free of impurities.

10. A foreign body detection system in a milk powder can, characterized in that: include: A processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the method for detecting foreign matter in a milk powder can according to any one of claims 1 to 9 is implemented.

Citation Information

Patent Citations

  • Milk powder quality detection method and system based on convolutional neural network

    CN117522838A

  • Infant food safety visual detection method

    CN116912820A

  • Milk powder quality visual detection method and system

    CN118691607A