Beef quality detection method based on spectral analysis

By combining spectral analysis with image and spectral information preprocessing, feature extraction, and multi-head attention mechanism, the destructiveness and large-scale detection problems of traditional detection methods are solved, and non-destructive and efficient beef quality assessment is achieved.

CN119991722BActive Publication Date: 2025-09-09GUANGZHOU TOP FOOD CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510204757.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-24
Publication Date
2025-09-09
Estimated Expiration
2045-02-24

AI Technical Summary

Technical Problem

Traditional chemical testing methods for beef quality require destructive sampling and are difficult to meet large-scale testing needs. In addition, the market needs to grade beef quality to meet the needs of different consumer groups.

Method used

A spectral analysis-based method is used to obtain image and spectral information of the beef surface through a camera for preprocessing, and then feature extraction is performed by combining threshold segmentation method and convolutional neural network. The multi-head attention mechanism is used for weighting, and finally quality assessment is performed through machine learning.

Benefits of technology

It realizes non-destructive testing of beef quality, improves the expressiveness, robustness and generalization ability of the test, can analyze beef quality from multiple angles, and adapts to large-scale testing needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119991722B_ABST
    Figure CN119991722B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of meat quality testing, and in particular to a method for testing beef quality based on spectral analysis. The method comprises: obtaining first image information and spectral information of the beef surface, and preprocessing the first image information and spectral information; segmenting the first image information using a first threshold segmentation method, obtaining dark areas and repairing them, and performing feature extraction based on the repaired first image information to obtain a first eigenvector; segmenting the spectral information using a second threshold segmentation method, obtaining reflective areas and repairing them, and obtaining a spectral eigenvector from the repaired spectral information; weighting the first eigenvector and the spectral eigenvector based on an attention mechanism to obtain a second eigenvector; and performing learning and classification based on the second eigenvector using a preset machine learning method to output a beef quality assessment result. This invention not only achieves nondestructive testing but also improves detection accuracy and efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of meat products and quality detection, and in particular to a beef quality detection method based on spectral analysis. Background Art

[0002] Beef is one of the main meats consumed by Chinese people, with consumption increasing annually. It plays an increasingly important role in global protein consumption. However, beef is susceptible to spoilage microorganisms and contamination during cutting and processing, affecting product shelf life and posing health risks to consumers. Furthermore, the market price of beef of different qualities varies significantly, necessitating quality grading to suit different consumer groups and facilitate categorized consumption. Therefore, there is an urgent need for beef quality testing and grading. However, traditional chemical testing methods typically require destructive sampling and often must be conducted under laboratory conditions, making them difficult to meet large-scale testing needs. Summary of the Invention

[0003] In order to solve the above technical problems, the present application is proposed. The present application discloses a method for detecting beef quality based on spectral analysis, comprising the following steps: Step S1: obtaining first image information of the surface of the beef to be detected based on a camera, obtaining spectral information of the beef to be detected based on a spectrometer, and preprocessing the first image information and the spectral information respectively; Step S2: segmenting the preprocessed first image information using a first threshold segmentation method to obtain dark areas, repairing the dark areas, and extracting features based on the first image information of the repaired dark areas to obtain a first eigenvector; Step S3: segmenting the preprocessed spectral information using a second threshold segmentation method to obtain reflective areas, repairing the reflective areas, and extracting spectral eigenvectors from the repaired spectral information using a convolutional neural network; Step S4: weighting the first eigenvector and the spectral eigenvector based on a multi-head attention mechanism to obtain a second eigenvector; Step S5: learning and classifying the second eigenvector using a preset machine learning method to output an evaluation result of the quality of the beef to be detected.

[0004] Preferably, the preprocessing of the first image information and the spectral information includes: preprocessing of the first image information includes edge detection, cropping, and contrast enhancement; preprocessing of the spectral information includes correction, denoising, and normalization.

[0005] Preferably, the first threshold segmentation method is used to segment the preprocessed first image information to obtain the dark area, including: loading the preprocessed first image information, converting the first image information from an RGB image to an HSV image; extracting the brightness channel V, saturation channel S and hue channel H from the HSV image and setting the brightness threshold, saturation threshold and hue threshold accordingly; generating a mask based on the brightness channel V, saturation channel S and hue channel H and the set brightness threshold, saturation threshold and hue threshold; applying the mask to the first image information to obtain the dark area.

