Foreign matter detection method and system in bagged meat based on machine vision

Through machine vision-based detection methods, the similarity is calculated using the high-frequency feature difference of a specific loss function and Fourier spectrum diagram, the problem of low detection accuracy of foreign matter in bagged meat in the prior art is solved, and higher detection accuracy and distinction ability are achieved.

CN119417823BActive Publication Date: 2025-05-06XIAN YANGYUN FOOD TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510018185.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-05-06
Estimated Expiration
2045-01-07

AI Technical Summary

Technical Problem

The existing foreign object detection methods are relatively low in detection of foreign objects in bagged meat, especially for foreign objects with smaller density differences and non-metal foreign objects.

Method used

Using machine vision-based detection method, by collecting the texture map of bagged meat and inputting it into a preset foreign object detection model, the model is trained using a specific loss function, tiny foreign object characteristics are captured, and the similarity is calculated through the high-frequency feature difference of the Fourier spectrogram to improve detection accuracy.

Benefits of technology

It improves the accuracy of foreign matter detection in bagged meat, can more accurately distinguish the spectrum characteristics of qualified products and foreign matters, and provides more refined discrimination information, thereby improving the model's distinction ability and classification performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119417823B_ABST
    Figure CN119417823B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image processing technology, and the present invention relates to a method and system for detecting foreign matter in bagged meat based on machine vision. The method includes: collecting the texture map of the bagged meat to be detected, and inputting it into a preset foreign matter detection model to obtain the foreign matter detection result; the training method of the foreign matter detection model includes: obtaining the texture map of the foreign matter detected at the historical moment and the first average image of multiple historical bagged meat texture maps; dividing the first average image into multiple areas of the same size according to a preset division method; and enlarging the texture map of the foreign matter to the size of the area; obtaining the similarity between each area of ​​the first average image and the enlarged texture map of the foreign matter, and constructing the loss function corresponding to each area according to the similarity of each area, and using the constructed loss function foreign matter detection model for training. The method of the present invention can effectively improve the accuracy of foreign matter detection in bagged meat.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and more specifically, to a method and system for detecting foreign matter in bagged meat based on machine vision. Background Art

[0002] During the production and processing of bagged meat, foreign matter is often mixed in. These foreign matter include exogenous foreign matter such as metal and plastic, as well as endogenous foreign matter such as meat hair. The mixing of these foreign matter will not only cause physical and mental harm to consumers, but also have a huge impact on the reputation of the company. Therefore, it is very important to detect foreign matter in bagged meat.

[0003] At present, the commonly used foreign body detection methods in food include X-ray imaging, hyperspectral imaging, machine vision, metal detection, etc., but these technologies have some shortcomings in the actual detection process. For example, X-ray imaging is difficult to identify foreign bodies with small density differences, and it has certain ionization damage to the human body. For example, the patent application document with application publication number CN115345860A discloses an X-ray-based artificial intelligence foreign body detection method, which uses an X-ray machine to obtain an X-ray transmission image of the inspected object and combines the regional growing algorithm to detect foreign bodies. However, this method has difficulty in identifying foreign bodies with small density differences, and it has certain ionization damage to the human body.

[0004] Hyperspectral imaging is costly and greatly affected by the environment, and it is difficult to detect transparent or low-reflectivity foreign objects; metal detection cannot identify non-metallic foreign objects; compared with the above three detection methods, machine vision will not have any impact on the appearance and safety of bagged meat and has strong adaptability to complex production environments. However, some foreign objects in bagged meat (such as small rust residues and certain colored plastics) are very similar in color to meat and may be difficult to detect through machine vision. Summary of the invention

[0005] In order to solve the technical problem that the detection results of the existing foreign body detection methods have poor accuracy, the present invention provides solutions in the following aspects.

[0006] In a first aspect, the present invention provides a method for detecting foreign matter in bagged meat based on machine vision, comprising: collecting a texture map of the bagged meat to be detected, and inputting it into a preset foreign matter detection model to obtain a foreign matter detection result; the training method of the foreign matter detection model comprises:

