Beef quality detection method based on spectral analysis
Through the detection method based on spectral analysis, combined with the preprocessing of image and spectral information, feature extraction and multi-head attention mechanism, the destructiveness and laboratory dependence of traditional detection methods are solved, and lossless and efficient beef quality detection is achieved.
Patent Information
- Application Number
- CN202510204757.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-24
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2045-02-24
AI Technical Summary
Traditional chemical testing methods have problems of destructive sampling and laboratory conditions dependence on beef quality testing, which is difficult to meet the needs of large-scale testing.
Using a detection method based on spectral analysis, the image information on the beef surface and the spectral information obtained by the spectrometer are obtained through the camera for pre-processing. The feature vectors are extracted by combining the threshold segmentation method and the convolutional neural network, and the multi-head attention mechanism is used for weighting, and finally the quality evaluation is performed through machine learning methods.
The non-destructive testing of beef quality can be achieved, and the beef can be detected from multiple angles, removing the impact of dark areas and reflective areas on detection, and improving the expression ability, robustness, generalization ability and interpretability of the detection.
Smart Images

Figure CN119991722A_ABST
Abstract
Description
Technical Field
[0001] The 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 the Chinese people, and its consumption has been increasing year by year. It plays an increasingly important role in global protein consumption. However, beef is easily contaminated by spoilage microorganisms and processing during cutting, which affects the shelf life of the product and poses a health risk to consumers. In addition, the prices of beef of different qualities vary greatly in the market. The market needs to grade the quality of beef to adapt to different consumer groups and better classify consumption. Therefore, there is an urgent need to test and grade the quality of beef. However, the use of traditional chemical methods for testing usually requires destructive sampling and often needs to be carried out under laboratory conditions, which is 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 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, obtaining a dark area, repairing the dark area, and extracting features based on the first image information of the repaired dark area to obtain a first feature vector; Step S3: segmenting the preprocessed spectral information using a second threshold segmentation method, obtaining a reflective area, repairing the reflective area, and extracting a spectral feature vector from the repaired spectral information using a convolutional neural network; Step S4: weighting the first feature vector and the spectral feature vector based on a multi-head attention mechanism to obtain a second feature vector; Step S5: learning and classifying according to the second feature vector through a preset machine learning method, and outputting 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 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 and 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 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 uses a spectral matrix to extract 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.
[0009] Preferably, the step S4 comprises: performing linear transformation on the first feature vector and the spectral feature respectively to generate a query matrix Q, a key matrix K and a value matrix V;
[0010] The attention score is calculated 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 different weight matrices each time, to obtain the output vectors of multiple independent attention heads, and 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 addition of the elements corresponding to the output vectors of the multiple attention heads, n is the total number of the output vectors of the attention heads, and α, β and γ are weighted parameters for controlling the balance of the output vectors of the multiple attention heads.
[0015] Preferably, after step S5, it 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, including 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 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 as follows: first image information of the surface of beef to be tested is obtained based on a camera, spectral information of the beef to be tested is obtained based on a spectrometer, and the first image information and the spectral information are preprocessed to obtain first feature information respectively; the preprocessed first image information is segmented by a first threshold segmentation method to obtain dark areas, the dark areas are repaired, and features are extracted based on the first image information of the repaired dark areas; the preprocessed spectral information is segmented by a second threshold segmentation method to obtain reflective areas, the reflective areas are repaired, and a spectral feature vector is extracted from the repaired spectral information using a convolutional neural network; 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, and an evaluation result of the quality of the beef to be tested is output. Nondestructive 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 used 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 solution. 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 specific implementations, 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 A schematic flow chart of detailed implementation steps for obtaining the dark area in step S2; DETAILED DESCRIPTION
[0023] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme 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...), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication 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 used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such 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 FIG. 1 is a hardware structure block diagram of a mobile terminal for a method for detecting beef quality 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 in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can 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 as 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, to implement the above 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 arranged 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. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0029] A schematic flow chart of a method for detecting beef quality based on spectral analysis in 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, the method comprising the following steps:
[0030] 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;
[0031] In the embodiment of the present application, the camera and the spectrometer are ensured to shoot the beef surface at a fixed position and angle to obtain a consistent image and control the lighting conditions to avoid being too bright or too dark, ensure the image quality, and control the temperature, humidity and other conditions of the measurement environment to avoid interference with the spectrometer by external factors.
[0032] The preprocessing of the first image information and the spectral information includes: the preprocessing of the first image information includes edge detection, cropping, and contrast enhancement; the preprocessing of 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; for the image of the retained beef part, using an adaptive histogram equalization method to enhance the contrast of the first image.
[0034] The preprocessing of spectral information includes: using polynomial fitting method to perform baseline correction, eliminating background signals and other interferences, and making spectral data more accurate; specifically including: reading spectral data files; polynomial fitting: using polynomial fitting method to fit the baseline of spectral data; baseline correction: subtracting the fitted baseline from the original spectral data to obtain the corrected spectral data. Use moving average filter to denoise, call the function moving_average_filter that implements the moving average filter for denoising, for example, moving_average_filter(spectrum,window_size=5), where spectrum(numpy.ndarray): input spectral data, window_size(int): the size of the moving average window, the default is 5, and the window size window_size parameter can be adjusted as needed. Finally, use the minimum-maximum normalization method to calculate the minimum and maximum values in the spectral data, and normalize the spectral data to between 0-1 for easy model processing.
[0035] Step S2, segmenting the preprocessed first image information using a first threshold segmentation method to obtain a dark area, repairing the dark area, and extracting features based on the first image information of the repaired dark area to obtain a first feature vector;
[0036] In this embodiment, the first threshold segmentation method is used to segment the preprocessed 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; 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, the color histogram is used to extract color features, the gray level co-occurrence matrix (GLCM) is calculated to extract texture features, and the texture features are extracted by calculating the contour and regional attributes of the image.
[0039] Step S3, the second threshold segmentation method is used 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, the OTSU threshold method is used 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 segmented image band: Use the np.argmin function to find the band index with the smallest information entropy as the optimal segmented image band.
[0041] In the optimal segmentation image band, the OTSU threshold method is used to extract the reflective area: Assuming that the image has two parts, 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 types 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 the segmentation threshold K is selected by calculation so that the inter-class variance θ 2When (k) reaches the maximum, the segmentation threshold K at this time is taken as the optimal segmentation threshold, and the reflective area is extracted based on the segmentation threshold K to obtain the reflective area image. Visualization results: Use matplotlib to draw the characteristic curve, the optimal band image and the reflective area image. Save the reflective area image: Save the extracted reflective area image to a file.
[0042] The spectral information based on the repaired reflective area uses a spectral matrix to extract 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] Among them, the spectral data is reshaped into a two-dimensional array, each row represents a pixel point, 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 the principal component analysis method. The spectral data of the reflective area is repaired by bringing the principal component of the reflective area closer to the principal component of the non-reflective area. This can be achieved by 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, which is usually determined according to the degree of reflection to achieve adjustment and repair of the reflective area, and the repaired spectral data is reinserted into the original spectral data and reshaped back to the original image.
[0044] A spectral matrix is constructed according to the modified spectral information, and a spectral feature vector is obtained by feature extraction according to the spectral matrix, wherein the spectral 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. Obtain 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 feature vector and the spectral feature vector based on a multi-head attention mechanism to obtain a second feature vector;
[0047] In this embodiment, the first feature vector 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 to ensure 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 different weight matrices each time, to obtain the output vectors of multiple independent attention heads, and 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 the output vectors of the attention heads, 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 using a preset machine learning method, and an evaluation result of the quality of the beef to be tested 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, 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 used to input the encoded classification feature vector into the 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 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; the preprocessed first image information is segmented by a first threshold segmentation method to obtain a dark area, the dark area is repaired, and feature extraction is performed based on the first image information of the repaired dark area to obtain a first feature vector; the preprocessed spectral information is segmented by a second threshold segmentation method to obtain a reflective area, the reflective area is repaired, and a convolutional neural network is used to extract a spectral feature vector 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, 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 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, so that the beef is tested and analyzed from multiple angles. The threshold segmentation algorithm is also used to segment, repair and optimize the image, thereby removing the influence of dark and reflective areas on the 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, and 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 may be provided as methods, systems or computer program products. Therefore, the present application may 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 may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to 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 generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. 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 capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A 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 operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0062] In a typical configuration, a computing device includes one or more processors (CPU), 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 include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. 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 disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape 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 temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0065] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0066] The above are only 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 modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should 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 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 a dark area, repairing the dark area, 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 preprocessed 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; Step S4: weighting the first feature vector and the spectral feature vector based on a multi-head attention mechanism to obtain a second feature vector; Step S5: Based on the second feature vector, learning and classification are performed using a preset machine learning method to output a quality assessment result of the beef to be tested.
2. The method according to claim 1, characterized in that The preprocessing of the first image information and the spectral information comprises: 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 preprocessed first image information using a first threshold segmentation method to obtain a dark area includes: Loading the first image information after preprocessing, and converting the first image information from an RGB image to an HSV image; Extract the brightness channel V, the saturation channel S and the hue channel H from the HSV image and set the brightness threshold, the saturation threshold and the 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, including: 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 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; Extracting first feature information of the preprocessed and restored first image information, wherein the first feature information includes color features, texture features, and morphological features; Among them, the color histogram is used to extract color features, the gray level co-occurrence matrix is calculated to extract texture features, and the contour and regional attributes of the image are calculated to extract texture features.
5. The method according to claim 1, characterized in that: The step of segmenting the spectral information after the preprocessing by using the second threshold segmentation method to obtain the 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 segmented bands, the reflective area is extracted by using the OTSU threshold method to obtain the reflective area.
6. The method according to claim 1, characterized in that The step of obtaining a spectral feature vector by extracting a spectral matrix based on the repaired spectral information 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, wherein the spectral feature vector is a characteristic wavelength.
7. The method according to claim 1, characterized in that 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; The attention score is calculated 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 different weight matrices each time, to obtain the output vectors of multiple independent attention heads, and concatenate all the attention head output vectors to obtain the second eigenvector using the following formula, where the formula is: F a =αF1⊕βF2⊕…⊕γF n , 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 number of output vectors of the attention heads, α, β and γ are weighted parameters for controlling the balance of the output vectors of the multiple attention heads.
8. The method according to claim 1, characterized in that After step S5, the following steps are included: The preset machine learning method is evaluated and feedback is provided, and the preset machine learning method is optimized based on the evaluation and feedback results.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the beef quality detection method based on spectral analysis as described in any one of claims 1 to 7 is implemented.
10. 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 online non-destructive testing method and apparatus based on fusion of image and spectrum information
CN101551341A
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
Assembled intelligent self-adaptive illumination multispectral lens microscopic detection system
CN119044080A
Agricultural product detection method, electronic equipment and computer readable storage medium
CN119198624A