[0006] Preferably, the dark area is repaired, and feature extraction is performed based on the first image information after the preprocessing and repair of the dark area to obtain a first feature vector, including: based on the dark area, using the np.where function to enhance the brightness of the dark area, using the np.clip function to ensure that the saturation channel S is between 0-255 and the hue channel H is between 0 and 179; using the cv2.merge function to merge the enhanced brightness channel V, saturation channel S and hue channel H to generate a new HSV image, and converting the new HSV image back to an RGB image to obtain the first image information after the preprocessing and repair of the dark area; extracting first feature information of the first image information after the preprocessing and repair of the dark area, wherein the first feature information includes color features, texture features and morphological features.

[0007] Preferably, the second threshold segmentation method is used to segment the spectral information after the preprocessing to obtain the reflective area and the normal area, including: calculating the contrast, gradient and information entropy of the spectral information in each band, and using the information entropy to determine the optimal segmentation band; based on the optimal segmentation band, the OTSU threshold method is used to extract the reflective area to obtain the reflective area.

[0008] Preferably, the spectral information based on the repaired reflective area is used to extract the spectral feature vector using a spectral matrix, including: repairing the reflective area using a principal component analysis method; constructing a spectral matrix based on the modified spectral information, and obtaining a spectral feature vector through feature extraction based on the spectral matrix, wherein the spectral feature vector is a characteristic wavelength.

[0009] Preferably, the step S4 comprises: performing linear transformation on the first eigenvector and the spectral feature respectively to generate a query matrix Q, a key matrix K and a value matrix V;

[0010] Calculate the attention score using the dot product of the query matrix Q and the key matrix K;

[0011] Use the attention score to perform weighted summation on the value matrix V to obtain the output vector of the attention head;

[0012] Repeat the above process, using a different weight matrix each time, to obtain the output vectors of multiple independent attention heads. Concatenate all the attention head output vectors to obtain the second eigenvector using the following formula, where the formula is:

[0013]

[0014] Among them, F a is the second eigenvector, F n is the output vector of the nth attention head, represents the sum of the elements corresponding to the output vectors of the multiple attention heads, n is the total number of attention head output vectors, α, β and γ are weighting parameters for controlling the balance of the output vectors of the multiple attention heads.

[0015] Preferably, after step S5, the method includes: evaluating and providing feedback on the preset machine learning method, and improving the preset machine learning method based on the evaluation and feedback results.

[0016] In addition, to achieve the above-mentioned purpose, the present application also proposes an electronic device, comprising a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the program, the beef quality detection method based on spectral analysis as described above is implemented.

[0017] In addition, to achieve the above-mentioned purpose, the present application also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the beef quality detection method based on spectral analysis as described above are implemented.

[0018] The beneficial effects of the present application are that, first image information of the surface of beef to be inspected is obtained based on a camera, spectral information of the beef to be inspected is obtained based on a spectrometer, and the first image information and the spectral information are preprocessed to obtain first feature information respectively; a first threshold segmentation method is used to segment the preprocessed first image information to obtain dark areas, the dark areas are repaired, and features are extracted based on the first image information of the repaired dark areas; a second threshold segmentation method is used to segment the preprocessed spectral information to obtain reflective areas, the reflective areas are repaired, and a convolutional neural network is used to extract spectral feature vectors from the repaired spectral information; the first feature vector and the spectral feature vector are weighted based on a multi-head attention mechanism to obtain a second feature vector; according to the second feature vector, learning and classification are performed through a preset machine learning method to output an evaluation result of the quality of the beef to be inspected. Non-destructive testing of beef quality is achieved. In addition, the first image information of the beef surface to be tested is obtained by a camera, and the spectral information of the beef to be tested is obtained by a spectrometer. The beef is tested and analyzed from multiple angles. The threshold segmentation algorithm is also combined to segment and repair the image, removing the influence of dark and reflective areas on beef quality detection. Finally, the multi-attention mechanism is used to capture information at different scales and levels, thereby improving the expressiveness, robustness, generalization ability and interpretability of the overall beef detection scheme. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following detailed description, they are used to explain the embodiments of the present application but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:

[0020] Figure 1 This is a hardware structure block diagram of a mobile terminal for a beef quality detection method based on spectral analysis according to an embodiment of the present invention;

[0021] Figure 2 This is a schematic diagram of the process of beef quality detection based on spectral analysis of the present invention;

[0022] Figure 3 for Figure 1 Detailed implementation steps for obtaining the dark area in step S2; DETAILED DESCRIPTION

[0023] To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0024] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back, etc.), the directional indications are only used to explain the relative position relationship, movement status, etc. between the various components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indications will also change accordingly.

[0025] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the fact that they can be implemented by ordinary technicians in this field. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0026] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a beef quality detection method based on spectral analysis according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0027] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a data information security protection method in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0028] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the mobile terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0029] A flow chart of a method for detecting beef quality based on spectral analysis according to an embodiment of the present application is shown in the attached figure. Figure 2 As shown, the embodiment of the present application provides a method for detecting beef quality based on spectral analysis, which includes the following steps:

[0030] Step S1: obtaining first image information of the surface of the beef to be tested using a camera, obtaining spectral information of the beef to be tested using a spectrometer, and preprocessing the first image information and the spectral information respectively;

[0031] In the embodiment of the present application, the camera and spectrometer are ensured to capture the beef surface at a fixed position and angle to obtain a consistent image and control the lighting conditions to avoid excessive brightness or darkness, ensure image quality, and control the temperature, humidity and other conditions of the measurement environment to avoid interference with the spectrometer due to external factors.

[0032] The preprocessing of the first image information and the spectral information includes: preprocessing the first image information includes edge detection, cropping, and contrast enhancement; preprocessing the spectral information includes correction, denoising, and normalization.

[0033] In an embodiment of the present application, preprocessing of the first image information includes: using any one of the Canny algorithm, the Sobel operator, or the Laplacian operator to detect edges in the image; removing irrelevant background in the image, retaining only the beef part, and automatically cropping the beef area using image segmentation technology; and for the image of the retained beef part, using an adaptive histogram equalization method to enhance the contrast of the first image.

[0034] Preprocessing the spectral information includes baseline correction using a polynomial fitting method to eliminate background signals and other interference, making the spectral data more accurate. Specifically, it includes: reading the spectral data file; polynomial fitting: fitting the baseline of the spectral data using a polynomial fitting method; baseline correction: subtracting the fitted baseline from the original spectral data to obtain the corrected spectral data. Denoising is performed using a moving average filter. The function moving_average_filter, which implements the moving average filter, is called for this purpose. For example, moving_average_filter(spectrum, window_size=5) is used, where spectrum (numpy.ndarray): the input spectral data, and window_size (int): the size of the moving average window. The default value is 5, and the window_size parameter can be adjusted as needed. Finally, using the minimum-maximum normalization method, the minimum and maximum values ​​in the spectral data are calculated and normalized to a range of 0-1 for ease of model processing.

[0035] Step S2: segmenting the preprocessed first image information using a first threshold segmentation method to obtain dark areas, repairing the dark areas, and performing feature extraction based on the first image information of the repaired dark areas to obtain a first feature vector;

[0036] In this embodiment, the first threshold segmentation method is used to segment the pre-processed first image information to obtain the dark area. Figure 3 , including: loading the first image information after preprocessing, converting the first image information from an RGB image to an HSV image; extracting a brightness channel V, a saturation channel S, and a hue channel H from the HSV image and setting a brightness threshold, a saturation threshold, and a hue threshold accordingly; generating a mask based on the brightness channel V, the saturation channel S, the hue channel H and the set brightness threshold, saturation threshold, and hue threshold; and applying the mask to the first image information to obtain a dark area.

[0037] The dark area is repaired, and features are extracted based on the first image information after the preprocessing and repair of the dark area to obtain a first feature vector, including: based on the dark area, using the np.where function to enhance the brightness of the dark area, using the np.clip function to ensure that the saturation channel S is between 0-255 and the hue channel H is between 0 and 179; using the cv2.merge function to merge the enhanced brightness channel V, saturation channel S and hue channel H to generate a new HSV image, and converting the new HSV image back to an RGB image to obtain the first image information after the preprocessing and repair of the dark area; extracting first feature information of the first image information after the preprocessing and repair of the dark area, wherein the first feature information includes color features, texture features and morphological features.