[0007] Acquire a texture map of a foreign object detected at a historical moment and a first average image of a plurality of historical bagged meat texture maps; divide the first average image into a plurality of regions of the same size according to a preset division method; and enlarge the texture map of the foreign object to the size of the region;

[0008] Determine the similarity between each region of the first average image and the texture map of the magnified foreign object, and construct a loss function corresponding to each region based on the similarity of each region, and use the loss function to train the foreign object detection model; the loss function expression is:

[0009] ;

[0010] In the formula, The texture map of the historical bagged meat in the foreign body detection model The loss function corresponding to each region; Texture map of historical bagged meat The true label of each region; Output the historical bagged meat texture map in the CNN model Prediction value of window area probability; is the similarity; ln represents the logarithm with e as the base.

[0011] In the process of training the foreign body detection model, the present invention calculates the loss between the model input and output by introducing the similarity between the first average image in the corresponding area and the texture map of the foreign body. The true label of the area is that there is foreign matter in the bagged meat, and the penalty factor of the loss function in this area is Inversely proportional, in the historical bagged meat texture map The true label of the area is that there is no foreign matter in the bagged meat, so that the penalty factor of the loss function in this area is Compared with the original binary cross entropy loss function, the loss function can more effectively capture the tiny foreign body features in the bagged meat image during the training process. This method can more accurately distinguish the spectral features of qualified products and foreign bodies, provide more detailed discrimination information, and thus improve the model's ability to distinguish different categories (qualified products and foreign bodies). Ultimately, the loss function is more discriminating and can better optimize the classification performance during training, thereby improving the accuracy of foreign body detection results when using the neural network model to detect foreign bodies in bagged meat.

[0012] Preferably, for the kth region of the first average image, the similarity calculation method includes: obtaining a second average image of a plurality of texture images of qualified bagged meat, and dividing it into a plurality of regions of the same size according to the preset division method; obtaining a first Fourier spectrum image of the texture image of the magnified foreign matter, a second Fourier spectrum image of the region of the first average image, and a third Fourier spectrum image of the corresponding region of the second average image;

[0013] Calculate the first high-frequency feature difference between the third Fourier spectrum graph and the first Fourier spectrum graph, and the second high-frequency feature difference between the third Fourier spectrum graph and the second Fourier spectrum graph; calculate the similarity between the first high-frequency feature difference and the second high-frequency feature difference, and use it as the similarity.

[0014] When obtaining the similarity between the kth region of the first average image and the texture map of the foreign object, the present invention does not directly compare the kth region of the first average image with the texture map of the foreign object, but introduces a second average image of the texture maps of multiple qualified bagged meats, respectively obtains the difference between the kth region of the first average image and the kth region of the second average image, and the difference between the texture map of the foreign object and the kth region of the second average image, and compares the similarity between the two differences, so that the similarity calculation between the kth region of the first average image and the texture map of the foreign object is more accurate. In addition, when comparing the difference between the two texture maps, the two texture maps are first converted into Fourier spectrum maps, and the difference between the high-frequency features of the two Fourier spectrum maps is calculated, and the difference between the two texture maps is measured by the difference between the high-frequency features, so that the difference calculation between the two texture maps is more efficient and accurate.

[0015] Preferably, the first high-frequency feature difference is represented by a first high-frequency feature difference vector, and a calculation method thereof includes: determining a high-frequency region and a low-frequency region of the first Fourier spectrum graph and the third Fourier spectrum graph;

[0016] The frequency mean, frequency variance and frequency range of the high frequency region of the first Fourier spectrum graph, as well as the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph are obtained, and the first high frequency feature difference vector is calculated, and its expression is:

[0017] ;

[0018] In the formula, represents the first high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and They are the frequency mean, frequency variance and frequency range of the high-frequency region of the first Fourier spectrum.

