Food foreign matter detection method and device, computer device and storage medium
By performing binarization processing and morphological feature analysis on food images, the problem of low accuracy in foreign object detection in food was solved, achieving efficient foreign object identification and improved accuracy.
Patent Information
- Application Number
- CN202210495396.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-07
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2042-05-07
AI Technical Summary
Existing technologies for detecting foreign objects in food have low accuracy, and manual selection leads to high costs and is prone to missed or false detections.
By acquiring the image to be detected, binarization is performed using different grayscale thresholds to identify the contours and contour center points in the image. The presence of foreign objects is determined by combining morphological feature analysis, including preprocessing steps such as median filtering, contrast enhancement, and gamma correction.
It improves the accuracy of foreign object detection in food, avoids missed detections, and reduces the cost of manual intervention and the false detection rate.
Smart Images

Figure CN115082819B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image recognition, in particular to a food foreign matter detection method and device, computer equipment and computer readable storage medium. BACKGROUND
[0002] With the rapid development of artificial intelligence technology in recent years, intelligent empowerment for various industries is being carried out in various parts of the country.
[0003] Food foreign matter refers to substances mixed in food other than food itself, which cannot be digested by the human body and is extremely likely to cause physical harm to the human body. As a typical representative of non-destructive testing, X-ray machine plays an important role in various types of food foreign matter detection. However, in X-ray machine foreign matter detection, manual selection of food foreign matter will lead to serious cost problems, as well as missed detection and false detection problems caused by visual fatigue of the human eye. SUMMARY
[0004] The technical problem solved by the present application is to provide a food foreign matter detection method, device, computer equipment and computer readable storage medium, which solves the problem of low accuracy of food foreign matter detection in the prior art.
[0005] To solve the above technical problems, the first technical solution adopted by the present application is to provide a food foreign matter detection method, which includes: obtaining a to-be-detected image, the to-be-detected image including to-be-detected food; performing binaryzation processing on the to-be-detected image based on different gray threshold values to obtain a mask image set of the to-be-detected image, the mask image set including multiple binary mask images of the to-be-detected image; performing contour recognition on each binary mask image in the mask image set to obtain contour detection information corresponding to each binary mask image; and determining whether there is foreign matter in the to-be-detected food based on the morphological features of the contour detection information.
[0006] Among them, the to-be-detected image is an image scanned by any of X-ray, alpha-ray, beta-ray and gamma-ray on the to-be-detected food; the binaryzation processing on the to-be-detected image based on different gray threshold values to obtain the mask image set of the to-be-detected image, the mask image set including multiple binary mask images of the to-be-detected image, includes: selecting multiple gray threshold values within the gray value range of the to-be-detected image; and performing binaryzation processing on the to-be-detected image according to the multiple gray threshold values to obtain a binary mask image corresponding to each gray threshold value.
[0007] The contour detection information includes a contour and a contour center point; the contour recognition is performed on each binary mask image in the mask image set respectively to obtain the contour detection information corresponding to each binary mask image respectively, including: performing edge contour recognition on the binary mask image to obtain the contour and the contour center point corresponding to the binary mask image; after the contour recognition is performed on each binary mask image in the mask image set respectively to obtain the contour detection information corresponding to each binary mask image respectively, based on the morphological features of the contour detection information, it is further determined whether the foreign matter candidate contour corresponding to the contour center point exists in the food to be detected.
[0008] The determination of whether the contour corresponding to the contour center point is the foreign matter candidate contour based on the position of the contour center point includes: judging whether the number of contour center points with a distance less than a preset value between the selected contour center point and other contour center points in the mask image set reaches a preset number; if the number of contour center points with a distance less than a preset value reaches a preset number, the contour corresponding to the selected contour center point is determined as the foreign matter candidate contour.
[0009] The determination of whether the contour corresponding to the contour center point is the foreign matter candidate contour based on the position of the contour center point includes: judging whether the number of contour center points with a distance less than a preset value between the selected contour center point and other contour center points in the mask image set reaches a preset number; if the number of contour center points with a distance less than a preset value reaches a preset number, the contour corresponding to the selected contour center point is determined as the foreign matter candidate contour.
[0010] The morphological data includes a contour area and a contour circularity; and the determination of whether the foreign matter candidate contour exists in the food to be detected in response to the similarity between the morphological data of the foreign matter candidate contour and the preset morphological data exceeding a similarity threshold value includes: in response to the contour area being greater than an area of a preset number of pixels and the contour circularity being greater than a threshold value, it is determined that the foreign matter exists in the food to be detected.
[0011] The mask image set of the image to be detected is obtained by performing binaryzation processing on the image to be detected based on different gray threshold values; and the mask image set of the image to be detected is obtained by performing binaryzation processing on the image to be detected based on different gray threshold values, including: performing binaryzation processing on the preprocessed image based on different gray threshold values to obtain the mask image set of the image to be detected.
[0012] The binarization processing is performed on the image to be detected based on different gray threshold values to obtain a mask image set of the image to be detected.
[0013] The contrast enhancement processing is performed on the image to be detected to obtain a foreign matter enhanced image corresponding to the image to be detected, including: performing contrast stretching processing on the image to be detected to obtain a contrast enhanced image; performing normalization processing on the contrast enhanced image to obtain a normalized image; and performing gamma correction and inverse normalization processing on the normalized image to obtain the foreign matter enhanced image.
[0014] The contrast stretching processing is performed on the image to be detected to obtain a contrast enhanced image, including: compressing a gray level display range corresponding to the image to be detected to obtain the contrast enhanced image.
[0015] To solve the above technical problems, a third technical solution adopted by the present application is to provide a food foreign matter detection device, which comprises: an acquisition module configured to acquire an image to be detected, the image to be detected comprising a food to be detected; a binarization module configured to perform binarization processing on the image to be detected based on different gray threshold values to obtain a mask image set of the image to be detected, the mask image set comprising a plurality of binarization mask images of the image to be detected; a detection module configured to perform contour recognition on each binarization mask image in the mask image set to obtain contour detection information corresponding to each binarization mask image; and an analysis module configured to determine whether a foreign matter exists in the food to be detected based on morphological features of the contour detection information.
[0016] To solve the above technical problems, a third technical solution adopted by the present application is to provide a computer device, which comprises a memory, a processor, and a computer program stored in the memory and running on the processor, the processor being configured to execute program data to implement the steps in the above food foreign matter detection method.
[0017] To solve the above technical problems, a fourth technical solution adopted by the present application is to provide a computer readable storage medium, which stores a computer program, the computer program being executed by a processor to implement the steps in the above food foreign matter detection method.
[0018] The beneficial effects of the present application are: different from the prior art, the food foreign matter detection method, device, computer equipment and computer readable storage medium provided by the present application, the food foreign matter detection method comprises: acquiring a to-be-detected image, the to-be-detected image comprising a to-be-detected food; based on different gray threshold values, the to-be-detected image is binarized respectively to obtain a mask image set of the to-be-detected image, the mask image set comprising a plurality of binary mask images of the to-be-detected image; the contour recognition is performed on each binary mask image in the mask image set respectively to obtain the contour detection information corresponding to each binary mask image respectively; based on the morphological features of the contour detection information, it is determined whether there is a foreign matter in the to-be-detected food. The present application binarizes the to-be-detected image through different gray threshold values to obtain a plurality of binary mask images, and determines whether there is a foreign matter in the to-be-detected food through the morphological features of the contours in the plurality of binary mask images, which can avoid missing detection of foreign matters, and further improve the detection accuracy of foreign matters. BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0020] Figure 1 is a flowchart of the food foreign matter detection method provided by the present application;
[0021] Figure 2 is a flowchart of an embodiment of the food foreign matter detection method provided by the present application;
[0022] Figure 3 is Figure 2 is a flowchart of a specific embodiment of step S203 in the food foreign matter detection method provided by the present application;
[0023] Figure 4 is a flowchart of a specific embodiment of the food foreign matter detection method provided by the present application;
[0024] Figure 5 is a schematic block diagram of the food foreign matter detection device provided by the present application;
[0025] Figure 6 is a schematic block diagram of an embodiment of the food foreign matter detection device provided by the present application;
[0026] Figure 7 is a schematic block diagram of an embodiment of the computer equipment provided by the present application;
[0027] Figure 8is a schematic block diagram of an embodiment of the computer readable storage medium provided by the present application. DETAILED DESCRIPTION
[0028] The scheme of the embodiment of the present application will be described in detail below with reference to the accompanying drawings of the specification.
[0029] In the following description, specific details are set forth in order to provide a thorough understanding of the present application, but the present application can be practiced without these particulars. References to specific structure, interfaces, techniques, etc., are not intended to limit the scope of the application, which is defined solely by the appended claims, along with the full range of equivalents to which they are entitled.
[0030] The term "and / or", used herein merely describes an associated relationship between associated objects, and means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, the character " / " herein generally means that the front and rear associated objects are in an "or" relationship. In addition, "multiple" herein means two or more than two.
[0031] In order for those skilled in the art to better understand the technical solutions of the present application, a food foreign matter detection method provided by the present application is further described in detail below in combination with the drawings and specific embodiments.
[0032] Please refer to Figure 1 , Figure 1 is a flowchart of the food foreign matter detection method provided by the present application. The present embodiment provides a food foreign matter detection method, which comprises the following steps.
[0033] S11: Obtain a to-be-detected image.
[0034] Specifically, the to-be-detected image comprises a to-be-detected food. The to-be-detected image is an image scanned by any one of X-ray, alpha ray, beta ray and gamma ray on the to-be-detected food.
[0035] In an embodiment, the to-be-detected image is denoised by a median filtering method to obtain a preprocessed image.
[0036] In an embodiment, the to-be-detected image is subjected to contrast enhancement processing to obtain a foreign matter enhanced image corresponding to the to-be-detected image.
[0037] In a specific embodiment, the to-be-detected image is subjected to contrast stretching processing to obtain a contrast enhanced image; the contrast enhanced image is subjected to normalization processing to obtain a normalized image; the normalized image is subjected to gamma correction and inverse normalization processing to obtain a foreign matter enhanced image.
[0038] The gray level display range corresponding to the to-be-detected image is compressed to obtain a contrast enhanced image. The to-be-detected image is subjected to contrast stretching processing based on the following formula to obtain a contrast enhanced image.
[0039]
[0040] In the formula, g(i, j) is an output image; f(i, j) is an input image; m is a gray mean value of the image to be detected; and the value of E is 0.8, 1.2 or 1.6, which is determined according to actual conditions.
[0041] S12: The image to be detected is binarized based on different gray threshold values to obtain a mask image set of the image to be detected.
[0042] Specifically, the mask image set includes multiple binarized mask images of the image to be detected.
[0043] In an embodiment, multiple gray threshold values are selected within a gray value range of the image to be detected; and the image to be detected is binarized based on the multiple gray threshold values to obtain a binarized mask image corresponding to each gray threshold value.
[0044] In a specific embodiment, the preprocessed image is binarized based on different gray threshold values to obtain the mask image set of the image to be detected.
[0045] In a specific embodiment, the foreign matter enhanced image is binarized based on different gray threshold values to obtain the mask image set of the image to be detected.
[0046] S13: Each binarized mask image in the mask image set is subjected to contour recognition to obtain contour detection information corresponding to each binarized mask image.
[0047] Specifically, the contour detection information includes a contour and a contour center point. The binarized mask image is subjected to edge contour recognition to obtain a contour and a contour center point corresponding to the binarized mask image; and whether the corresponding contour is a foreign matter candidate contour is determined based on the contour center point.
[0048] In a specific embodiment, it is determined whether a number of contour center points with a distance less than a preset value from other contour center points in the mask image set reaches a preset number; and if the number of contour center points with the distance less than the preset value reaches the preset number, the contour corresponding to the selected contour center point is determined as a foreign matter candidate contour.
[0049] S14: Whether a foreign matter exists in the food to be detected is determined based on a morphological feature of the contour detection information.
[0050] Specifically, a morphological feature of the foreign matter candidate contour is detected to obtain morphological data of the foreign matter candidate contour; and in response to a similarity between the morphological data of the foreign matter candidate contour and preset morphological data exceeding a similarity threshold value, it is determined that a foreign matter exists in the food to be detected.
[0051] In a specific embodiment, the shape data includes a contour area and a contour roundness; in response to the contour area being greater than an area of a preset number of pixels and the contour roundness being greater than a threshold value, it is determined that there is a foreign matter in the food to be detected.
[0052] The food foreign matter detection method provided in this embodiment includes obtaining a to-be-detected image, the to-be-detected image including a food to be detected; performing binarization processing on the to-be-detected image based on different gray threshold values to obtain a mask image set of the to-be-detected image, the mask image set including a plurality of binarization mask images of the to-be-detected image; performing contour recognition on each binarization mask image in the mask image set to obtain contour detection information corresponding to each binarization mask image; and determining whether there is a foreign matter in the food to be detected based on a shape feature of the contour detection information. The to-be-detected image is binarized by different gray threshold values to obtain a plurality of binarization mask images, and whether there is a foreign matter in the food to be detected is determined based on the shape feature of the contour in the plurality of binarization mask images, so that the foreign matter can be avoided from being missed, and the detection accuracy of the foreign matter is improved.
[0053] Please refer to Figure 2 , Figure 2 is a flowchart of an embodiment of the food foreign matter detection method provided in the present application. The food foreign matter detection method provided in this embodiment includes the following steps.
[0054] S201: Obtain a to-be-detected image.
[0055] Specifically, the to-be-detected image includes a food to be detected. The to-be-detected image is an image scanned by any one of X-ray, alpha ray, beta ray and gamma ray on the food to be detected.
[0056] The food in this embodiment is a solid food with uniform density, and the shape of the food can be a cylinder, a cone or a sphere, such as a milk piece, a cake, chocolate, a candy, etc. The thickness of the food can be preferably 2-4 mm. During the production, processing, packaging and transportation of the food, a foreign matter that cannot be digested by the human body and can cause physical harm to the human body can be introduced. The foreign matter is contained in the food, the volume of the foreign matter should be smaller than that of the food itself, and the foreign matter cannot be directly observed by the naked eye. In order to realize accurate detection, the density of the foreign matter should be different from that of the food itself, and preferably the density of the foreign matter is significantly different from that of the food itself, such as metal, ceramic, glass, plastic, sandstone, etc. The foreign matter is further preferably metal, such as iron wire, iron filings, iron sheet, copper wire, lead block, etc.
[0057] In a specific embodiment, the food to be sold is detected by an X-ray machine to obtain an X-ray scanning image of the food to be detected. In the X-ray scanning image of the food, the most obvious feature of the foreign matter is the local abnormality of the gray intensity, which is obviously different from the background of the food. Therefore, whether the abnormal area is foreign matter can be determined by analyzing multiple features of the abnormal area.
[0058] S202: The image to be detected is denoised by a median filter to obtain a preprocessed image.
[0059] Specifically, due to the reasons of system hardware, there are often a large amount of noise in the general X-ray scanning image, so it is necessary to first denoise the obtained image to be detected. The neighborhood average method, modulus maximum reconstruction filter, spatial correlation filter, and wavelet domain threshold filter can be used to denoise the image to be detected.
[0060] In order to improve the denoising effect and the accuracy of foreign matter detection, in this embodiment, a median filter with good denoising effect is used as a denoising operator to denoise the image to be detected to obtain a preprocessed image. The median filter can remove noise and protect the edges of the image, thereby obtaining a satisfactory restoration effect, and in the actual operation process, the statistical characteristics of the image to be detected are not required, which brings a lot of convenience. Moreover, the median filter can filter the sharp pulses. The filtered data retains the change trend of the original image, and at the same time, the influence of the sharp pulses on the analysis is removed.
[0061] Since the denoising effect of the median filter and the shape and size of the window are strongly related, in order to make the denoising effect better, the shape and size of the window are set to a 3*3 template. The shape and size of the window can be set according to the actual situation. Specifically, the gray values of an odd number of pixel points in the 3*3 sampling window of the image to be detected are taken out, and the gray values are sorted; the middle gray value is selected to replace the gray value of the middle pixel point in the sampling window.
[0062] S203: Contrast enhancement processing is performed to obtain a foreign matter enhanced image corresponding to the image to be detected.
[0063] Specifically, in order to make the imaging difference between the foreign matter and the food background more obvious, the image to be detected needs to be subjected to contrast enhancement processing. The specific steps are as follows.
[0064] Please refer to Figure 3 , Figure 3 is Figure 2 the flowchart of a specific embodiment of step S203 in the food foreign matter detection method provided by the application.
[0065] S2031: The image to be detected is subjected to contrast stretching processing to obtain a contrast enhanced image.
[0066] Specifically, in order to increase the imaging difference between foreign matter and food background, the gray level display range corresponding to the image to be detected is compressed to obtain a contrast-enhanced image.
[0067] In an embodiment, the contrast of the image to be detected can be stretched based on formula 1 to obtain a contrast-enhanced image.
[0068]
[0069] In the formula, g(i, j) is the output image, f(i, j) is the input image, m is the gray mean value of the image to be detected, and E is 0.8, 1.2 or 1.6, which is determined according to actual conditions.
[0070] S2032: Normalizing the contrast-enhanced image to obtain a normalized image.
[0071] Specifically, in order to facilitate calculation and eliminate the dimensional influence between indicators, data standardization processing is needed to solve the comparability between data indicators. After the original data is processed by data standardization, each indicator is in the same order of magnitude, which is suitable for comprehensive comparison and evaluation. That is, the pixel value in the contrast-enhanced image is converted to a real number between 0 and 1.
[0072] In an embodiment, the pixel value of each pixel point in the contrast-enhanced image can be normalized based on formula 2 to obtain a normalized image.
[0073]
[0074] In the formula, g(i, j) is the output image, and f(i, j) is the input image.
[0075] S2033: Gamma correction and inverse normalization of the normalized image to obtain a foreign matter-enhanced image.
[0076] Specifically, the normalized image can be pre-compensated, and the real value of the pre-compensated image is inversely transformed to an integer value between 0 and 255 to obtain a foreign matter-enhanced image.
[0077] In an embodiment, the pixel value in the normalized image can be gamma pre-compensated based on formula 3.
[0078]
[0079] In the formula, g(i, j) is the output image, f(i, j) is the input image, and r is a parameter set by a person.
[0080] In an embodiment, the pixel value of each pixel point in the pre-compensated image can be inversely normalized based on formula 4 to obtain a foreign matter enhanced image.
[0081] g(i,j) = f(i,j) x 256 - 0.5 (Formula 4)
[0082] In the formula, g(i,j) is an output image, and f(i,j) is an input image.
[0083] Through the above steps, the acquired to-be-detected image can be subjected to contrast enhancement processing to increase the difference between the foreign matter and the food background, thereby improving the detection accuracy of the foreign matter in the to-be-detected food.
[0084] S204: Selecting a plurality of gray threshold values in the gray value range of the to-be-detected image.
[0085] Specifically, in order to improve the detection accuracy of the foreign matter in the to-be-detected food, a binary image pyramid needs to be constructed. In the gray value range of the to-be-detected image, a plurality of gray threshold values can be selected based on a set step s, so as to facilitate subsequent construction of a binary image pyramid.
[0086] In a specific embodiment, the gray value range corresponding to the to-be-detected image is [T1, T2], and the plurality of gray threshold values selected based on the step s are [T1, T1+s, T1+2s, T1+3s,..., T2] respectively.
[0087] S205: Binaryzation processing the to-be-detected image according to the plurality of gray threshold values respectively to obtain a binary mask image corresponding to each gray threshold value.
[0088] Specifically, the to-be-detected image is subjected to binaryzation processing according to the gray threshold values obtained in the above step S204, to obtain a binary mask image corresponding to each gray threshold value.
[0089] In a specific embodiment, all pixel points in the to-be-detected image are traversed, the gray value of the pixel point is compared with the gray threshold value, the pixel point with a gray value greater than the gray threshold value is assigned a value of 1, and the pixel point with a gray value not greater than the gray threshold value is assigned a value of 0, thereby obtaining a binary mask image corresponding to each gray threshold value. A binary image pyramid is constructed through the binary mask images corresponding to all gray threshold values. The constructed binary image pyramid is a mask image set.
[0090] S206: Performing edge contour recognition on the binary mask image to obtain a contour and a contour center point corresponding to the binary mask image.
[0091] Specifically, since the grayscale values of the foreign matter and the food background are different, the values of different pixel points are different after the to-be-detected image is binarized. Based on different values, the outlines of the patterns formed in the binarization mask image are different. The binarization mask image can be subjected to edge contour analysis, and then it is determined whether the to-be-detected image contains foreign matter based on the shape of the contour.
[0092] In an embodiment, the contour detection is performed on all binarization mask images in the binarization image pyramid respectively, to obtain the contours corresponding to the binarization mask images. The center point positions of the contours are detected, to obtain the position coordinates of the contour center points corresponding to the contours. The position coordinates of the contour center points are the position coordinates in the binarization mask image.
[0093] S207: Determine whether the number of contour center points with a distance less than a preset value between the selected contour center point and other contour center points in the mask image set reaches a preset number.
[0094] Specifically, in order to preliminarily determine whether the contour pattern is a foreign matter, it is necessary to count the distances between the contour center points corresponding to the binarization mask images in the mask image set.
[0095] The contour center points corresponding to all binarization mask images in the mask image set are traversed, a contour center point corresponding to a binarization mask image is selected, and the distance between the selected contour center point and other contour center points in the mask image set is calculated.
[0096] It is determined whether the distance between the selected contour center point and other contour center points in the mask image set is less than a preset value. The preset value can be the length of 5 pixel points. The preset value can also be set according to actual conditions. If the distance between the selected contour center point and other contour center points in the mask image set is less than the preset value, it is determined that the selected contour center point and the contour center point corresponding to the distance less than the preset value are at the same position.
[0097] The number of center points with a distance less than the preset value from the selected contour center point in the mask image set is counted, and it is determined whether the number of counted center points reaches a preset number. The preset number can be two or multiple. The preset number can be set according to actual conditions.
[0098] If the number of contour center points with a distance less than the preset value between the selected binarization mask image and other binarization mask images in the mask image set reaches the preset number, the process directly jumps to step S208; if the number of contour center points with a distance less than the preset value between the selected binarization mask image and other binarization mask images in the mask image set does not reach the preset number, the process directly jumps to step S209.
[0099] S208: Determine the contour corresponding to the selected binary mask image as a foreign matter candidate contour.
[0100] Specifically, if the number of contour center points with a distance less than the preset value between the contour center point of the selected binary mask image and the contour center points of other binary mask images in the mask image set reaches a preset number, the contour corresponding to the selected binary mask image is determined as a foreign matter candidate contour.
[0101] S209: Delete the contour corresponding to the selected binary mask image.
[0102] Specifically, if the number of contour center points with a distance less than the preset value between the contour center point of the selected binary mask image and the contour center points of other binary mask images in the mask image set does not reach the preset number, the selected binary mask image is deleted.
[0103] S210: Perform morphological feature detection on the foreign matter candidate contour to obtain morphological data of the foreign matter candidate contour.
[0104] Specifically, morphological feature detection is performed on the foreign matter candidate contour obtained through the above step S208, and feature information of the foreign matter candidate contour is extracted to obtain morphological data of the foreign matter candidate contour.
[0105] In an embodiment, the morphological data can include contour shape. The shape of the detected foreign matter candidate contour can be compared with the shape of a preset foreign matter in a database, and then it is determined whether the foreign matter candidate contour is the contour of a foreign matter.
[0106] In an embodiment, the morphological data can include contour area and contour circularity. When the foreign matter candidate contour is detected, the contour area and the contour perimeter can be directly detected.
[0107] Specifically, the contour circularity of the foreign matter candidate contour can be calculated based on formula 5.
[0108]
[0109] In the formula, s represents the contour area, p represents the contour perimeter, and c represents the circularity. The closer c is to 1, the closer the contour is to a circle.
[0110] S211: In response to the similarity of the morphological data of the foreign matter candidate contour and the preset morphological data exceeding a similarity threshold, it is determined that a foreign matter exists in the food to be detected.
[0111] Specifically, the shape data of the foreign matter candidate contour is compared with preset shape data, and it is determined whether the foreign matter candidate contour is a foreign matter, and it is further determined whether the foreign matter exists in the food to be detected.
[0112] In a specific embodiment, if the similarity between the shape of the foreign matter candidate contour and the shape of the preset foreign matter in the database reaches a similarity threshold, it is determined that the foreign matter candidate contour is a contour of a foreign matter, and it is further determined that the foreign matter exists in the food to be detected.
[0113] In a specific embodiment, if the contour area of the foreign matter candidate contour is greater than the area of a preset number of pixels, and the contour circularity of the foreign matter candidate contour is greater than a threshold, it is determined that the foreign matter candidate contour is a contour of a foreign matter, and it is further determined that the foreign matter exists in the food to be detected.
[0114] Please refer to Figure 4 , Figure 4 is a flowchart of a specific embodiment of the food foreign matter detection method provided by the present application.
[0115] In a specific embodiment, the food to be detected is subjected to X-ray scanning by an X-ray machine to obtain a food X-ray machine image. The X-ray scanning image of the food is subjected to image denoising by a median filter, and the image after denoising processing is subjected to contrast stretching processing to obtain a foreign matter enhanced image. Based on the gray value range of the foreign matter enhanced image, a plurality of gray threshold values are determined, and the foreign matter enhanced image is subjected to binarization processing based on the gray threshold values to obtain a plurality of binarization mask images, and a binary image pyramid is constructed by the plurality of binarization mask images obtained. The contour and contour center point of all binarization mask images in the binary image pyramid are detected respectively to obtain the contour and contour center point corresponding to each binarization mask image. One contour center point is selected, and the distance between the contour center point and the contour center points corresponding to all binarization mask images in the mask image set is counted, and the number of contour center points with a distance less than 5 pixel points from the selected contour center point is counted. If the number of contour center points with a distance less than 5 pixel points from the selected contour center point is greater than 2, it is determined that the contour corresponding to the selected contour center point is a foreign matter candidate contour. The contour area and contour circularity of the foreign matter candidate contour are obtained by contour analysis. If the contour area of the foreign matter candidate contour is greater than the area of a preset number of pixels, and the contour circularity of the foreign matter candidate contour is greater than a threshold, it is determined that the foreign matter candidate contour is a contour of a foreign matter, and it is further determined that the foreign matter exists in the food to be detected.
[0116] In this embodiment, a plurality of binarization mask images are used as the basis for contour detection, which makes the food foreign matter detection method have strong anti-noise ability; and after shape analysis and processing of the contour, the false detection probability can be greatly reduced.
[0117] The food foreign matter detection method provided in the embodiment comprises: acquiring a to-be-detected image, the to-be-detected image comprising to-be-detected food; performing binaryzation processing on the to-be-detected image based on different gray threshold values respectively to obtain a mask image set of the to-be-detected image, the mask image set comprising a plurality of binaryzation mask images of the to-be-detected image; performing contour recognition on each binaryzation mask image in the mask image set respectively to obtain contour detection information corresponding to each binaryzation mask image respectively; and determining whether there is foreign matter in the to-be-detected food based on the morphological features of the contour detection information. The to-be-detected image is binaryzation processed by different gray threshold values to obtain a plurality of binaryzation mask images, and whether there is foreign matter in the to-be-detected food is determined based on the morphological features of the contours in the plurality of binaryzation mask images, so that foreign matter missed detection can be avoided, and the detection accuracy of foreign matter is improved.
[0118] Please refer to Figure 5 , Figure 5 is a schematic block diagram of the food foreign matter detection device provided in the embodiment. The food foreign matter detection device 60 comprises an acquisition module 61, a binaryzation module 62, a detection module 63 and an analysis module 64.
[0119] The acquisition module 61 is configured to acquire a to-be-detected image, the to-be-detected image comprising to-be-detected food. The to-be-detected image is an image scanned by any one of X-ray, alpha ray, beta ray and gamma ray on the to-be-detected food.
[0120] The binaryzation module 62 is configured to perform binaryzation processing on the to-be-detected image based on different gray threshold values respectively to obtain a mask image set of the to-be-detected image, the mask image set comprising a plurality of binaryzation mask images of the to-be-detected image.
[0121] Specifically, the binaryzation module 62 is configured to select a plurality of gray threshold values in the gray value range of the to-be-detected image; and perform binaryzation processing on the to-be-detected image according to the plurality of gray threshold values respectively to obtain a binaryzation mask image corresponding to each gray threshold value.
[0122] The detection module 63 is configured to perform contour recognition on each binaryzation mask image in the mask image set respectively to obtain contour detection information corresponding to each binaryzation mask image respectively. The contour detection information comprises a contour and a contour center point.
[0123] Specifically, the detection module 63 is configured to perform edge contour recognition on the binary mask image to obtain a contour corresponding to the binary mask image and a contour center point of the contour; and determine whether the contour is a foreign matter candidate contour based on the contour center point. In an embodiment, the detection module 63 is configured to determine whether a number of contour center points with a distance less than a preset value from the selected contour center point and other contour center points in the mask image set reaches a preset number; and if the number of contour center points with the distance less than the preset value reaches the preset number, determine the contour corresponding to the selected contour center point as the foreign matter candidate contour.
[0124] The analysis module 64 is configured to determine whether there is a foreign matter in the food to be detected based on a morphological feature of the contour detection information.
[0125] Specifically, the analysis module 64 is configured to perform morphological feature detection on the foreign matter candidate contour to obtain morphological data of the foreign matter candidate contour; and determine that there is a foreign matter in the food to be detected in response to a similarity between the morphological data of the foreign matter candidate contour and preset morphological data exceeding a similarity threshold. In an embodiment, the morphological data includes a contour area and a contour circularity; and the analysis module 64 is configured to determine that there is a foreign matter in the food to be detected in response to the contour area being greater than an area of a preset number of pixels and the contour circularity being greater than a threshold.
[0126] Referring to Figure 6 , Figure 6 is a schematic block diagram of an embodiment of the food foreign matter detection device provided by the present application.
[0127] In another embodiment, the food foreign matter detection device 60 further includes a preprocessing module 65 configured to perform denoising processing on the to-be-detected image by a median filtering manner to obtain a preprocessed image, and perform contrast enhancement processing on the to-be-detected image to obtain a foreign matter enhanced image corresponding to the to-be-detected image. Specifically, the preprocessing module 65 is configured to perform contrast stretching processing on the to-be-detected image to obtain a contrast enhanced image; perform normalization processing on the contrast enhanced image to obtain a normalized image; and perform gamma correction and inverse normalization processing on the normalized image to obtain the foreign matter enhanced image.
[0128] Specifically, a gray level display range corresponding to the to-be-detected image is compressed to obtain the contrast enhanced image.
[0129] The food foreign matter detection device provided in the embodiment obtains a to-be-detected image, the to-be-detected image including to-be-detected food; performs binarization processing on the to-be-detected image based on different gray threshold values to obtain a mask image set of the to-be-detected image, the mask image set including a plurality of binarization mask images of the to-be-detected image; performs contour recognition on each binarization mask image in the mask image set to obtain contour detection information corresponding to each binarization mask image; and determines whether a foreign matter exists in the to-be-detected food based on a morphological feature of the contour detection information. The application performs binarization processing on the to-be-detected image based on different gray threshold values to obtain a plurality of binarization mask images, and determines whether a foreign matter exists in the to-be-detected food based on a morphological feature of the contour in the plurality of binarization mask images, so that foreign matter omission can be avoided, and the detection accuracy of the foreign matter is improved.
[0130] Referring to Figure 7 , Figure 7 is a schematic block diagram of an embodiment of the computer device. The computer device 80 includes a memory 81 and a processor 82 coupled to each other. The processor 82 is configured to execute program instructions stored in the memory 81 to implement the steps of any of the food foreign matter detection methods described above. In a specific implementation scenario, the computer device 80 can include but is not limited to a microcomputer, a server, and in addition, the computer device 80 can also include a notebook computer, a tablet computer and other mobile devices, which are not limited herein.
[0131] Specifically, the processor 82 is configured to control itself and the memory 81 to implement the steps of any of the training methods of the image detection model described above. The processor 82 can also be referred to as a CPU (Central Processing Unit). The processor 82 can be an integrated circuit chip with a processing capability of signals. The processor 82 can also be a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. In addition, the processor 82 can be implemented by an integrated circuit chip together.
[0132] Referring to Figure 8 , Figure 8is a schematic block diagram of an embodiment of the computer readable storage medium provided by the present application. The computer readable storage medium 90 stores program instructions 901 capable of being executed by a processor, and the program instructions 901 are used to implement the steps of any of the food foreign matter detection method embodiments described above.
[0133] In some embodiments, the device provided by the embodiments of the present disclosure has functions or includes modules that can be used to perform the methods described in the above method embodiments, and the specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.
[0134] The above description of various embodiments tends to emphasize the differences between various embodiments, and the same or similar parts can be mutually referred to. For the sake of brevity, it will not be repeated here.
[0135] In several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic, for example, the division of modules or units is only a logical function division, and in actual implementation, there can be another division manner, for example, a unit or component can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed each other can be indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0136] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0137] If the integrated unit is realized in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in the various embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0138] If the technical solution of the present application involves personal information, the product applying the technical solution of the present application has been explicitly informed of the personal information processing rules before processing the personal information, and has obtained the personal independent consent. If the technical solution of the present application involves sensitive personal information, the product applying the technical solution of the present application has obtained the personal independent consent before processing the sensitive personal information, and at the same time meets the requirement of "explicit consent". For example, at the personal information collection device such as camera, a clear and prominent mark is set to inform that the personal information collection range has been entered, and the personal information will be collected. If the individual voluntarily enters the collection range, it is considered to agree to collect the personal information. Or, on the device for processing personal information, the personal information processing rules are informed by using obvious marks / information, and the personal authorization is obtained by means of pop-up information or asking the individual to upload his / her personal information, etc. The personal information processing rules can include personal information processor, personal information processing purpose, processing method and personal information type, etc.
[0139] The above is only an embodiment of the present application, and does not limit the patent protection scope of the present application. Any equivalent structure or equivalent process transformation using the content of the specification and drawings of the present application, or direct or indirect application in other related technical fields, is also included in the patent protection scope of the present application.
Claims
1. A method of detecting a foreign matter in a food product, characterized by, The food foreign matter detection method comprises: acquiring a to-be-detected image, the to-be-detected image comprising a to-be-detected food; performing binarization processing on the to-be-detected image based on different grayscale thresholds respectively to obtain a mask image set of the to-be-detected image, the mask image set comprising a plurality of binarization mask images of the to-be-detected image; performing contour recognition on each binarization mask image in the mask image set respectively to obtain contour detection information corresponding to each binarization mask image respectively, the contour detection information comprising a contour and a contour center point; determining whether there is a foreign matter in the to-be-detected food based on morphological features of the contour detection information; wherein the contour recognition on each binarization mask image in the mask image set respectively to obtain contour detection information corresponding to each binarization mask image respectively comprises: performing edge contour recognition on the binarization mask image to obtain the contour corresponding to the binarization mask image and the contour center point; determining whether the contour corresponding to the contour center point is a foreign matter candidate contour based on a position of the contour center point; the determination of whether there is a foreign matter in the to-be-detected food based on the morphological features of the contour detection information comprises: performing morphological feature detection on the foreign matter candidate contour to obtain morphological data of the foreign matter candidate contour; in response to a similarity between the morphological data of the foreign matter candidate contour and preset morphological data exceeding a similarity threshold, determining that there is the foreign matter in the to-be-detected food.
2. The food foreign matter detection method according to claim 1, wherein the binarization processing on the to-be-detected image based on different grayscale thresholds respectively to obtain a mask image set of the to-be-detected image, the mask image set comprising a plurality of binarization mask images of the to-be-detected image comprises: selecting a plurality of grayscale thresholds in a grayscale value range of the to-be-detected image; performing binarization processing on the to-be-detected image according to the plurality of grayscale thresholds respectively to obtain the binarization mask image corresponding to each grayscale threshold.
3. The food foreign matter detection method according to claim 1, wherein the determination of whether the contour corresponding to the contour center point is a foreign matter candidate contour based on a position of the contour center point comprises: judging whether a number of the contour center points with a distance less than a preset value between the selected contour center point and other contour center points in the mask image set reaches a preset number; if the number of the contour center points with the distance less than the preset value reaches the preset number, determining that the contour corresponding to the selected contour center point is the foreign matter candidate contour.
4. The food foreign matter detection method according to claim 1, characterized by, the morphological data comprises a contour area and a contour circularity; the determination of whether there is a foreign matter in the to-be-detected food in response to a similarity between the morphological data of the foreign matter candidate contour and preset morphological data exceeding a similarity threshold comprises: in response to the contour area being greater than an area of a preset number of pixels and the contour circularity being greater than a threshold, determining that there is the foreign matter in the to-be-detected food.
5. The food foreign matter detection method according to claim 1, wherein The binarization processing of the image to be detected based on different gray scale thresholds respectively obtains a mask image set of the image to be detected, and the method further comprises: The image to be detected is denoised by median filtering to obtain a preprocessed image; The binarization processing of the image to be detected based on different gray scale thresholds respectively obtains a mask image set of the image to be detected, and the method further comprises: The binarization processing of the preprocessed image based on different gray scale thresholds respectively obtains a mask image set of the image to be detected.
6. The food foreign matter detection method according to claim 1 or 5, wherein the binarization processing of the image to be detected based on different gray scale thresholds respectively obtains a mask image set of the image to be detected, and the method further comprises: The image to be detected is subjected to contrast enhancement processing to obtain a foreign matter enhanced image corresponding to the image to be detected; The binarization processing of the image to be detected based on different gray scale thresholds respectively obtains a mask image set of the image to be detected, and the method further comprises: The binarization processing of the foreign matter enhanced image based on different gray scale thresholds respectively obtains a mask image set of the image to be detected.
7. The food foreign matter detection method according to claim 6, wherein the contrast enhancement processing of the image to be detected to obtain a foreign matter enhanced image corresponding to the image to be detected comprises: The image to be detected is subjected to contrast stretching processing to obtain a contrast enhanced image; The contrast enhanced image is subjected to normalization processing to obtain a normalized image; The normalized image is subjected to gamma correction and inverse normalization processing to obtain the foreign matter enhanced image.
8. The food foreign matter detection method according to claim 7, wherein the contrast stretching processing of the image to be detected to obtain a contrast enhanced image comprises: The gray scale level display range corresponding to the image to be detected is compressed to obtain the contrast enhanced image. The food foreign matter detection device comprises: An acquisition module configured to acquire an image to be detected, the image to be detected comprising a food to be detected; A binarization module configured to perform binarization processing on the image to be detected based on different gray scale thresholds respectively to obtain a mask image set of the image to be detected, the mask image set comprising a plurality of binarization mask images of the image to be detected; 9. A food foreign matter detection apparatus characterized by comprising: A detection module configured to perform contour recognition on each binarization mask image in the mask image set respectively to obtain contour detection information corresponding to each binarization mask image respectively, the contour detection information comprising a contour and a contour center point, and further configured to perform edge contour recognition on the binarization mask image to obtain the contour and the contour center point corresponding to the binarization mask image, and determine whether the contour corresponding to the contour center point is a foreign matter candidate contour based on the position of the contour center point. An analysis module is configured to determine whether there is a foreign matter in the food to be detected based on a morphological feature of the contour detection information, and to perform morphological feature detection on the foreign matter candidate contour to obtain morphological data of the foreign matter candidate contour, and to determine that the foreign matter exists in the food to be detected in response to a similarity between the morphological data of the foreign matter candidate contour and preset morphological data exceeding a similarity threshold.
10. A computer device, comprising: The computer device comprises a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor is configured to execute program data to implement the steps in the food foreign matter detection method according to any one of claims 1-8.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the steps in the food foreign matter detection method according to any one of claims 1-8.
Citation Information
Patent Citations
Image detection method and device, computer, readable storage medium and program product
CN114331951A
Device and method for inspection of foreign matter in flexible plastic container
JP2002122550A