[0038] Among them, color features are extracted by using color histogram, texture features are extracted by calculating gray level co-occurrence matrix (GLCM), and texture features are extracted by calculating image contours and regional attributes.

[0039] Step S3, using the second threshold segmentation method to segment the spectral information after the preprocessing to obtain the reflective area, including: calculating the contrast, gradient and information entropy of the spectral information in each band, and using the information entropy to determine the optimal segmented image band; based on the optimal segmented image band, and using the OTSU threshold method to extract the reflective area to obtain the reflective area.

[0040] Specifically, read the spectral data: read the spectral data from the file. Initialize the feature array: create an empty list to store the contrast, gradient, and information entropy of each band. Calculate the features of each band: traverse each band, calculate the gray-level co-occurrence matrix (GLCM) to extract the contrast, extract the gradient by calculating the gradient amplitude of the image, and calculate the information entropy by calculating the histogram of each band and using the entropy formula, and store the results in the corresponding list. Find the band with the smallest information entropy as the optimal segmentation image band: use the np.argmin function to find the band index with the smallest information entropy as the optimal segmentation image band.

[0041] The OTSU threshold method is used to extract the reflective area in the optimal segmentation image band: Assuming that the image has two parts, namely the foreground area and the background area, the appropriate threshold is determined according to the frequency histogram of the image to segment the foreground area and the background area, so that the inter-class variance of the foreground image and the background image is maximized. That is, the segmentation threshold K between the peak values ​​of the two classes of image histograms in the image frequency histogram is calculated as the optimal segmentation threshold. The traditional method is to use the traversal method to set the segmentation threshold, and to screen out the segmentation threshold K by calculation so that the inter-class variance θ 2When (k) reaches its maximum value, the segmentation threshold K at this point is taken as the optimal segmentation threshold. Reflective regions are extracted based on this threshold, and an image of the reflective regions is obtained. Visualization: Use matplotlib to plot the characteristic curve, the optimal band image, and the reflective region image. Saving the reflective region image: Save the extracted reflective region image to a file.

[0042] The spectral information based on the repaired reflective area is extracted using a spectral matrix to obtain a spectral feature vector, including: repairing the reflective area using a principal component analysis method; constructing a spectral matrix based on the modified spectral information, and obtaining a spectral feature vector through feature extraction based on the spectral matrix, wherein the spectral feature vector is a characteristic wavelength.

[0043] The spectral data is reshaped into a two-dimensional array, where each row represents a pixel and each column represents a band. The reflective area is marked as 1 and the non-reflective area is marked as 0. The spectral data of the reflective area and the non-reflective area are separated. The spectral data of the reflective area and the non-reflective area are analyzed using principal component analysis. The spectral data of the reflective area is repaired by moving the principal component of the reflective area closer to the principal component of the non-reflective area. This can be achieved through linear interpolation, regression, or other suitable mapping functions. Assuming that we have the principal component value P_non_reflective of the non-reflective area and the principal component value P_reflective of the reflective area, a linear interpolation relationship is found, such as P_corrected = (1-α)*P_reflective + α*P_non_reflective, where α is a weight factor, usually determined according to the degree of reflectivity, to achieve adjustment and repair of the reflective area. The repaired spectral data is reinserted into the original spectral data and reshaped back to the original image.

[0044] A spectrum matrix is ​​constructed according to the modified spectrum information, and a spectrum feature vector is obtained by feature extraction according to the spectrum matrix, where the spectrum feature vector is a characteristic wavelength.

[0045] In this embodiment, a matrix is ​​constructed: the spectral data of each sample is arranged in a row to form a matrix. If n samples have measurement values ​​at m wavelengths, then the spectral matrix is ​​n×m. Feature extraction: Various feature extraction methods, such as partial least squares regression (PLS), wavelet analysis, etc., are used to extract important features from the spectral matrix to reduce the dimension of the data while retaining most of the information. Obtaining a feature vector: After feature extraction, each sample will correspond to a feature vector, which is usually shorter than the original spectral data, but contains the most important information. The characteristic wavelength refers to the specific wavelength that is found to be most useful for classification or prediction during the feature extraction process.