[0019] The present invention uses the first high-frequency feature difference vector to characterize the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the first Fourier spectrum graph. When calculating the first high-frequency feature difference vector, the three parameters of the frequency mean, frequency variance and frequency range in the high-frequency area are fully considered, and the difference between the three parameters of the third Fourier spectrum graph and the first Fourier spectrum graph is calculated. The high-frequency feature difference vector is constructed using the calculated difference, so as to more accurately calculate the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the first Fourier spectrum graph.

[0020] Preferably, the second high-frequency feature difference is represented by a second high-frequency feature difference vector, and a calculation method thereof includes: determining a high-frequency region and a low-frequency region of the second Fourier spectrum graph and the third Fourier spectrum graph;

[0021] The frequency mean, frequency variance and frequency range of the high frequency region of the second Fourier spectrum graph, as well as the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph are obtained, and the second high frequency feature difference vector is calculated, and its expression is:

[0022] ;

[0023] In the formula, represents the second high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and They are the frequency mean, frequency variance and frequency range of the high-frequency area of ​​the second Fourier spectrum.

[0024] The present invention uses a second high-frequency feature difference vector to characterize the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the second Fourier spectrum graph. When calculating the second high-frequency feature difference vector, the three parameters of the frequency mean, frequency variance and frequency range in the high-frequency area are fully considered, and the difference between the three parameters of the third Fourier spectrum graph and the second Fourier spectrum graph is calculated. The high-frequency feature difference vector is constructed using the calculated difference, so as to more accurately calculate the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the second Fourier spectrum graph.

[0025] Preferably, the size of the region is , the method for determining the high-frequency region and the low-frequency region of the first Fourier spectrum graph includes:

[0026] The first Fourier spectrum graph is spectrally shifted to move the origin to the center of the image, and the range with a radius of N / 20 from the origin is defined as the low-frequency area, and the rest of the area is the high-frequency area.

[0027] Preferably, the similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is:

[0028] ;

[0029] In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, represents the cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector, and exp() represents an exponential function with the natural constant e as the base.

[0030] The present invention uses the cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector to calculate the similarity between the first high-frequency feature difference and the second high-frequency feature difference, and makes the similarity between the first high-frequency feature difference and the second high-frequency feature difference proportional to the cosine similarity, so that the similarity between the first high-frequency feature difference and the second high-frequency feature difference can be calculated more accurately.

[0031] Preferably, the similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is:

[0032] ;

[0033] In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, exp() represents an exponential function with the natural constant e as the base, represents the Euclidean distance between the first high-frequency feature difference vector and the second high-frequency feature difference vector; represents the i-th element of the first high-frequency feature difference vector, Represents the i-th element of the second high-frequency feature difference vector.

[0034] In the present invention, the similarity between the first high-frequency feature difference and the second high-frequency feature difference is calculated by the Euclidean distance between the first high-frequency feature difference vector and the second high-frequency feature difference vector, and the similarity between the first high-frequency feature difference and the second high-frequency feature difference is made inversely proportional to the corresponding Euclidean distance, so that the similarity between the first high-frequency feature difference and the second high-frequency feature difference can be calculated more accurately.

[0035] Preferably, the method for acquiring the texture map of the foreign matter includes:

[0036] Collecting an image of the foreign object and performing median filtering to denoise the image, thereby obtaining a denoised foreign object image;

[0037] Grayscale processing is performed on the denoised foreign body image to obtain a foreign body grayscale image;

[0038] The foreign object grayscale image is convolved using a Gabor filter to obtain a texture image of the foreign object.

[0039] When acquiring the texture map of a foreign object, the present invention first denoises and grayscales the collected image of the foreign object, thereby improving the accuracy and efficiency of texture extraction; by utilizing a Gabor filter to extract the texture in the image, the texture details in the image are more comprehensively captured, further improving the accuracy of texture extraction.

[0040] Preferably, dividing the first average image into multiple areas of the same size according to a preset division method includes: using a moving window of size N×N to perform a window moving operation with a step length of N on the first average image, thereby dividing multiple texture images of qualified bagged meat into multiple areas of the same size.

