Method and system for rapid detection of food foreign matter based on image features
By calculating the confidence of the shadow area and adjusting the gray value in food foreign matter detection, the problem of close gray value of the shadow area and foreign matter pixels is solved, and the accuracy of the detection results is improved.
Patent Information
- Application Number
- CN202410939905.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-15
AI Technical Summary
When the existing food foreign body detection method based on image features processes food images, due to the close gray value of the shadow area and foreign body pixels, the detection results after adaptive histogram equalization enhancement will be biased, especially in the case of food overlap and aggregation. It is difficult to distinguish accurately.
By obtaining the curve segment of the grayscale image and the extreme points of the curve segment, the confidence of each suspected shadow area is calculated, and the grayscale value is adjusted according to the adjustment coefficient of the pixel point gray value of the curve segment to reduce the enhancement of the shadow area. Strength, improve the accuracy of foreign object detection.
Effectively distinguish the causes of shadow areas, reduce the enhancement intensity of pixels in shadow areas, increase the enhancement intensity of foreign object pixels, and improve the accuracy of food foreign object detection results.
Smart Images

Figure CN118470024B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and system for quickly detecting foreign matter in food based on image features. Background Art
[0002] The research on food foreign body detection methods based on image features has always been a hot issue in the field of food safety. Domestic and foreign scholars have conducted extensive research on food foreign body detection methods, aiming to improve the accuracy and efficiency of detection. Although the image feature-based methods have achieved good results in food foreign body detection, there are still some problems.
[0003] In food images, shadow areas may be caused by the presence of foreign matter, or by the overlap and aggregation of food. The grayscale values of the pixels in the shadow area are close to those of the foreign matter. Using the existing adaptive histogram equalization for enhancement will cause the grayscale values of both the shadow area and the foreign matter pixels to be enhanced, thereby causing deviations in the subsequent food foreign matter detection results. Summary of the invention
[0004] In order to solve the above problems, the present invention provides a method and system for rapid detection of food foreign matter based on image features.
[0005] An embodiment of the present invention provides a method for rapid detection of foreign matter in food based on image features, the method comprising the following steps:
[0006] Obtain a grayscale image of the white asparagus to be detected;
[0007] The grayscale image is divided into several image blocks; according to the grayscale value of the pixel points in each column in each image block, the grayscale curve of each column in each image block is obtained; according to the extreme value point of the grayscale curve of each column, the curve segment of the grayscale curve of each column is obtained; the grayscale value with the largest number of pixels in the grayscale image is used as the main characteristic grayscale value of the grayscale image; according to the difference between the extreme value point of the grayscale curve of each column and the main characteristic grayscale value, all suspected shadow areas of each column are obtained; according to the grayscale value difference, slope and number of pixels between each curve segment and other curve segments in each suspected shadow area, the confidence of each curve segment in each suspected shadow area is obtained; according to the confidence of each curve segment in each suspected shadow area, the confidence of each suspected shadow area is obtained;
[0008] According to the number of pixels of each curve segment in each suspected shadow area, the confidence and the confidence of each suspected shadow area, the adjustment coefficient of the grayscale value of the pixel point of each curve segment in each suspected shadow area is obtained; according to the adjustment coefficient of the grayscale value of the pixel point of each curve segment and the main characteristic grayscale value, the adjusted grayscale value of each pixel point of each curve segment is obtained; according to the adjusted grayscale value of each pixel point of each curve segment, the enhanced image block is obtained;
[0009] The food foreign body detection is performed on the white asparagus to be detected based on the enhanced image blocks.
[0010] Preferably, the grayscale image is divided into a plurality of image blocks, including the specific method of:
[0011] Preset a parameter , use size The sliding window is moved in the grayscale image of the white asparagus to be detected with a step size of A sliding window operation is performed, and each sliding window is used as an image block of the grayscale image of the white asparagus to be detected, so as to obtain a plurality of image blocks of the grayscale image of the white asparagus to be detected.
[0012] Preferably, the grayscale curve of each column in each image block is obtained according to the grayscale value of the pixel points in each column in each image block, including the specific method of:
[0013] First In the image block The arrangement order of each pixel point in the column from top to bottom is the horizontal axis, and the gray value of the pixel point is the vertical axis; In the image block All pixel points in the column are input into the two-dimensional coordinate system, several data points are obtained, and a Bezier curve is constructed based on all the data points and recorded as Grayscale curve of the column.
[0014] Preferably, the step of obtaining the curve segment of the grayscale curve of each column according to the extreme value point of the grayscale curve of each column comprises the following specific methods:
[0015] For The grayscale curve of the column is subjected to Newton's method to obtain All extreme points of the grayscale curve of the column; Connect all the adjacent extreme points in the grayscale curve of the column to obtain the All curve segments of the grayscale curve of the column.
[0016] Preferably, the method of obtaining all suspected shadow areas of each column according to the difference between the extreme point of the grayscale curve of each column and the main characteristic grayscale value includes:
[0017] For Any extreme point of the grayscale curve of the column, the difference between the grayscale value of the extreme point and the main characteristic grayscale value is used as the first difference of the extreme point; The first extreme point of the grayscale curve of the column starts to traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point whose grayscale value is greater than the main characteristic grayscale value is taken as the The starting point of the first suspected shadow area of the grayscale curve of the column, starting from the starting point of the first suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point with the first difference greater than the main characteristic grayscale value is taken as the The end point of the first suspected shadow area of the grayscale curve of the column, and the starting point of the first suspected shadow area corresponds to the In the image block The pixel point in the column corresponds to the end point of the first shadow-like area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The first suspected shadow area of the column; starting from the end point of the first suspected shadow area, traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point with a grayscale value greater than the main feature grayscale value is taken as the The starting point of the second suspected shadow area of the grayscale curve of the column, starting from the starting point of the second suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point whose first difference is greater than the main characteristic grayscale value is taken as the The end point of the second suspected shadow area of the grayscale curve of the column is set to the starting point of the second suspected shadow area corresponding to the In the image block The pixel point in the column corresponds to the end point of the second suspected shadow area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The second suspected shadow area of the column is obtained; and so on, until the In the image block All suspected shaded areas of the column.
[0018] Preferably, the specific formula for obtaining the confidence of each curve segment in each suspected shadow area according to the gray value difference, slope and number of pixels between each curve segment and other curve segments in each suspected shadow area is:
[0019]
[0020] In the formula, Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. In the suspected shadow area The slope of a curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates taking the absolute value.
[0021] Preferably, the specific formula for obtaining the confidence of each suspected shadow area according to the confidence of each curve segment in each suspected shadow area is:
[0022]
[0023] In the formula, Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area.
[0024] Preferably, the specific formula for obtaining the adjustment coefficient of the grayscale value of the pixel point of each curve segment in each suspected shadow area according to the number of pixels of each curve segment in each suspected shadow area, the confidence level and the confidence level of each suspected shadow area is:
[0025]
[0026] In the formula, Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block The number of all pixels in the column; Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block The minimum confidence value of all suspected shadow areas in the column; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The minimum confidence value of all curve segments in the suspected shadow area; represents the linear normalization function.
[0027] Preferably, the specific formula for obtaining the adjusted grayscale value of each pixel point of each curve segment according to the adjustment coefficient of the grayscale value of the pixel point of each curve segment and the main characteristic grayscale value is:
[0028]
[0029] In the formula, Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel after adjustment; Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel; Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Represents the main feature grayscale value of the grayscale image of the white asparagus to be detected.
[0030] The present invention also proposes a rapid detection system for food foreign matter based on image features, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any step of the rapid detection method for food foreign matter based on image features when executing the computer program.
[0031] The beneficial effects of the technical solution of the present invention are as follows: the present invention obtains the confidence of each suspected shadow area according to the confidence of each curve segment in each suspected shadow area; this is used to distinguish the causes of the shadow area, avoiding the shadow area caused by the overlap and aggregation of food; according to the adjustment coefficient of the grayscale value of the pixel point of each curve segment and the main characteristic grayscale value, the adjusted grayscale value of each pixel point of each curve segment is obtained; according to the adjusted grayscale value of each pixel point of each curve segment, the enhanced image block is obtained; the enhancement intensity of the pixel points in the shadow area is reduced, and the enhancement intensity of the foreign body pixel points is increased, thereby improving the accuracy of the food foreign body detection result. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 The figure is a flowchart of the steps of the method for rapid detection of foreign matter in food based on image features of the present invention. DETAILED DESCRIPTION
[0034] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the method and system for rapid detection of foreign matter in food based on image features proposed by the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0035] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0036] The specific scheme of the method and system for rapid detection of foreign matter in food based on image features provided by the present invention is described in detail below with reference to the accompanying drawings.
[0037] See also Figure 1 , which shows a flowchart of a method for rapid detection of foreign matter in food based on image features provided by an embodiment of the present invention, the method comprising the following steps:
[0038] Step S001: obtaining a grayscale image of white asparagus to be detected.
[0039] It should be noted that during the food processing process, if foreign matter exists in the semi-finished food, it will cause serious safety problems in the processed finished food. Therefore, it is necessary to detect foreign matter in the semi-finished product based on image features. During the food processing process, if foreign matter is mixed into the semi-finished food, it will cause safety problems in the subsequent food processing process.
[0040] Specifically, we first need to collect the grayscale image of the white asparagus to be detected. The specific process is as follows:
[0041] The real-time image of the semi-finished white asparagus to be inspected during the processing is captured by an industrial camera to obtain the image of the white asparagus to be inspected, and the image of the white asparagus to be inspected is subjected to median filtering, denoising and gray-scaling operations to obtain the gray-scale image of the white asparagus to be inspected. In this embodiment, the gray-scale image of the white asparagus to be inspected is described as having a size of 800×800. The median filtering and gray-scaling operations are prior arts, and are not described in detail in this embodiment.
[0042] So far, the grayscale image of the white asparagus to be detected is obtained through the above method.
[0043] Step S002: Divide the grayscale image of the white asparagus to be detected into a plurality of image blocks, and obtain the confidence of each suspected shadow area in each column of each image block.
[0044] It should be noted that due to the overlap and aggregation of the semi-finished segments of white asparagus, some shadow areas appear in the image. The pixels in the shadow area usually have lower grayscale values. In the process of adaptive histogram equalization, it is usually necessary to increase the grayscale values of the pixels in the shadow area to show the dark details of the shadow part. However, there are cases where foreign objects with low grayscale values are located in the shadow area. At this time, if the original adaptive histogram equalization is used to equalize the image, the grayscale value of the foreign object will also be increased, which will cause the grayscale value characteristics of the foreign object to be close to the grayscale value characteristics of the white asparagus. Therefore, it is necessary to first calculate the grayscale value characteristics of the pixels in the local area during the adaptive histogram equalization process to determine the confidence of the suspected shadow area in the local area.
[0045] Preset a parameter , wherein this embodiment is based on This example is described as an example, and this embodiment is not specifically limited. It depends on the specific implementation situation.
[0046] Specifically, use size The sliding window is moved in the grayscale image of the white asparagus to be detected with a step size of A sliding window operation is performed, and each sliding window is used as an image block of the grayscale image of the white asparagus to be detected, thereby obtaining a plurality of image blocks of the grayscale image of the white asparagus to be detected.
[0047] For the grayscale image of white asparagus to be detected image blocks, with the In the image block The arrangement order of each pixel point in the column from top to bottom is the horizontal axis, and the gray value of the pixel point is the vertical axis; In the image block All pixel points in the column are input into the two-dimensional coordinate system, several data points are obtained, and a Bezier curve is constructed based on all the data points and recorded as The grayscale curve of the column is obtained Grayscale curves of all columns in an image block.
[0048] For The grayscale curve of the column is subjected to Newton's method to obtain All extreme points of the grayscale curve of the column; Connect all the adjacent extreme points in the grayscale curve of the column to obtain the All curve segments of the grayscale curve of the column;
[0049] Among them, constructing Bezier curves and Newton's method are existing technologies, and this embodiment will not be described in detail here.
[0050] The grayscale value with the largest number of pixels in the grayscale image of the white asparagus to be detected is used as the main characteristic grayscale value of the grayscale image of the white asparagus to be detected; Any extreme point of the grayscale curve of the column, the difference between the grayscale value of the extreme point and the main characteristic grayscale value is used as the first difference of the extreme point; The first extreme point of the grayscale curve of the column starts to traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point with a grayscale value greater than the main feature grayscale value is taken as the The starting point of the first suspected shadow area of the grayscale curve of the column, starting from the starting point of the first suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point whose first difference is greater than the main characteristic grayscale value is taken as the The end point of the first suspected shadow area of the grayscale curve of the column, and the starting point of the first suspected shadow area corresponds to the In the image block The pixel point in the column corresponds to the end point of the first shadow-like area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The first suspected shadow area of the column; starting from the end point of the first suspected shadow area, traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point with a grayscale value greater than the main feature grayscale value is taken as the The starting point of the second suspected shadow area of the grayscale curve of the column, starting from the starting point of the second suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point whose first difference is greater than the main characteristic grayscale value is taken as the The end point of the second suspected shadow area of the grayscale curve of the column is set to the starting point of the second suspected shadow area corresponding to the In the image block The pixel point in the column corresponds to the end point of the second suspected shadow area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The second suspected shadow area of the column is obtained; and so on, until the In the image block All suspected shaded areas of the column.
[0051] At this point, all suspected shadow areas in each column of each image block are obtained.
[0052] Specifically, In the image block Column No. In the suspected shadow area The confidence level of a curve segment is calculated as:
[0053]
[0054] In the formula, Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. In the suspected shadow area The slope of a curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates taking the absolute value.
[0055] It should be noted that since the pixels in the shadow area show a characteristic of gradual grayscale value change, the number of pixels in the curve segment is usually large, while the grayscale values of the pixels in the foreign matter or white asparagus segment are relatively similar, which is reflected in the curve graph as a small range of fluctuations, corresponding to which there are multiple curve segments with a small number of pixels in the segment; therefore The larger the In the suspected shadow area The greater the confidence of the curve segment.
[0056] Further, In the image block Column No. The confidence level of a suspected shadow area is calculated as:
[0057]
[0058] In the formula, Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area.
[0059] So far, the confidence of each suspected shadow area in each column of each image block is obtained through the above method.
[0060] Step S003: Obtain all enhanced image blocks according to the adjusted grayscale value of each pixel point of each curve segment in each suspected shadow area of each column in each image block.
[0061] It should be noted that, since the new grayscale value corresponding to the original grayscale is determined by the cumulative distribution function of the grayscale during the histogram equalization of the image block, if the proportion of the suspected shadow area in the image block is larger and the confidence is greater, the grayscale value of the suspected shadow area after the histogram equalization will be compressed, causing it to be close to the grayscale value of the foreign body feature, affecting the subsequent detection effect; therefore, before performing local area histogram equalization, the grayscale value of the pixel point in the image block must first be preprocessed by linear transformation.
[0062] Specifically, In the image block Column No. In the suspected shadow area The calculation method of the adjustment coefficient of the gray value of the pixel point of a curve segment is:
[0063]
[0064] In the formula, Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block The number of all pixels in the column; Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block The minimum confidence value of all suspected shadow areas in the column; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The minimum confidence value of all curve segments in the suspected shadow area; represents the linear normalization function.
[0065] At this point, the adjustment coefficient of the grayscale value of the pixel point of each curve segment in each suspected shadow area of each column in each image block is obtained.
[0066] Further, In the image block Column No. In the suspected shadow area The curve segment The calculation method of the gray value of each pixel after adjustment is:
[0067]
[0068] In the formula, Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel after adjustment; Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel; Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Represents the main feature grayscale value of the grayscale image of the white asparagus to be detected.
[0069] The first The adjusted grayscale value of each pixel point of each curve segment in each suspected shadow area of all columns in the image block is used as the After calculating the grayscale value of each pixel point of each curve segment in each suspected shadow area of all columns in the image blocks, the grayscale value is recorded as the enhanced image block, and then all enhanced image blocks are obtained.
[0070] So far, all enhanced image blocks of the grayscale image of the white asparagus to be detected are obtained through the above method.
[0071] Step S004: Rapidly detect food foreign matter on the white asparagus to be detected based on the enhanced image blocks.
[0072] Specifically, a large number of grayscale images of white asparagus without foreign matter are obtained and recorded as normal white asparagus images; a large number of grayscale images of white asparagus with foreign matter are obtained and recorded as abnormal white asparagus images; a large number of normal white asparagus images and abnormal white asparagus images are manually labeled with category information in an image set, wherein the normal white asparagus image category is labeled as 0 and the abnormal white asparagus image category is labeled as 1; and a cross entropy loss function is used to supervise the training. After the neural network training is completed, each enhanced image block is input into a neural grid. If the neural grid outputs the normal white asparagus image category, then the white asparagus to be detected does not contain food foreign matter. If the neural grid outputs the abnormal white asparagus image category, then the white asparagus to be detected contains food foreign matter.
[0073] Among them, the neural network in this embodiment is an LSTM neural network, and other neural network models can be used in other embodiments, which is not limited in this embodiment.
[0074] Through the above steps, the rapid detection method of food foreign matter based on image features is completed.
[0075] The present invention also proposes a rapid detection system for food foreign matter based on image features, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the rapid detection method for food foreign matter based on image features in steps S001 to S004 are implemented.
[0076] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. Rapid detection method of food foreign matter based on image features, It is characterized in that The method comprises the following steps: Obtain a grayscale image of the white asparagus to be detected; The grayscale image is divided into several image blocks; according to the grayscale value of the pixel points in each column in each image block, the grayscale curve of each column in each image block is obtained; according to the extreme value point of the grayscale curve of each column, the curve segment of the grayscale curve of each column is obtained; the grayscale value with the largest number of pixels in the grayscale image is used as the main characteristic grayscale value of the grayscale image; according to the difference between the extreme value point of the grayscale curve of each column and the main characteristic grayscale value, all suspected shadow areas of each column are obtained; according to the grayscale value difference, slope and number of pixels between each curve segment and other curve segments in each suspected shadow area, the confidence of each curve segment in each suspected shadow area is obtained; according to the confidence of each curve segment in each suspected shadow area, the confidence of each suspected shadow area is obtained; According to the number of pixels of each curve segment in each suspected shadow area, the confidence and the confidence of each suspected shadow area, the adjustment coefficient of the grayscale value of the pixel point of each curve segment in each suspected shadow area is obtained; according to the adjustment coefficient of the grayscale value of the pixel point of each curve segment and the main characteristic grayscale value, the adjusted grayscale value of each pixel point of each curve segment is obtained; according to the adjusted grayscale value of each pixel point of each curve segment, the enhanced image block is obtained; Food foreign matter detection is performed on the white asparagus to be detected based on the enhanced image blocks; The specific method of obtaining all suspected shadow areas of each column according to the difference between the extreme point of the grayscale curve of each column and the main characteristic grayscale value includes: For Any extreme point of the grayscale curve of the column, the difference between the grayscale value of the extreme point and the main characteristic grayscale value is used as the first difference of the extreme point; The first extreme point of the grayscale curve of the column starts to traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point whose grayscale value is greater than the main characteristic grayscale value is taken as the The starting point of the first suspected shadow area of the grayscale curve of the column, starting from the starting point of the first suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point with the first difference greater than the main characteristic grayscale value is taken as the The end point of the first suspected shadow area of the grayscale curve of the column, and the starting point of the first suspected shadow area corresponds to the In the image block The pixel point in the column corresponds to the end point of the first shadow-like area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The first suspected shadow area of the column; starting from the end point of the first suspected shadow area, traverse the Of all the remaining extreme points of the grayscale curve of the column, the first extreme point whose grayscale value is greater than the main characteristic grayscale value is taken as the The starting point of the second suspected shadow area of the grayscale curve of the column, starting from the starting point of the second suspected shadow area, traverses the Of all the remaining extreme points of the grayscale curve of the column, the extreme point with the first difference greater than the main characteristic grayscale value is taken as the The end point of the second suspected shadow area of the grayscale curve of the column is set to the starting point of the second suspected shadow area corresponding to the In the image block The pixel point in the column corresponds to the end point of the second suspected shadow area. In the image block The area composed of all pixels between the pixels in the first column is In the image block The second suspected shadow area of the column is obtained; and so on, until the In the image block All suspected shaded areas of the column; The specific formula for obtaining the confidence of each suspected shadow area according to the confidence of each curve segment in each suspected shadow area is: In the formula, Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; The specific formula for obtaining the adjustment coefficient of the grayscale value of each pixel point of each curve segment in each suspected shadow area according to the number of pixels of each curve segment in each suspected shadow area, the confidence level and the confidence level of each suspected shadow area is: In the formula, Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block The number of all pixels in the column; Indicates In the image block Column No. The confidence level of the suspected shadow area; Indicates In the image block The minimum confidence value of all suspected shadow areas in the column; Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. The minimum confidence value of all curve segments in the suspected shadow area; represents the linear normalization function.
2. According to the method for rapid detection of food foreign matter based on image features according to claim 1, It is characterized in that The grayscale image is divided into a plurality of image blocks, including the following specific methods: Preset a parameter , use size The sliding window is moved in the grayscale image of the white asparagus to be detected with a step size of A sliding window operation is performed, and each sliding window is used as an image block of the grayscale image of the white asparagus to be detected, so as to obtain a plurality of image blocks of the grayscale image of the white asparagus to be detected.
3. According to the method for rapid detection of food foreign matter based on image features as claimed in claim 1, It is characterized in that The specific method of obtaining the grayscale curve of each column in each image block according to the grayscale value of the pixel point in each column in each image block includes: First In the image block The arrangement order of each pixel point in the column from top to bottom is the horizontal axis, and the gray value of the pixel point is the vertical axis; In the image block All pixel points in the column are input into the two-dimensional coordinate system, several data points are obtained, and a Bezier curve is constructed based on all the data points and recorded as Grayscale curve of the column.
4. According to the method for rapid detection of food foreign matter based on image features as claimed in claim 1, It is characterized in that The method of obtaining the curve segment of the grayscale curve of each column according to the extreme value point of the grayscale curve of each column includes: For The grayscale curve of the column is subjected to Newton's method to obtain All extreme points of the grayscale curve of the column; Connect all the adjacent extreme points in the grayscale curve of the column to obtain the All curve segments of the grayscale curve of the column.
5. According to the method for rapid detection of food foreign matter based on image features as claimed in claim 1, It is characterized in that The specific formula for obtaining the confidence of each curve segment in each suspected shadow area according to the gray value difference, slope and number of pixels between each curve segment and other curve segments in each suspected shadow area is: In the formula, Indicates In the image block Column No. In the suspected shadow area The confidence level of each curve segment; Indicates In the image block Column No. In the suspected shadow area The slope of a curve segment; Indicates In the image block Column No. The number of all curve segments in the suspected shadow area; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The average gray value of all pixels in a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates In the image block Column No. In the suspected shadow area The number of all pixels of a curve segment; Indicates taking the absolute value.
6. According to the method for rapid detection of foreign matter in food based on image features as claimed in claim 1, It is characterized in that The specific formula for obtaining the adjusted grayscale value of each pixel point of each curve segment according to the adjustment coefficient of the grayscale value of the pixel point of each curve segment and the main characteristic grayscale value is: In the formula, Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel after adjustment; Indicates In the image block Column No. In the suspected shadow area The curve segment The gray value of each pixel; Indicates In the image block Column No. In the suspected shadow area The adjustment coefficient of the gray value of the pixel point of each curve segment; Represents the main feature grayscale value of the grayscale image of the white asparagus to be detected.
7. A food foreign body rapid detection system based on image features, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, It is characterized in that When the processor executes the computer program, the steps of the method for rapid detection of foreign matter in food based on image features as described in any one of claims 1 to 6 are implemented.