[0046] Step S4: weighting the first eigenvector and the spectral eigenvector based on a multi-head attention mechanism to obtain a second eigenvector;

[0047] In this embodiment, the first eigenvector and the spectral feature are linearly transformed to generate a query matrix Q, a key matrix K and a value matrix V. In this generation process, the weight vector of the query matrix Q is set to H Q , the weight vector of the key matrix K is H K And the weight vector of the value matrix V is H V ;

[0048] The attention score is calculated using the dot product of the query matrix Q and the key matrix K. The attention score is normalized using the softmax function to obtain the attention weight distribution α. ​​The softmax function converts the score of each position into a probability, ensuring that the sum of the probabilities of all positions is 1. The value vector V is weighted and summed using the normalized attention weight α to obtain the output vector of the weighted attention head.

[0049] Repeat the above process, using a different weight matrix each time, to obtain the output vectors of multiple independent attention heads. Concatenate all the attention head output vectors to obtain the second eigenvector using the following formula, where the formula is:

[0050]

[0051] Among them, F a is the second eigenvector, F n is the output vector of the nth attention head, represents the addition of the elements corresponding to the output vectors of the attention heads, n is the total number of attention head output vectors, and α, β and γ are weighting parameters for controlling the balance of the output vectors of the multiple attention heads.

[0052] Step S5: Based on the second feature vector, learning and classification are performed through a preset machine learning method, and an evaluation result of the beef to be tested and its quality is output.

[0053] In this embodiment, the preset machine learning algorithm is through model training, that is, the preprocessed data is divided into a training set and a validation set, the training set is used to train the selected model, and the model parameters are adjusted to optimize the performance; model evaluation: the performance of the model is evaluated using the validation set, and common evaluation indicators include accuracy, recall rate, F1 score, and AUC-ROC curve; model optimization: if the model performance is not ideal, you can try to adjust the model parameters, change the feature combination or select a different model.

[0054] In this embodiment, a fully connected layer of a classifier using a preset machine learning method performs fully connected encoding on the second feature vector to obtain an encoded classification feature vector; and a classification result generating unit is configured to input the encoded classification feature vector into a Softmax classification function of the classifier to obtain the classification result. The classification result includes three categories: excellent beef quality, good beef quality, and poor beef quality.

[0055] In an embodiment of the present application, first image information of the surface of the beef to be inspected is obtained based on a camera, spectral information of the beef to be inspected is obtained based on a spectrometer, and the first image information and the spectral information are preprocessed respectively; a first threshold segmentation method is used to segment the preprocessed first image information to obtain a dark area, which is repaired, and feature extraction is performed based on the first image information of the repaired dark area to obtain a first eigenvector; a second threshold segmentation method is used to segment the preprocessed spectral information to obtain a reflective area, which is repaired, and a convolutional neural network is used to extract a spectral eigenvector from the repaired spectral information; the first eigenvector and the spectral eigenvector are weighted based on a multi-head attention mechanism to obtain a second eigenvector; based on the second eigenvector, learning and classification are performed through a preset machine learning method, and an evaluation result of the quality of the beef to be inspected is output. Non-destructive testing of beef quality is achieved. In addition, the camera obtains the first image information of the beef surface to be tested, and the spectrometer obtains the spectral information of the beef to be tested, so that the beef is inspected and analyzed from multiple angles. The threshold segmentation algorithm is also combined to segment, repair and optimize the image, removing the influence of dark and reflective areas on detection. Finally, the multi-attention mechanism is used to capture information at different scales and levels, thereby improving the expressiveness, robustness, generalization ability and interpretability of the overall solution.

[0056] An embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the beef quality detection method based on spectral analysis as described above when executing the program.

[0057] An embodiment of the present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for detecting beef quality based on spectral analysis as described above is implemented.

[0058] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0059] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0060] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0061] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0062] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0063] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0064] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0065] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0066] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims

1. A beef quality detection method based on spectral analysis, characterized in that: The following steps are involved: Step S1: obtaining first image information of the surface of the beef to be inspected using a camera, obtaining spectral information of the beef to be inspected using a spectrometer, and preprocessing the first image information and the spectral information respectively; Step S2: segmenting the preprocessed first image information using a first threshold segmentation method to obtain dark areas, repairing the dark areas, and performing feature extraction based on the repaired first image information to obtain a first feature vector; Step S3: using a second threshold segmentation method to segment the pre-processed spectral information, obtaining a reflective area, repairing the reflective area, and obtaining a spectral feature vector based on the repaired spectral information using a spectral matrix extraction method; Step S4: weighting the first eigenvector and the spectral eigenvector based on a multi-head attention mechanism to obtain a second eigenvector; Step S5: Based on the second feature vector, learning and classification are performed using a preset machine learning method, and a quality assessment result of the beef to be tested is output; The step S4 comprises: Performing linear transformation on the first eigenvector and the spectral eigenvector respectively to generate a query matrix Q, a key matrix K and a value matrix V; Calculate the attention score using the dot product of the query matrix Q and the key matrix K; Use the attention score to perform weighted summation on the value matrix V to obtain the output vector of the attention head; Repeat the above process, using a different weight matrix each time, to obtain the output vectors of multiple independent attention heads. Concatenate all the attention head output vectors to obtain the second eigenvector using the following formula, where the formula is: , in, is the second eigenvector, is the output vector of the nth attention head, represents the sum of the elements corresponding to the output vectors of the attention heads, n is the number of output vectors of the attention heads, 、 and are weighted parameters that control the balance of output vectors of the multiple attention heads.

2. The method according to claim 1, characterized in that The preprocessing of the first image information and the spectral information includes: Preprocessing the first image information includes edge detection, cropping, and contrast enhancement; The preprocessing of the spectral information includes correction, denoising and normalization.

3. The method according to claim 1, characterized in that The step of segmenting the pre-processed first image information using a first threshold segmentation method to obtain a dark area includes: Loading the preprocessed first image information, and converting the first image information from an RGB image to an HSV image; Extract the brightness channel V, saturation channel S and hue channel H from the HSV image and set the brightness threshold, saturation threshold and hue threshold accordingly; Generate a mask based on the brightness channel V, the saturation channel S and the hue channel H and the set brightness threshold, saturation threshold and hue threshold; The mask is applied to the first image information to obtain a dark area.

4. The method according to claim 3, characterized in that Restoring the dark area and performing feature extraction based on the preprocessed and restored first image information to obtain a first feature vector includes: For the dark area, the np.where function is used to enhance the brightness of the dark area, and the np.clip function is used to ensure that the saturation channel S is between 0-255 and the hue channel H is between 0 and 179; Use the cv2.merge function to merge the enhanced brightness channel V, saturation channel S, and hue channel H to generate a new HSV image, and convert the new HSV image back to an RGB image to obtain the first image information after preprocessing and restoration; Extract first feature information of the preprocessed and restored first image information, wherein the first feature information includes color features, texture features and morphological features; wherein, color features are extracted by using a color histogram, texture features are extracted by calculating a gray level co-occurrence matrix, and texture features are extracted by calculating the contour and regional attributes of the image.

5. The method according to claim 1, wherein The step of segmenting the pre-processed spectral information using a second threshold segmentation method to obtain a reflective area includes: Calculate the contrast, gradient and information entropy of the spectral information in each band, and use the information entropy to determine the optimal segmentation band; Based on the optimal segmentation band, the reflective area is extracted using the OTSU threshold method to obtain the reflective area.

6. The method according to claim 1, characterized in that The step of extracting a spectral feature vector based on the repaired spectral information using a spectral matrix comprises: Repairing the reflective area using principal component analysis; A spectral matrix is ​​constructed according to the repaired spectral information, and a spectral feature vector is obtained by feature extraction according to the spectral matrix, where the spectral feature vector is a characteristic wavelength.

7. The method according to claim 1, characterized in that After step S5, the following steps are included: Evaluate and provide feedback on the preset machine learning method, and optimize the preset machine learning method based on the evaluation and feedback results.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the beef quality detection method based on spectral analysis according to any one of claims 1 to 7 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the beef quality detection method based on spectral analysis as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Meat product freshness detection method based on spectral imaging technology

    CN105548029A

  • Method and system for establishing tongue picture classification model of different insomnia degrees based on map fusion

    CN118982709A