[0041] In a second aspect, the present invention provides a system for detecting foreign objects in bagged meat based on machine vision, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the method for detecting foreign objects in bagged meat based on machine vision of the present invention is implemented.

[0042] In summary, the beneficial effect of the present invention is that the accuracy of foreign matter detection in bagged meat can be effectively improved by using the machine vision-based foreign matter detection method in bagged meat of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:

[0044] Figure 1 is a flow chart schematically showing a method for detecting foreign matter in bagged meat based on machine vision according to an embodiment of the present invention;

[0045] Figure 2 is an image schematically showing bagged meat to be inspected according to an embodiment of the present invention;

[0046] Figure 3 is a schematic diagram schematically showing a foreign body detection result according to an embodiment of the present invention;

[0047] Figure 4 The figure schematically shows the structure of a system for detecting foreign matter in bagged meat based on machine vision according to an embodiment of the present invention. DETAILED DESCRIPTION

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

[0049] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0050] Example of foreign body detection method in bagged meat based on machine vision:

[0051] like Figure 1 As shown, the method for detecting foreign matter in bagged meat based on machine vision of the present invention comprises: collecting a texture map of the bagged meat to be detected, and inputting it into a preset foreign matter detection model, thereby obtaining a foreign matter detection result;

[0052] First, an industrial camera can be used to capture an image of the bagged meat to be inspected, and texture features in the image can be extracted to obtain a texture map. Texture features can be extracted using a Gabor filter or a local binary pattern. Figure 2 shown.

[0053] For a texture image of a bagged meat to be tested, the corresponding foreign body detection result is as follows: Figure 3 As shown in the figure, it can be seen that there is no foreign matter in area A, area B, area C and area D.

[0054] The training method of the foreign body detection model includes:

[0055] S101, obtaining a texture map of a foreign object and a historical texture map of bagged meat and preprocessing them, specifically: obtaining a texture map of a foreign object detected at a historical moment and a first average image of a plurality of historical texture maps of bagged meat; dividing the first average image into a plurality of regions of the same size according to a preset division method; and enlarging the texture map of the foreign object to the size of the region;

[0056] In this embodiment, the method for obtaining the first average image of multiple historical bagged meat texture images is: adding the pixels corresponding to each historical bagged meat texture image, and dividing the result by the total number of historical bagged meat texture images to obtain the average value of each pixel; then assigning the obtained average value to a new image, thereby obtaining the first average image of multiple historical bagged meat texture images.

[0057] Because foreign matter in the bagged meat image is generally hidden in the bagged meat, with only a small amount of foreign matter appearing in a local area of ​​the bagged meat, dividing the window facilitates more accurate detection of whether there is foreign matter in the bagged meat.

[0058] S102, constructing a loss function and training the foreign body detection model, specifically: determining the similarity between each region of the first average image and the texture map of the magnified foreign body, and constructing a loss function corresponding to each region according to the similarity of each region, and using the loss function to train the foreign body detection model; the loss function expression is:

[0059] ;

[0060] In the formula, The texture map of the historical bagged meat in the foreign body detection model The loss function corresponding to each region; Texture map of historical bagged meat The true label of each region; Output the historical bagged meat texture map in the CNN model The probability that the predicted value of the window area is 1; is the similarity; Indicates that there is foreign matter. It means no foreign matter, and ln means logarithm with base e.

[0061] The greater the similarity between a certain area of ​​the first average image and the texture map of the foreign object, the greater the possibility that the foreign object exists in the area of ​​the historical bagged meat. Conversely, the smaller the similarity between a certain area of ​​the first average image and the texture map of the foreign object, the smaller the possibility that the foreign object exists in the area of ​​the historical bagged meat. The true label of the area is that there is foreign matter in the bagged meat, and the penalty factor of the loss function in this area is Inversely proportional, in the historical bagged meat texture map The true label of the area is that there is no foreign matter in the bagged meat, so that the penalty factor of the loss function in this area is Proportional to the predicted results and similarity The size of the loss function penalty factor is adaptively adjusted to achieve better training effect of the foreign object detection model.

[0062] The specific process of training is:

[0063] a. Input the historical bagged meat images into the foreign body detection model and calculate the predicted value through forward propagation.

[0064] b. Use the loss function to calculate the difference between the predicted value and the true value;

[0065] c. Calculate the gradient of the loss function to the model parameters through the back-propagation algorithm, and use the optimizer to update the model parameters;

[0066] d. Iteratively update the model parameters until the preset number of times is reached.

[0067] In the process of training the foreign body detection model, the present invention calculates the loss between the model input and output by introducing the similarity between the first average image in the corresponding area and the texture map of the foreign body. The true label of the area is that there is foreign matter in the bagged meat, and the penalty factor of the loss function in this area is Inversely proportional, in the historical bagged meat texture map The true label of the area is that there is no foreign matter in the bagged meat, so that the penalty factor of the loss function in this area is Compared with the original binary cross entropy loss function, the loss function can more effectively capture the tiny foreign body features in the bagged meat image during the training process. This method can more accurately distinguish the spectral features of qualified products and foreign bodies, provide more detailed discrimination information, and thus improve the model's ability to distinguish different categories (qualified products and foreign bodies). Ultimately, the loss function is more discriminating and can better optimize the classification performance during training, thereby improving the accuracy of foreign body detection results when using the neural network model to detect foreign bodies in bagged meat.

[0068] In one embodiment, for the kth region of the first average image, the similarity calculation method includes:

[0069] S201, obtaining a second average image of a plurality of texture images of qualified bagged meat, and dividing them into a plurality of regions of the same size according to the preset division method; obtaining a first Fourier spectrum image of the texture image of the magnified foreign matter, a second Fourier spectrum image of the region of the first average image, and a third Fourier spectrum image of the region corresponding to the second average image;

[0070] The corresponding Fourier spectrum graph can be obtained by performing Fourier transform on the texture image.

[0071] S202, calculating a first high-frequency feature difference between the third Fourier spectrum graph and the first Fourier spectrum graph, and a second high-frequency feature difference between the third Fourier spectrum graph and the second Fourier spectrum graph; calculating a similarity between the first high-frequency feature difference and the second high-frequency feature difference, and using it as the similarity.

[0072] The first high-frequency feature difference between the third Fourier spectrum diagram and the first Fourier spectrum diagram refers to the difference between the high-frequency features of the third Fourier spectrum diagram and the high-frequency features of the first Fourier spectrum diagram. Similarly, the second high-frequency feature difference between the third Fourier spectrum diagram and the second Fourier spectrum diagram refers to the difference between the high-frequency features of the third Fourier spectrum diagram and the high-frequency features of the second Fourier spectrum diagram.

[0073] When obtaining the similarity between the kth region of the first average image and the texture map of the foreign object, this embodiment does not directly compare the kth region of the first average image with the texture map of the foreign object, but introduces a second average image of the texture maps of multiple qualified bagged meats, respectively obtains the difference between the kth region of the first average image and the kth region of the second average image, and the difference between the texture map of the foreign object and the kth region of the second average image, and compares the similarity between the two differences, so that the similarity calculation between the kth region of the first average image and the texture map of the foreign object is more accurate. In addition, when comparing the difference between the two texture maps, the two texture maps are first converted into Fourier spectrum maps, and the difference between the high-frequency features of the two Fourier spectrum maps is calculated, and the difference between the two texture maps is measured by the difference between the high-frequency features, so that the difference calculation between the two texture maps is more efficient and accurate.

[0074] In one embodiment, the first high-frequency feature difference is represented by a first high-frequency feature difference vector, and a calculation method thereof includes:

[0075] S301, determining the high-frequency region and the low-frequency region of the first Fourier spectrum graph and the third Fourier spectrum graph;

[0076] S302, obtaining the frequency mean, frequency variance and frequency range of the high frequency region of the first Fourier spectrum graph, and the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph, and calculating the first high frequency feature difference vector, the expression of which is:

[0077] ;

[0078] In the formula, represents the first high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and They are the frequency mean, frequency variance and frequency range of the high-frequency region of the first Fourier spectrum.

[0079] This embodiment uses the first high-frequency feature difference vector to characterize the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the first Fourier spectrum graph. When calculating the first high-frequency feature difference vector, the three parameters of the frequency mean, frequency variance and frequency range in the high-frequency region are fully considered, and the difference between the three parameters of the third Fourier spectrum graph and the first Fourier spectrum graph is calculated. The high-frequency feature difference vector is constructed using the calculated difference, so as to more accurately calculate the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the first Fourier spectrum graph.

[0080] In one embodiment, the second high-frequency feature difference is represented by a second high-frequency feature difference vector, and a calculation method thereof includes:

[0081] determining a high frequency region and a low frequency region of the second Fourier spectrum graph and the third Fourier spectrum graph;

[0082] The frequency mean, frequency variance and frequency range of the high frequency region of the second Fourier spectrum graph, as well as the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph are obtained, and the second high frequency feature difference vector is calculated, and its expression is:

[0083] ;

[0084] In the formula, represents the second high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and They are the frequency mean, frequency variance and frequency range of the high-frequency area of ​​the second Fourier spectrum.

[0085] This embodiment uses the second high-frequency feature difference vector to characterize the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the second Fourier spectrum graph. When calculating the second high-frequency feature difference vector, the three parameters of the frequency mean, frequency variance and frequency range in the high-frequency region are fully considered, and the difference between the three parameters of the third Fourier spectrum graph and the second Fourier spectrum graph is calculated. The high-frequency feature difference vector is constructed using the calculated difference, so as to more accurately calculate the difference between the high-frequency features of the third Fourier spectrum graph and the high-frequency features of the second Fourier spectrum graph.

[0086] In one embodiment, the size of the region is The method for determining the high-frequency area and the low-frequency area of ​​the first Fourier spectrum diagram includes: performing spectrum shift on the first Fourier spectrum diagram to move the origin to the center of the image, and defining the range with a radius of N / 20 from the origin as the low-frequency area, and the remaining area as the high-frequency area.

[0087] In one embodiment, the similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is:

[0088] ;

[0089] In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, represents the cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector.

[0090] In this embodiment, the similarity between the first high-frequency feature difference and the second high-frequency feature difference is calculated based on the cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector. The larger the cosine similarity, the higher the similarity between the two vectors, the greater the similarity between the first high-frequency feature difference and the second high-frequency feature difference, and the greater the possibility that foreign matter exists in the area of ​​the bagged meat to be detected; the smaller the value, the lower the similarity between the two vectors, the smaller the similarity between the first high-frequency feature difference and the second high-frequency feature difference, and the smaller the possibility that foreign matter exists in the area of ​​the bagged meat to be detected.

[0091] The cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector is used to calculate the similarity between the first high-frequency feature difference and the second high-frequency feature difference, and the similarity between the first high-frequency feature difference and the second high-frequency feature difference is made proportional to the cosine similarity, so that the similarity between the first high-frequency feature difference and the second high-frequency feature difference can be calculated more accurately.

[0092] In one embodiment, the similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is:

[0093] ;

[0094] In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, exp() represents an exponential function with the natural constant e as the base, represents the Euclidean distance between the first high-frequency feature difference vector and the second high-frequency feature difference vector; represents the i-th element of the first high-frequency feature difference vector, Represents the i-th element of the second high-frequency feature difference vector.

[0095] In this embodiment, the similarity between the first high-frequency feature difference and the second high-frequency feature difference is calculated by the Euclidean distance between the first high-frequency feature difference vector and the second high-frequency feature difference vector, and the similarity between the first high-frequency feature difference and the second high-frequency feature difference is made inversely proportional to the corresponding Euclidean distance, so that the similarity between the first high-frequency feature difference and the second high-frequency feature difference can be calculated more accurately.

[0096] It can be seen from the above embodiments that an image of a foreign object can be first captured, and texture features in the image can be extracted to obtain a texture map. In one embodiment, the method for obtaining the texture map of the foreign object includes:

[0097] S401, collecting an image of the foreign object, and performing median filtering to denoise the image, thereby obtaining a denoised foreign object image;

[0098] By performing median filtering on the image of the foreign object, the interference of noise can be eliminated, making the texture map of the foreign object more accurate.

[0099] S402, graying the denoised foreign body image to obtain a foreign body grayscale image;

[0100] By graying the image, the image can be converted from RGB to a single-channel grayscale image, which facilitates subsequent processing and also helps to increase the processing speed.

[0101] S403 , convolving the foreign object grayscale image using a Gabor filter to obtain a texture image of the foreign object.

[0102] The Gabor filter is a linear filter based on sine and cosine functions, known for its unique locality, directionality, and multi-scale properties. It can achieve localization in both the spatial domain and the frequency domain, thereby extracting texture information of a specific frequency at a specific location in the image. By changing the directional parameters of the filter, the Gabor filter can extract texture features in different directions, enhancing the ability to recognize the directionality of image texture.

[0103] When acquiring the texture map of a foreign object, this embodiment first denoises and grayscales the collected image of the foreign object, thereby improving the accuracy and efficiency of texture extraction; by utilizing a Gabor filter to extract the texture in the image, the texture details in the image are more comprehensively captured, further improving the accuracy of texture extraction.

[0104] In one embodiment, dividing the first average image into multiple regions of the same size according to a preset division method includes: using a moving window of size N×N to perform a window moving operation with a step length of N on the first average image, thereby dividing multiple texture images of qualified bagged meat into multiple regions of the same size.

[0105] Example of foreign body detection system in bagged meat based on machine vision:

[0106] The present invention also provides a foreign body detection system for bagged meat based on machine vision. Figure 4 As shown, the system for detecting foreign objects in bagged meat based on machine vision includes a processor and a memory, wherein the memory stores computer program instructions. When the computer program instructions are executed by the processor, the method for detecting foreign objects in bagged meat based on machine vision described in the above embodiment is implemented.

[0107] The machine vision-based foreign body detection system for bagged meat also includes other components familiar to those skilled in the art, such as a communication bus and a communication interface, whose settings and functions are known in the art and will not be described in detail here.

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

[0109] In the description of this specification, "plurality" or "several" means at least two, such as two, three or more, etc., unless otherwise clearly and specifically defined.

[0110] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, various alternatives to the embodiments of the present invention described herein may be employed.

Claims

1. A method for detecting foreign matter in bagged meat based on machine vision, characterized in that: include: Collecting the texture image of the bagged meat to be tested and inputting it into a preset foreign body detection model to obtain the foreign body detection result; The training method of the foreign body detection model includes: Acquire a texture map of a foreign object detected at a historical moment and a first average image of a plurality of historical bagged meat texture maps; divide the first average image into a plurality of regions of the same size according to a preset division method; and enlarge the texture map of the foreign object to the size of the region; Determine the similarity between each region of the first average image and the texture map of the magnified foreign object, and construct a loss function corresponding to each region based on the similarity of each region, and use the loss function to train the foreign object detection model; the loss function expression is: ; In the formula, The texture map of the historical bagged meat in the foreign body detection model The loss function corresponding to each region; Texture map of historical bagged meat The true label of each region; Output the historical bagged meat texture map in the CNN model Prediction value of window area probability; is the similarity; ln represents the logarithm with base e; For the kth region of the first average image, the similarity calculation method includes: Obtaining a second average image of a plurality of texture images of qualified bagged meat, and dividing the second average image into a plurality of regions of the same size according to the preset division method; Acquire a first Fourier spectrum diagram of the texture map of the amplified foreign object, a second Fourier spectrum diagram of the area of ​​the first average image, and a third Fourier spectrum diagram of the corresponding area of ​​the second average image; Calculating a first high-frequency feature difference between the third Fourier spectrum graph and the first Fourier spectrum graph, and a second high-frequency feature difference between the third Fourier spectrum graph and the second Fourier spectrum graph; calculating a similarity between the first high-frequency feature difference and the second high-frequency feature difference, and using it as the similarity; The first high-frequency feature difference is represented by a first high-frequency feature difference vector, and a calculation method thereof includes: determining a high-frequency region and a low-frequency region of the first Fourier spectrum graph and the third Fourier spectrum graph; The frequency mean, frequency variance and frequency range of the high frequency region of the first Fourier spectrum graph, as well as the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph are obtained, and the first high frequency feature difference vector is calculated, and its expression is: ; In the formula, represents the first high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and are the frequency mean, frequency variance and frequency range of the high frequency region of the first Fourier spectrum diagram; The size of the region is The method for determining the high-frequency area and the low-frequency area of ​​the first Fourier spectrum diagram includes: performing spectrum shift on the first Fourier spectrum diagram to move the origin to the center of the image, and defining the range with a radius of N / 20 from the origin as the low-frequency area, and the remaining area as the high-frequency area.

2. The method for detecting foreign matter in bagged meat based on machine vision according to claim 1, characterized in that: The second high-frequency feature difference is represented by a second high-frequency feature difference vector, and a calculation method thereof includes: determining a high-frequency region and a low-frequency region of the second Fourier spectrum graph and the third Fourier spectrum graph; The frequency mean, frequency variance and frequency range of the high frequency region of the second Fourier spectrum graph, as well as the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph are obtained, and the second high frequency feature difference vector is calculated, and its expression is: ; In the formula, represents the second high-frequency feature difference vector, , and They are the frequency mean, frequency variance and frequency range of the high frequency region of the third Fourier spectrum graph; , and They are the frequency mean, frequency variance and frequency range of the high-frequency area of ​​the second Fourier spectrum.

3. The method for detecting foreign matter in bagged meat based on machine vision according to claim 2, characterized in that: The similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is: ; In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, represents the cosine similarity between the first high-frequency feature difference vector and the second high-frequency feature difference vector, and exp() represents an exponential function with the natural constant e as the base.

4. The method for detecting foreign matter in bagged meat based on machine vision according to claim 2, characterized in that: The similarity calculation expression between the first high-frequency feature difference and the second high-frequency feature difference is: ; In the formula, represents the similarity between the first high-frequency feature difference and the second high-frequency feature difference, exp() represents an exponential function with the natural constant e as the base, represents the Euclidean distance between the first high-frequency feature difference vector and the second high-frequency feature difference vector; represents the i-th element of the first high-frequency feature difference vector, Represents the i-th element of the second high-frequency feature difference vector.

5. The method for detecting foreign matter in bagged meat based on machine vision according to claim 1, characterized in that: The method for obtaining the texture map of the foreign object includes: Collecting an image of the foreign object and performing median filtering to denoise the image, thereby obtaining a denoised foreign object image; Grayscale processing is performed on the denoised foreign body image to obtain a foreign body grayscale image; The foreign object grayscale image is convolved using a Gabor filter to obtain a texture image of the foreign object.

6. The method for detecting foreign matter in bagged meat based on machine vision according to any one of claims 1 to 5, characterized in that: Dividing the first average image into multiple areas of the same size according to a preset division method includes: using a moving window of size N×N to perform a window moving operation with a step length of N on the first average image, thereby dividing multiple texture images of qualified bagged meat into multiple areas of the same size.

7. A foreign body detection system for bagged meat based on machine vision, comprising a processor and a memory, wherein the memory stores computer program instructions, characterized in that: When the computer program instructions are executed by the processor, the method for detecting foreign matter in bagged meat based on machine vision as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Artificial intelligence foreign matter detection method based on X rays

    CN115345860A

  • Image detection method and device based on frequency domain periodic texture removal

    CN113658154A

  • Railway fastener anomaly detection method and system based on computer vision

    CN119205747A