A food freshness detection method, system and device based on machine vision and functionalized metal organic framework composite material
By using a core-shell structured pH-responsive unit and machine vision technology in the smart packaging film, the interfacial compatibility problem of the smart packaging film was solved, enabling early and accurate warning and comprehensive assessment of food freshness, thereby improving food safety levels.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA AGRI UNIV
- Filing Date
- 2026-02-03
- Publication Date
- 2026-06-12
AI Technical Summary
In existing technologies, smart packaging films suffer from interface compatibility issues, leading to the aggregation of functional particles, a decrease in film mechanical properties, impaired optical transparency, and uneven indication response. They are unable to achieve a balance between rapid and sensitive response during shelf life and during spoilage. Furthermore, traditional computer vision methods have limited feature extraction capabilities, making it difficult to achieve accurate and automated interpretation.
A core-shell structured pH response unit is constructed by coating an ovalbumin-sodium alginate nanocomposite with a cyclodextrin-based metal-organic framework loaded with a natural pH indicator. This is combined with machine vision and a multi-head self-attention mechanism to build a visual encoder converter architecture, enabling feature extraction and classification.
It improves the mechanical properties, optical transparency, and color response uniformity of the smart packaging film, enabling early and accurate warnings, reducing the false judgment rate, automatically determining food freshness and generating comprehensive evaluation reports, and providing convenient and accurate food quality assessment.
Smart Images

Figure CN122200629A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine learning technology, and in particular to a method, system and device for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials. Background Technology
[0002] With consumers increasingly focused on food quality and safety, and the global food supply chain becoming more complex, traditional production date-expiration date labels are no longer sufficient to meet the market's demand for real-time, dynamic monitoring of food conditions. Smart packaging, as a core driver of the food industry's transformation and upgrading, is undergoing a shift from traditional passive packaging to proactive sensing and real-time feedback. Among these, pH-responsive smart packaging films have attracted significant attention due to their ability to sensitively monitor volatile alkaline substances produced during the spoilage of high-protein foods such as meat and seafood. The decomposition of proteins by microorganisms produces alkaline substances such as ammonia and amines, leading to an increase in the food's pH value. pH-responsive smart packaging films can directly reflect this process through color changes, providing real-time visual feedback to consumers and supply chain managers. Simultaneously, in response to the global call for sustainable development and to reduce plastic pollution, developing film-forming matrices based on biodegradable and biocompatible polymers has become a mainstream technological approach. Furthermore, with the development of artificial intelligence and machine vision technologies, combining smart materials with deep learning algorithms to achieve automated and precise monitoring of food quality has become a cutting-edge research direction in the field of smart packaging.
[0003] While existing technologies have explored the encapsulation of natural pH indicators (such as anthocyanins) in carriers like metal-organic frameworks (MOFs) to prepare smart packaging films, these technologies generally face severe interfacial compatibility issues. Specifically, significant differences in surface properties and interfacial energy mismatch exist between MOF particles and polymer matrices (such as starch and polyvinyl alcohol), leading to severe agglomeration of functional particles during the blending process. This agglomeration triggers a series of negative chain reactions: a significant decrease in film mechanical properties, with agglomerates forming defects and stress concentration points, making the film brittle and fragile; severely impaired optical transparency, with large agglomerates strongly scattering incident light, resulting in a blurred film; and poor uniformity of indication response, as agglomeration leads to uneven indicator distribution, causing localized differences in the film's color change response and even non-responsive areas, severely compromising the reliability and accuracy of the indication. More importantly, existing technologies cannot strike a balance between high stability during shelf life and rapid and sensitive response to spoilage, resulting in indicators either becoming ineffective and fading before the food spoils, or having a delayed response that fails to provide early warning.
[0004] Furthermore, even though some studies have attempted to introduce image recognition technology to assist in interpreting color changes in packaging films, they mostly employ traditional computer vision methods or basic neural networks. These methods have limited feature extraction capabilities, are not robust enough to complex and non-uniform color change patterns, and lack a mechanism for deep collaboration with smart packaging materials, making it difficult to achieve accurate automated interpretation. Summary of the Invention
[0005] This invention provides a method, system, and device for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, in order to overcome the shortcomings of existing technologies.
[0006] This invention provides a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, comprising:
[0007] S1: Acquire a target food image covered with pH response units, perform preprocessing operations on the target food image, and generate standardized image data; S2: Divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence; S3: Based on the visual encoder transformer architecture, feature extraction is performed on the feature embedding vector sequence. The association weights between image patches in the feature embedding vector sequence are calculated using a multi-head self-attention mechanism. After processing by a feedforward neural network, a global feature representation is output. S4: Input the global feature representation into the classification prediction module, and obtain the probability distribution of food freshness category through multilayer perceptron mapping. Output the freshness discrimination result according to the probability distribution.
[0008] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials is provided. In step S1, the pH response unit has a core-shell structure. The core is a cyclodextrin-based metal-organic framework loaded with a natural pH indicator, and the shell is an ovalbumin-sodium alginate nanocomposite. When the freshness of the target food changes and volatile basic nitrogen is generated, the natural pH indicator loaded in the pH response unit undergoes a reversible or irreversible color change.
[0009] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials is provided, wherein the preparation process of the pH response unit includes: S111: Cyclodextrin-based metal-organic frameworks were synthesized by a room temperature aqueous phase method. Natural pH indicator was mixed with the cyclodextrin-based metal-organic framework in a solvent in the dark. After filtration and drying, a porous carrier loaded with natural pH indicator was obtained. S112: Prepare ovalbumin solution and sodium alginate solution, adjust the pH of the system to 4.0, and use the composite coagulation method to make the ovalbumin solution and sodium alginate solution self-assemble on the surface of the porous carrier loaded with natural pH indicator to form an ovalbumin-sodium alginate nanocomposite shell with pH response gating function. S113: The pH-responsive unit with a core-shell structure is dispersed in a film-forming matrix solution, which is obtained by blending plasma-modified polysaccharide with a water-soluble synthetic polymer. The film-forming matrix solution in which the pH-responsive unit is dispersed is then subjected to a casting film-forming process to form a smart packaging film.
[0010] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite material is provided. In step S111, the mass ratio of the natural pH indicator to the cyclodextrin-based metal-organic framework is 1:1 to 1:6, and the mass ratio of the porous carrier loaded with the natural pH indicator to the ovalbumin-sodium alginate nanocomposite is 1:18 to 5:18. In step S113, the mass ratio of the pH response unit to the film-forming matrix in the film-forming matrix solution is 1.9:5 to 2.3:5, and the mass ratio of the plasma-modified polysaccharide to the water-soluble synthetic polymer is 1:4. The natural pH indicator is selected from at least one of anthocyanins, curcumin, betaine, alizarin, and shikonin; The plasma-modified polysaccharide is corn starch treated with dielectric barrier discharge plasma, and the water-soluble synthetic polymer is polyvinyl alcohol.
[0011] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials is provided. In step S112, the outer shell of the ovalbumin-sodium alginate nanocomposite has a pH-responsive gating function. In acidic or neutral environments (fresh high-protein foods), the carboxyl groups of sodium alginate in the shell of the ovalbumin-sodium alginate nanocomposite are in a protonated state, and the shell of the ovalbumin-sodium alginate nanocomposite shrinks to form a dense barrier, preventing the external environment from contacting the porous carrier loaded with the natural pH indicator. In an alkaline environment (for spoiled high-protein food), the deprotonation of the carboxyl groups of sodium alginate in the shell of the ovalbumin-sodium alginate nanocomposite generates electrostatic repulsion. The shell of the ovalbumin-sodium alginate nanocomposite expands, increasing its porosity, allowing volatile alkaline substances to enter the porous carrier loaded with a natural pH indicator and triggering the natural pH indicator to change color.
[0012] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, the step S1 of performing preprocessing on the target food image specifically includes: The target food image is subjected to denoising filtering to eliminate noise interference in the target food image; A white balance algorithm is used to correct the color temperature parameters of the target food image to compensate for the influence of light source color shift. The brightness of the target food image is normalized and adjusted according to a preset dynamic range.
[0013] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, step S2 further includes: S21: Divide the standardized image data into multiple two-dimensional image blocks according to the preset block size parameters; S22: Perform a flattening transformation on multiple two-dimensional image blocks to convert them into multiple one-dimensional vector representations; S23: Using a linear projection layer, multiple one-dimensional vector representations are mapped to a unified-dimensional embedding space to generate multiple image patch embedding vectors; S24: Based on the spatial coordinates of multiple two-dimensional image blocks in the standardized image data, add positional encoding to the corresponding image block embedding vector to form a feature embedding vector sequence.
[0014] The present invention provides a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, wherein step S3 further includes: S31: Feed the feature embedding vector sequence into the multi-head self-attention layer of the visual encoder transformer architecture; S32: In the multi-head self-attention layer, the query matrix, key matrix, and value matrix are calculated based on the feature embedding vector sequence; S33: Quantify the dependency strength between different image patch features in the feature embedding vector sequence using the attention score calculation mechanism, and generate attention-enhanced feature representations by weighted summation; S34: Perform residual connection and layer normalization processing on the attention-enhanced feature representation to obtain a normalized feature representation; S35: The normalized feature representation is fed into a feedforward neural network to perform a nonlinear transformation, and after residual connection and layer normalization, a global feature representation is output.
[0015] According to the food freshness detection method based on machine vision and functionalized metal-organic framework composite materials provided by the present invention, the training process of the visual encoder converter architecture in step S3 includes: S311: Construct a labeled dataset containing multiple sets of labeled samples. Each set of labeled samples includes a food image covered with the pH response unit, the corresponding freshness category label, the volatile basic nitrogen content measured in the laboratory, the thiobarbituric acid reactant value, the pH value, and the total number of colonies. S312: Divide the labeled dataset into a training set and a test set according to a preset ratio; S313: The visual encoder transformer architecture is trained end-to-end using the training set, and the model parameters of the visual encoder transformer architecture are continuously optimized through the backpropagation algorithm so that the weighted sum of the classification loss function and the regression loss function converges to the minimum value. S314: Use the test set to evaluate the prediction task performance of the trained visual encoder transformer architecture, and complete the model training when both the classification accuracy and regression prediction error meet the preset thresholds.
[0016] According to the present invention, a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, step S4 further includes: S41: Extract the category label feature vector from the global feature representation; S42: Input the category label feature vector into a multilayer perceptron, and perform a nonlinear mapping transformation on the category label feature vector through multiple fully connected layers; S43: Apply the softmax activation function to the output layer of the multilayer perceptron to calculate the predicted probabilities of multiple freshness categories and form a probability distribution; S44: Select the category corresponding to the maximum predicted probability in the probability distribution as the freshness discrimination result of the target food, wherein the freshness discrimination result includes fresh, slightly fresh and spoiled.
[0017] The food freshness detection method based on machine vision and functionalized metal-organic framework composite materials provided by the present invention further includes: S5: Based on the global feature representation, predict food quality indicators and obtain a comprehensive evaluation report; Step S5 further includes: S51: Based on the global feature representation, estimate the volatile basic nitrogen content, thiobarbituric acid reactant value and pH value of the target food through regression prediction branch; S52: Based on the global feature representation, predict the total number of colonies in the target food, and output the microbial risk result corresponding to the total number of colonies according to the preset safety threshold. The microbial risk result includes high risk level, medium risk level and low risk level. S53: Integrate the freshness assessment results, the volatile basic nitrogen content, the thiobarbituric acid reactant value, the pH value, and the microbial risk results to generate a comprehensive assessment report on the freshness of the target food.
[0018] A second aspect of the present invention provides a food freshness detection system based on machine vision and functionalized metal-organic framework composite materials, for performing a food freshness detection method based on machine vision and functionalized metal-organic framework composite materials as described in any one of the preceding claims, comprising: Acquisition module: used to acquire images of target food covered with pH response units, perform preprocessing operations on the target food images, and generate standardized image data; Transformation module: used to divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence; Extraction module: used to perform feature extraction on the feature embedding vector sequence based on the visual encoder transformer architecture, calculate the correlation weight between image patches in the feature embedding vector sequence using a multi-head self-attention mechanism, and output the global feature representation after processing by a feedforward neural network; Prediction module: It is used to receive the global feature representation, map it through the built-in multilayer perceptron to obtain the probability distribution of food freshness category, and output the freshness discrimination result according to the probability distribution.
[0019] A third aspect of the present invention also provides a food freshness detection device based on machine vision and functionalized metal-organic framework composite materials, comprising: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a food freshness detection device based on machine vision and functionalized metal-organic framework composite material to perform a food freshness detection method based on machine vision and functionalized metal-organic framework composite material as described above.
[0020] A fourth aspect of the present invention also provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a food freshness detection method based on machine vision and functionalized metal-organic framework composite materials as described in any of the preceding claims.
[0021] The fifth aspect of the present invention also provides a computer program product, including a computer program, wherein a processor of a computer device reads the computer program from a computer-readable storage medium, and the processor executes the computer program, causing the computer device to perform any of the above-described methods for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials.
[0022] This invention achieves multiple synergistic effects by constructing a core-shell structure for pH-responsive units, coating an ovalbumin-sodium alginate nanocomposite with a cyclodextrin-based metal-organic framework loaded with a natural pH indicator. The nanocomposite shell provided by this invention acts as an interfacial compatibilizer, effectively solving the interfacial incompatibility problem between functional particles and the polymer matrix. This allows the pH-responsive units to be uniformly and stably dispersed at the nanoscale in the film-forming matrix, avoiding aggregation. Consequently, it significantly improves the mechanical properties, optical transparency, and color response uniformity of the smart packaging film, ensuring the reliability and stability of the film in practical applications.
[0023] In addition, the shell has a unique pH-responsive gating function. In the acidic or neutral environment when food is fresh, it shrinks to form a dense barrier, which greatly enhances the stability of the indicator and effectively prevents the indicator from degrading prematurely and migrating into the food. In the alkaline environment caused by food spoilage, it automatically expands to open the channel, allowing volatile alkaline substances to enter quickly and trigger the indicator to change color sensitively. This fundamentally solves the technical contradiction between high stability during shelf life and rapid and sensitive response during spoilage, and achieves early and accurate warning.
[0024] On the other hand, this invention deeply integrates the functionalized material with a visual encoder converter architecture, utilizing a multi-head self-attention mechanism to capture the complex correlations and global information of different regions in an image. This overcomes the limitations of traditional methods in handling non-uniform color changes, achieving extremely high recognition accuracy and significantly reducing the false positive rate, outperforming traditional machine learning and deep learning models. Through multilayer perceptrons for accurate classification and regression prediction of global feature representations, it can not only automatically determine the freshness level of food but also simultaneously estimate multidimensional quality indicators such as volatile basic nitrogen content, thiobarbituric acid reactant values, pH value, and microbial risk, generating a comprehensive evaluation report. This achieves end-to-end automated monitoring from material sensing to intelligent interpretation, providing consumers and supply chain managers with a convenient, accurate, and contactless food quality assessment solution. It effectively reduces food waste, improves food safety levels, and has significant practical value and broad application prospects. Attached Figure Description
[0025] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0026] Figure 1A schematic diagram of a food freshness detection method based on machine vision and functionalized metal-organic framework composite materials provided in an embodiment of the present invention; Figure 2 A schematic diagram showing the classification results of a model based on a food freshness detection method using machine vision and functionalized metal-organic framework composite materials, provided in an embodiment of the present invention. Figure 3 A schematic diagram of a food freshness detection system based on machine vision and functionalized metal-organic framework composite material is provided in an embodiment of the present invention. Figure 4 This is a schematic diagram of a food freshness detection platform based on machine vision and functionalized metal-organic framework composite material, provided in an embodiment of the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, embodiments of this invention, and should not be construed as limiting the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. In the description of this invention, it should be understood that the terminology used is for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0028] The embodiments of the present invention are described below with reference to the figures.
[0029] like Figure 1 As shown, this invention provides a method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, comprising: S1: Acquire a target food image covered with pH response units, perform preprocessing operations on the target food image, and generate standardized image data.
[0030] Furthermore, the color change produced by the pH response unit in step S1 in response to the volatile alkaline substances released during the spoilage of the target food has a pre-established mapping relationship with the freshness category of the food. Specifically, the acquisition of the target food image in step S1 depends on the smart packaging film covering the target food, which contains a pH response unit. When the pH response unit comes into contact with the volatile basic nitrogen produced by the spoilage of the target food, the natural pH indicator loaded on it undergoes a reversible or irreversible color change. The hue, saturation, or brightness characteristics of the color change constitute the visual information basis for feature extraction and classification by the visual encoder converter architecture in step S3.
[0031] In step S1, the pH-responsive unit has a core-shell structure, with the core being a cyclodextrin-based metal-organic framework loaded with a natural pH indicator, and the shell being an ovalbumin-sodium alginate nanocomposite. The preparation process of the pH-responsive unit includes: S111: Cyclodextrin-based metal-organic frameworks were synthesized by a room-temperature aqueous phase method. Natural pH indicators were mixed with the cyclodextrin-based metal-organic frameworks in a solvent in the dark. After filtration and drying, a porous carrier loaded with natural pH indicators was obtained.
[0032] In step S111, the mass ratio of the natural pH indicator to the cyclodextrin-based metal-organic framework is 1:1 to 1:6, and the mass ratio of the porous carrier loaded with the natural pH indicator to the ovalbumin-sodium alginate nanocomposite is 1:18 to 5:18.
[0033] Furthermore, in this invention, the mass ratio of the natural pH indicator to the cyclodextrin-based metal-organic framework is set to a range of 1:1 to 1:6. When the mass ratio is 1:1, the pore capacity of the cyclodextrin-based metal-organic framework is relatively limited compared to the amount of natural pH indicator. Some natural pH indicator molecules cannot enter the pores and can only be adsorbed on the outer surface of the framework. Excess anthocyanin molecules aggregate on the carrier surface or cause pore blockage, thereby limiting the effective adsorption and encapsulation of anthocyanins, resulting in low loading efficiency. As the amount of cyclodextrin-based metal-organic framework increases, the total pore volume increases, and more natural pH indicator molecules can be effectively encapsulated inside the pores, significantly improving the loading efficiency.
[0034] Experimental data show that when the mass ratio of natural pH indicator to cyclodextrin-based metal-organic framework (MOF) reaches 1:2, the loading reaches a peak of 47.6%, at which point the pore space and the number of indicator molecules are optimally matched. Further increasing the proportion of MOF leads to a decrease in anthocyanin loading. Excess MOF particles are prone to aggregation in solution, causing some effective pores to be masked. Furthermore, the concentration gradient driving force for indicator diffusion into the pores is weakened by the dilution effect, resulting in a decrease in the actual loading capacity per unit mass of carrier. Although the pore capacity is sufficient, the reduced indicator content per unit mass of composite material weakens the color response signal intensity of the smart packaging film, affecting the clarity and sensitivity of visual interpretation. Simultaneously, an excessively high proportion of cyclodextrin-based MOF increases material cost and the content of inorganic components in the matrix, adversely affecting the film's flexibility. Therefore, the 1:1 to 1:6 ratio range of this invention ensures both high loading efficiency and indicator stability while balancing response signal intensity and overall film performance, with a mass ratio of 1:2 being the optimal choice.
[0035] Furthermore, in this invention, the mass ratio of the porous carrier loaded with the natural pH indicator to the ovalbumin-sodium alginate nanocomposite is set in the range of 1:18 to 5:18, which can improve the integrity of the shell coating, interfacial compatibility, and the effectiveness of the pH response gating function. When the proportion of the ovalbumin-sodium alginate nanocomposite is low, and the mass ratio is close to the upper limit of 5:18, although a preliminary shell layer can be formed on the surface of the pH indicator core, the shell thickness is relatively thin (about 10-20 nm), the coating density is insufficient, and some core surfaces are not completely covered. The incomplete coating causes some of the natural pH indicator in the core to be exposed to the external environment, reducing the protective effect of the shell on the indicator. At the same time, the interfacial compatibility is weakened, and the pH response unit still has a slight tendency to aggregate in the film-forming matrix. As the amount of ovalbumin-sodium alginate nanocomposite increases, the shell layer gradually thickens (20-50 nm), the coating integrity is significantly improved, and the core is completely wrapped by a dense and uniform shell. When the mass ratio of the porous carrier loaded with the natural pH indicator to the ovalbumin-sodium alginate nanocomposite is 3:18, the coating effect of the shell is optimal. At this ratio, the film exhibits the best performance in terms of antioxidant properties, sustained-release effect, mechanical properties, color stability, hydrophobicity, and swelling degree. The nanocomposite shell not only provides a strong and effective physicochemical barrier, greatly enhancing the stability and safety of the indicator, but also fully utilizes its role as an interface compatibilizer. The biomacromolecules (ovalbumin and sodium alginate) on its surface form a large number of hydrogen bonds and van der Waals forces with the hydrophilic polymers (polyvinyl alcohol and modified starch) in the film-forming matrix, enabling the pH response units to be uniformly and stably dispersed in the matrix at the nanoscale, avoiding aggregation and ensuring the excellent optical transparency, mechanical properties, and color response uniformity of the smart packaging film.
[0036] S112: Prepare ovalbumin solution and sodium alginate solution, adjust the pH of the system to 4.0, and use a composite coagulation method to make the ovalbumin solution and sodium alginate solution self-assemble on the surface of a porous carrier loaded with a natural pH indicator to form an ovalbumin-sodium alginate nanocomposite shell with pH response gating function.
[0037] In step S112, the outer shell of the ovalbumin-sodium alginate nanocomposite has a pH-responsive gating function: In acidic or neutral environments, the carboxyl groups of sodium alginate in the shell of the ovalbumin-sodium alginate nanocomposite are in a protonated state, and the shell of the ovalbumin-sodium alginate nanocomposite contracts to form a dense barrier, preventing the external environment from contacting the porous carrier loaded with the natural pH indicator. In alkaline environments, the carboxyl groups of sodium alginate in the shell of the ovalbumin-sodium alginate nanocomposite deprotonate, generating electrostatic repulsion, and the shell of the ovalbumin-sodium alginate nanocomposite expands to increase porosity, allowing volatile alkaline substances to enter the porous carrier loaded with the natural pH indicator and triggering the natural pH indicator to change color.
[0038] The ovalbumin-sodium alginate nanocomposite shell constructed in this invention possesses an intelligent pH-responsive gating function. This function is based on the conformational changes of the sodium alginate molecular chain under different pH environments. Under acidic or neutral environments, corresponding to the fresh state of food, the carboxyl groups on the sodium alginate molecular chain accept protons and transform into the -COOH form, entering a protonated state. Protonation causes the carboxyl groups to lose their negative charge, the electrostatic repulsion between sodium alginate molecular chains disappears, and the molecular chains contract and curl, while the electrostatic attraction between them and the positively charged ovalbumin is enhanced. Under this synergistic effect, the entire ovalbumin-sodium alginate nanocomposite shell shrinks and densifies, significantly reducing porosity and forming a tight physicochemical barrier. This isolates the porous carrier loaded with the natural pH indicator from the external environment, blocking the erosion of the indicator by oxygen, heat, light, and moisture, and preventing premature degradation and outward migration of the indicator.
[0039] When food spoils, protein decomposes to produce volatile alkaline substances such as ammonia and trimethylamine, raising the local pH level to an alkaline state. At this time, the carboxyl group of sodium alginate loses a proton and reverts to -COO. - The protein carries a negative charge. The dense distribution of a large number of negative charges on the molecular chain generates a strong electrostatic repulsion, forcing the molecular chain to stretch and expand. At the same time, ovalbumin also carries a negative charge under alkaline conditions. The electrostatic attraction between the two turns into repulsion, jointly driving the expansion of the shell structure and increasing the porosity.
[0040] The expanded outer shell forms a permeable channel, allowing volatile alkaline substances in the environment to quickly penetrate the shell and enter the cyclodextrin channels in the core. Through host-guest interactions, the microenvironment pH of the indicator is changed, triggering the natural pH indicator to change from purple-red to blue-green. The on / off switching mechanism provided by this invention enables the smart packaging film to maintain high stability during shelf life and achieve sensitive response during spoilage, thus resolving the contradiction between the stability and responsiveness of pH indicators.
[0041] S113: The pH-responsive unit with a core-shell structure is dispersed in a film-forming matrix solution, which is obtained by blending plasma-modified polysaccharide with a water-soluble synthetic polymer. The film-forming matrix solution in which the pH-responsive unit is dispersed is then subjected to a casting film-forming process to form a smart packaging film.
[0042] In step S113, the mass ratio of the pH response unit to the film-forming matrix in the film-forming matrix solution is 1.9:5 to 2.3:5, and the mass ratio of the plasma-modified polysaccharide to the water-soluble synthetic polymer is 1:4.
[0043] The natural pH indicator is selected from at least one of anthocyanins, curcumin, betalains, alizarin, and shikonin; the plasma-modified polysaccharide is corn starch treated with dielectric barrier discharge plasma; and the water-soluble synthetic polymer is polyvinyl alcohol.
[0044] Furthermore, in this invention, the mass ratio of the pH-responsive unit to the film-forming substrate is set to a range of 1.9:5 to 2.3:5. This ratio range has a decisive impact on the final performance of the smart packaging film. When the amount of pH-responsive unit added is low, at a mass ratio of 1.9:5, the concentration of the indicator in the film is relatively low. Although the optical transparency and mechanical properties of the film remain at a high level, the visual contrast of the color response is weak, requiring consumers to observe carefully to distinguish the color change, which is not conducive to quickly determining the freshness of food. As the amount of pH-responsive unit added increases, the concentration of the indicator in the film gradually increases, the visual contrast of the color response is significantly enhanced, and the color change effect is more obvious and intuitive.
[0045] Experimental data shows that when the mass ratio is 2.1:5, the film exhibits a clear gradient from purplish-red to blue-green during salmon spoilage, easily identifiable to the naked eye. Simultaneously, at this ratio, the film achieves an optimal balance between elongation at break and elastic modulus, possessing sufficient strength to withstand mechanical stress during packaging while maintaining good flexibility to adapt to changes in the shape and volume of the food. Further increasing the proportion of pH-responsive units to the upper limit of 0.5:5, while further enhancing the color response intensity, the excessively high inorganic filler content begins to negatively impact the film's mechanical, antioxidant, and color stability properties. The film's flexibility decreases, its brittleness increases, and it becomes prone to breakage during folding or stretching.
[0046] Therefore, the mass ratio range of 1.9:5 to 2.3:5 achieves the best balance between properties such as color response sensitivity, visual contrast, antioxidant properties and film mechanical properties, ensuring the reliability and practicality of smart packaging films in practical applications.
[0047] Specifically, step S1, which involves performing preprocessing on the target food image, includes: applying noise filtering to the target food image to eliminate noise interference; using a white balance algorithm to correct the color temperature parameters of the target food image to compensate for the influence of light source color shift; and normalizing the brightness of the target food image according to a preset dynamic range.
[0048] Furthermore, after acquiring the target food image, this invention first performs denoising filtering on the target food image. Since the image acquisition process is inevitably affected by factors such as sensor thermal noise and ambient light interference, resulting in random noise points in the image, this invention uses a Gaussian filter to perform convolution operations on the target food image. By weighted averaging of each pixel and its neighboring pixels, the noise pixel values are smoothed, and the denoised image data is output. Subsequently, this invention uses a white balance algorithm to correct the color temperature parameters of the denoised image data. Because the color temperature differences of different light sources can cause the image to appear cooler or warmer, affecting the accuracy of color recognition, this invention calculates the average value of the R, G, and B channels in the image to determine the current color temperature offset. Then, the pixel values of each channel are scaled and adjusted to make the average values of the three channels more consistent, thereby compensating for the influence of light source color shift and outputting color-balanced image data. Next, the present invention normalizes the brightness of the color balance image data according to a preset dynamic range. The present invention statistically analyzes the brightness histogram distribution of the image, determines the minimum brightness value and the maximum brightness value, and then linearly maps the brightness values of all pixels to a standard range of 0-255, so that the overall brightness distribution of the image is uniform, thereby generating the standardized image data.
[0049] S2: Divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence.
[0050] Step S2 further includes: S21: Divide the standardized image data into multiple two-dimensional image blocks according to the preset block size parameters; S22: Perform a flattening transformation on the multiple two-dimensional image blocks to convert them into multiple one-dimensional vector representations; S23: Use a linear projection layer to map the multiple one-dimensional vector representations to an embedding space of the same dimension to generate multiple image block embedding vectors; S24: Add position encoding to the corresponding image block embedding vectors according to the spatial coordinates of the multiple two-dimensional image blocks in the standardized image data to form a feature embedding vector sequence.
[0051] Furthermore, in step S2, the present invention first divides the standardized image data into multiple two-dimensional image blocks according to a preset block size parameter. Specifically, assuming the size of the standardized image data is H×W×C (height×width×number of channels), and the preset block size is P×P pixels, the present invention divides the image along the height and width directions into P×P windows to generate N two-dimensional image blocks, where N=(H / P)×(W / P), and the size of each two-dimensional image block is P×P×C.
[0052] Subsequently, the present invention performs a flattening transformation on multiple two-dimensional image blocks. Specifically, the present invention reshapes each two-dimensional image block of size P×P×C into a one-dimensional vector of length P²×C, generating a total of N one-dimensional vector representations.
[0053] Next, this invention utilizes a linear projection layer to map multiple one-dimensional vector representations to an embedding space of uniform dimension. The linear projection layer includes a weight matrix W with dimensions (P²×C)×D, where D is the target embedding dimension. This invention performs matrix multiplication on each one-dimensional vector and the weight matrix W, converting a vector of length P²×C into an image patch embedding vector of length D, generating N image patch embedding vectors.
[0054] Finally, based on the spatial coordinates of multiple two-dimensional image blocks in the standardized image data, this invention adds positional encoding to the corresponding image block embedding vectors. For each spatial location (i, j), this invention predefines a positional encoding vector PE(i, j) of length D. Then, the image block embedding vector at position (i, j) is added element-wise to PE(i, j) to obtain a feature embedding vector containing spatial positional information. The final N feature embedding vectors are arranged in spatial order to form a feature embedding vector sequence.
[0055] S3: Based on the visual encoder transformer architecture, feature extraction is performed on the feature embedding vector sequence. The association weights between image patches in the feature embedding vector sequence are calculated using a multi-head self-attention mechanism. After processing by a feedforward neural network, a global feature representation is output.
[0056] Step S3 further includes: S31: Feed the feature embedding vector sequence into the multi-head self-attention layer of the visual encoder transformer architecture; S32: In the multi-head self-attention layer, calculate the query matrix, key matrix, and value matrix based on the feature embedding vector sequence; S33: Quantify the dependency strength between different image patch features in the feature embedding vector sequence using an attention score calculation mechanism, and generate an attention-enhanced feature representation by weighted summation; S34: Perform residual connection and layer normalization processing on the attention-enhanced feature representation to obtain a normalized feature representation; S35: Feed the normalized feature representation into a feedforward neural network to perform a nonlinear transformation, and output a global feature representation after residual connection and layer normalization.
[0057] In step S3, the present invention feeds the feature embedding vector sequence into the multi-head self-attention layer of the visual encoder transformer architecture. The feature embedding vector sequence is an N×D matrix, where N is the number of image patches and D is the embedding dimension. In the multi-head self-attention layer, the present invention calculates the query matrix Q, the key matrix K, and the value matrix V based on the feature embedding vector sequence. Specifically, the present invention performs matrix multiplication with the feature embedding vector sequence using the three weight matrices respectively to generate the query matrix Q, the key matrix K, and the value matrix V, all of which are of size N×D.
[0058] Subsequently, this invention utilizes an attention score calculation mechanism to quantify the dependency strength between features of different image patches in the feature embedding vector sequence. This invention calculates the matrix product of the query matrix Q and the transpose of the key matrix K to obtain an N×N attention score matrix, where the (i, j)th element represents the attention level of the i-th image patch to the j-th image patch. This invention normalizes each row of the attention score matrix using the softmax function to obtain an attention weight matrix. Next, this invention performs matrix multiplication between the attention weight matrix and the value matrix V, generating an attention-enhanced feature representation of size N×D through weighted summation. The feature vector of each image patch in this matrix incorporates information from all other image patches.
[0059] Then, the present invention performs residual connection and layer normalization processing on the attention-enhanced feature representation. The residual connection adds the attention-enhanced feature representation to the original feature embedding vector sequence element by element to obtain the residually connected features. Layer normalization calculates the mean and standard deviation for each vector of the residually connected features, and then performs standardization processing to obtain the normalized feature representation.
[0060] Finally, this invention feeds the normalized feature representation into a feedforward neural network to perform a nonlinear transformation. The feedforward neural network contains two fully connected layers. The first layer maps the D-dimensional vector to a higher dimension and applies the ReLU activation function; the second layer maps the high-dimensional vector back to D dimensions. This invention sequentially passes each vector of the normalized feature representation through these two fully connected layers to obtain the nonlinearly transformed features. Finally, this invention performs residual connections again on the nonlinearly transformed features, i.e., adds them to the normalized feature representation and performs layer normalization processing, outputting a global feature representation of size N×D.
[0061] The training process of the visual encoder transformer architecture in step S3 includes: S311: Construct a labeled dataset containing multiple sets of labeled samples. Each set of labeled samples includes a food image covered with the pH response unit, the corresponding freshness category label, the volatile basic nitrogen content (TVB-N), thiobarbituric acid reactive substance value (TBARS), pH value, and total bacterial count (TVS) measured in the laboratory. S312: Divide the labeled dataset into a training set and a test set according to a preset ratio. S313: Use the training set to perform end-to-end training on the visual encoder converter architecture. Continuously optimize the model parameters of the visual encoder converter architecture using the backpropagation algorithm, so that the weighted sum of the classification loss function and the regression loss function converges to a minimum value. S314: Use the test set to evaluate the prediction task performance of the trained visual encoder converter architecture. Model training is completed when both the classification accuracy and regression prediction error meet preset thresholds.
[0062] It should be noted that in step S311, the association logic between the food image covered with the pH response unit and the corresponding freshness category label is as follows: the freshness category label is divided according to the laboratory's determination results of the volatile basic nitrogen content / thiobarbituric acid reactant value of the same sample, and the pH response unit responds to volatile basic nitrogen at the same stage of spoilage and presents a specific color pattern in the image. The visual encoder converter architecture learns the nonlinear mapping relationship between the color pattern and the freshness category label through training.
[0063] Specifically, for the training process of the visual encoder transformer architecture, the present invention first constructs a dataset containing multiple sets of labeled samples, wherein each set of labeled samples includes a food image covered with the pH response unit, the corresponding freshness category label (such as fresh, less fresh, spoiled), and the volatile basic nitrogen content, thiobarbituric acid reactant value, pH value and total bacterial count of the food sample as determined by standard laboratory methods.
[0064] This invention collects 4000 labeled samples to form a dataset. Then, this invention divides the dataset into a training set and a test set according to a preset ratio. Specifically, this invention uses 3000 labeled samples as the training set and 1000 labeled samples as the test set in a 3:1 ratio.
[0065] Next, the present invention uses the training set to perform end-to-end training on the visual encoder transformer architecture. During training, the present invention sequentially inputs food images from the training set into the visual encoder transformer architecture, and after processing in steps S1 to S35, obtains a global feature representation. The present invention inputs the global feature representation into the classification head to predict the probability distribution of the freshness category, and calculates the cross-entropy loss between the predicted probability and the true category label as the classification loss function. Simultaneously, the present invention inputs the global feature representation into the regression head to predict the volatile basic nitrogen content, thiobarbituric acid reactant value, pH value, and total bacterial count, and calculates the mean squared error between the predicted value and the true value as the regression loss function.
[0066] This invention adds the classification loss function and the regression loss function with preset weights to obtain the total loss function. Using a backpropagation algorithm, this invention calculates the gradient of the total loss function with respect to all weight matrices in the visual encoder transformer architecture, and uses an optimizer (such as Adam) to update the parameter values of these weight matrices based on the gradient, iterating continuously until the total loss function converges to its minimum value.
[0067] Finally, this invention uses the test set to evaluate the prediction task performance of the trained visual encoder transformer architecture. Specifically, 1000 food images from the test set are input into the trained model to obtain predicted freshness categories and quality index values. This invention calculates the classification accuracy and regression prediction error. When the classification accuracy reaches 97.52% or higher and the regression prediction error is below a preset threshold, model training is completed, and the final visual encoder transformer architecture model is obtained.
[0068] S4: Input the global feature representation into the classification prediction module, and obtain the probability distribution of food freshness category through multilayer perceptron mapping. Output the freshness discrimination result according to the probability distribution.
[0069] Step S4 further includes: S41: Extract category label feature vectors from the global feature representation; S42: Input the category label feature vectors into a multilayer perceptron, and perform nonlinear mapping transformation on the category label feature vectors through multiple fully connected layers; S43: Apply the softmax activation function to the output layer of the multilayer perceptron to calculate the predicted probabilities of multiple freshness categories and form a probability distribution; S44: Select the category corresponding to the maximum predicted probability in the probability distribution as the freshness discrimination result of the target food, wherein the freshness discrimination result includes fresh, slightly fresh, and spoiled.
[0070] In step S4, the present invention first extracts a class label feature vector from the global feature representation, which is an N×D matrix, where N is the number of image patches and D is the embedding dimension. Specifically, the present invention pre-inserts a learnable class label vector (CLS token) at the beginning of the feature embedding vector sequence. This vector, after being processed through multiple layers of the visual encoder transformer architecture, aggregates the global information of the entire image. The present invention extracts this class label feature vector from the first row of the global feature representation to obtain a 1×D vector.
[0071] Subsequently, the present invention inputs the category label feature vector into a multilayer perceptron. The multilayer perceptron comprises at least two fully connected layers. The first layer performs matrix multiplication on the D-dimensional category label feature vector using a weight matrix W1 (size D×H, where H is the hidden layer dimension) to obtain a 1×H intermediate feature vector. Then, a ReLU activation function is applied to the intermediate feature vector for non-linear transformation, outputting the activated intermediate feature vector. The second layer performs matrix multiplication on the activated intermediate feature vector using a weight matrix W2 (size H×C, where C is the number of freshness categories) to obtain a 1×C output vector, where each element of this vector corresponds to the original score of a freshness category.
[0072] Next, the present invention applies the softmax activation function to the output layer of the multilayer perceptron. Specifically, the present invention performs an exponential operation on each element of the 1×C output vector, then adds all the exponent values to obtain a normalization factor, and then divides each exponent value by the normalization factor to obtain a 1×C probability distribution vector, where each element takes a value from 0 to 1, and the sum of all elements is 1. Each element of the obtained probability distribution vector represents the predicted probability that the target food belongs to the corresponding freshness category.
[0073] Finally, this invention selects the category corresponding to the maximum predicted probability in the probability distribution as the freshness determination result of the target food. Specifically, this invention iterates through the C elements of the probability distribution vector, finds the element with the largest value and its index position. According to the predefined category mapping relationship (index 0 corresponds to fresh, index 1 corresponds to slightly less fresh, and index 2 corresponds to spoilage), this invention converts the index corresponding to the maximum probability into a specific freshness category label and outputs the freshness determination result.
[0074] This also includes: S5: Based on the global feature representation, predict food quality indicators and obtain a comprehensive evaluation report.
[0075] Step S5 further includes: S51: Based on the global feature representation, estimate the volatile basic nitrogen content, thiobarbituric acid reactant value, and pH value of the target food through regression prediction branch; S52: Predict the total bacterial count of the target food based on the global feature representation, and output the microbial risk result corresponding to the total bacterial count according to the preset safety threshold. The microbial risk result includes high risk level, medium risk level, and low risk level; S53: Integrate the freshness discrimination result, the volatile basic nitrogen content, the thiobarbituric acid reactant value, the pH value, and the microbial risk result to generate a comprehensive evaluation report.
[0076] In step S5, based on the global feature representation, the present invention estimates the volatile basic nitrogen content, thiobarbituric acid reactant value, and pH value of the target food through a regression prediction branch. The regression prediction branch also extracts a class label feature vector (1×D dimensional vector) from the global feature representation, and then inputs this vector into a regression-specific multilayer perceptron. The first layer of the regression multilayer perceptron uses a weight matrix W3 (with dimensions D×D). Map the category label feature vector to 1× The hidden features, after ReLU activation, are processed by the second layer through a weight matrix W4 (size 1). The hidden features are mapped to a 1×2 output vector. The first element of this output vector is the predicted volatile basic nitrogen content (mg / 100g), the second element is the predicted thiobarbituric acid reactant value (mg MDA / kg sample), and the third element is the predicted pH value. This invention outputs these three values as the estimation result.
[0077] Subsequently, the present invention predicts the total bacterial count of the target food based on the global feature representation. The present invention again extracts the category label feature vector from the global feature representation and inputs it into a multilayer perceptron with another regression branch. The structure of this multilayer perceptron is similar to that described above, with the first layer mapping the D-dimensional vector to... The hidden features are processed by ReLU activation, and the second layer maps the hidden features to a 1D output to obtain the predicted total colony count (unit: ...). CFU / g).
[0078] Next, the present invention classifies the risk level of the total number of colonies according to a preset safety threshold. The present invention presets two thresholds, T1 and T2. After setting, the present invention compares the predicted total number of colonies with these two thresholds: if the total number of colonies ≤ T1, a low risk level is output; if T1 < total number of colonies ≤ T2, a medium risk level is output; if the total number of colonies > T2, a high risk level is output, thus forming the microbial risk result.
[0079] Finally, this invention integrates the freshness assessment results, the volatile basic nitrogen content, the thiobarbituric acid reactant value, the pH value, and the microbial risk results to generate a comprehensive assessment report. This invention creates a data structure (such as a JSON object or structured text), using the freshness assessment result (such as "nearly fresh") as the primary assessment conclusion, and sequentially filling in the volatile basic nitrogen content, thiobarbituric acid reactant value, pH value, total bacterial count, and microbial risk results as supporting data. Simultaneously, this invention formats and outputs this data structure as a visual interface or PDF document, forming a complete comprehensive assessment report for users to view and save.
[0080] In summary, this invention has developed and deployed a high-precision and robust machine vision intelligent interpretation system. By utilizing the constructed Visual Encoder Transformer (VET) architecture, this invention achieves non-contact, quantitative, and automated interpretation of color changes in intelligent packaging films and directly outputs food freshness results.
[0081] like Figure 2 The figure shows the experimental results of the present invention in a specific embodiment. Figure 2 Figure A shows a comparison of the accuracy of different models in classifying food freshness in this invention. It visually compares the prediction accuracy of the VET model used in this invention with other existing machine learning and deep learning models on the salmon freshness classification task. The models compared from left to right on the horizontal axis are SVM, VGG16, ResNet50, VGG19, and WISER. The VET model of this invention is... Figure 2 As can be seen from A, the VET model of this invention has a significant advantage in accuracy and excellent classification performance.
[0082] Figure 2Figure B shows the confusion matrix of the VET model for classifying salmon freshness in a specific embodiment. It illustrates the confusion matrix of the VET model on the salmon freshness (Fresh, Less Fresh, Spoiled) classification task. The percentage values in the matrix clearly reflect the model's correct classification rate and misclassification rate for each freshness category (e.g., 96% correct recognition rate for the "Fresh" category, 4% misclassification as "Spoiled," etc.). Figure 2 As can be seen from B, the model of this invention has strong classification performance, as well as high robustness and accuracy.
[0083] like Figure 2 As shown, the present invention also provides a food freshness detection system based on machine vision and functionalized metal-organic framework composite materials, comprising: Acquisition module 100: used to acquire target food images covered with pH response units, perform preprocessing operations on the target food images, and generate standardized image data; Transformation module 200: used to divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence; Extraction module 300: is used to perform feature extraction on the feature embedding vector sequence based on the visual encoder transformer architecture, calculate the correlation weight between image patches in the feature embedding vector sequence using a multi-head self-attention mechanism, and output a global feature representation after processing by a feedforward neural network; Prediction module 400: receives the global feature representation, maps it through a built-in multilayer perceptron to obtain the probability distribution of food freshness category, and outputs the freshness discrimination result according to the probability distribution.
[0084] The present invention also provides a food freshness detection device based on machine vision and functionalized metal-organic framework composite material, comprising: a memory and at least one processor, wherein the memory stores instructions; at least one processor invokes the instructions in the memory to cause the food freshness detection device based on machine vision and functionalized metal-organic framework composite material to perform a food freshness detection method based on machine vision and functionalized metal-organic framework composite material as described above.
[0085] The present invention also provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a food freshness detection method based on machine vision and functionalized metal-organic framework composite materials as described in any of the preceding claims.
[0086] The present invention also provides a computer program product, including a computer program, wherein a processor of a computer device reads the computer program from a computer-readable storage medium, and the processor executes the computer program, causing the computer device to perform any of the above-described methods for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials.
[0087] Specifically, an apparatus equipped with a storage medium may be provided, on which software program code implementing the functions of any of the embodiments described above is stored, and the computer (or CPU or MPU) of the apparatus may read and execute the program code stored in the storage medium.
[0088] In this case, the program code read from the storage medium can itself implement the function of any of the above embodiments, and therefore the program code and the storage medium storing the program code constitute part of the present invention.
[0089] Storage media embodiments for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer via a communication network.
[0090] Furthermore, it should be clear that not only can the program code read by the computer be executed, but also the operating devices on the computer can be instructed based on the program code to perform some or all of the actual operations, thereby realizing the function of any of the above embodiments.
[0091] Furthermore, it is understood that the program code read from the storage medium is written to the memory set in the expansion board inserted into the computer or to the memory set in the expansion module connected to the computer. Then, based on the instructions of the program code, the CPU or other components installed on the expansion board or expansion module execute some and all of the actual operations, thereby realizing the function of any of the above embodiments.
[0092] like Figure 4 As shown, this is a food freshness detection platform based on machine vision and functional metal-organic framework composite materials, which integrates a method, system, equipment, storage medium, and program product for food freshness detection.
[0093] Figure 4In this system, the industrial camera and image preprocessing logic together correspond to the acquisition module. The industrial camera and supplementary lighting are responsible for acquiring images of the target food, while the image preprocessing logic performs preprocessing operations, together realizing all the functions of the acquisition module. The VET deep learning acceleration engine corresponds to the transformation and extraction modules. This engine internally performs the functions of transformation modules such as block division, linear projection, and position encoding, as well as the functions of extraction modules such as feature extraction based on the visual encoder transformer. The multi-task prediction logic corresponds to the prediction module, which receives the global feature representation, outputs the freshness judgment result through the multilayer perceptron, and simultaneously performs food quality index prediction. The core main control unit serves as the control center of the entire platform, scheduling and coordinating the execution of the entire detection process. The memory module provides data support for algorithm operation, the human-machine interaction and display module realizes the visualization of detection results and user interaction, and the communication interface provides data communication capabilities between the device and external systems.
[0094] Figure 4 The workflow of the food freshness detection platform is as follows: The core control unit first outputs a control signal to drive the supplementary lighting source to provide stable and uniform illumination for the target food. Simultaneously, an industrial camera acquires images of the target food covered with pH response units and transmits the image data stream to the core control unit in real time. Upon entering the core control unit, the image data stream is first fed into the image preprocessing logic, where preprocessing operations such as noise reduction filtering, white balance correction, and brightness normalization are performed to generate standardized image data. Subsequently, the standardized image data is fed into the VET deep learning acceleration engine, which performs operations such as block segmentation, linear projection transformation, and superposition position encoding. Then, feature extraction is performed through a visual encoder transformer architecture, and the correlation weights between image blocks are calculated using a multi-head self-attention mechanism. After processing by a feedforward neural network, a global feature representation is output. The global feature representation is then fed into a multi-task prediction logic. On one hand, it obtains the probability distribution of food freshness categories through a built-in multilayer perceptron mapping, thereby outputting the freshness judgment result. On the other hand, it also predicts food quality indicators, including estimating volatile basic nitrogen content, thiobarbituric acid reactant values, pH value, and total bacterial count, ultimately generating a comprehensive evaluation report. The test results are synchronously written to a memory module, which stores program instructions, VET model parameters, and historical test data. Simultaneously, the results are sent to a human-computer interaction and display module for real-time visualization. Furthermore, the communication interface supports data interaction between the device and external systems, allowing test results to be uploaded to the cloud or other host computer systems.
[0095] This invention aims to provide a platform comprising a machine vision-based method, system, device, storage medium, and program product for detecting the freshness of food using functional metal-organic framework (MOF) composite materials. Specifically, it involves acquiring an image of the target food covered with pH-responsive units based on a MOF core-shell structure and performing preprocessing to generate standardized image data. The standardized image data is then divided into multiple two-dimensional image blocks, subjected to linear projection transformation, and superimposed with positional encoding information to form a feature embedding vector sequence. Feature extraction is performed on the feature embedding vector sequence based on a visual encoder-transformer (VET) architecture. A multi-head self-attention mechanism is used to capture long-distance dependencies between image blocks, and the resulting global feature representation is processed by a feedforward neural network. This global feature representation is then input into a classification prediction module, and mapped through a multilayer perceptron to obtain the probability distribution of food freshness categories and predicted values of physicochemical indicators. This invention achieves high-precision automated detection of food freshness by integrating the pH-responsive unit of the CD-MOF composite core-shell structure with the VET architecture.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials, characterized in that, include: S1: Acquire a target food image covered with pH response units, perform preprocessing operations on the target food image, and generate standardized image data; S2: Divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence; S3: Based on the visual encoder transformer architecture, feature extraction is performed on the feature embedding vector sequence. The association weights between image patches in the feature embedding vector sequence are calculated using a multi-head self-attention mechanism. After processing by a feedforward neural network, a global feature representation is output. S4: Input the global feature representation into the classification prediction module, and obtain the probability distribution of food freshness category through multilayer perceptron mapping. Output the freshness discrimination result according to the probability distribution.
2. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, The pH response unit in step S1 has a core-shell structure, with the core being a cyclodextrin-based metal-organic framework loaded with a natural pH indicator, and the shell being an ovalbumin-sodium alginate nanocomposite; wherein the natural pH indicator is selected from at least one of anthocyanins, curcumin, betalains, alizarin, and shikonin. When changes in the freshness of the target food produce volatile basic nitrogen, the natural pH indicator loaded in the pH response unit undergoes a reversible or irreversible color change. The complex shell formed by the ovalbumin-sodium alginate nanocomposite has a pH-responsive gating function; In acidic or neutral environments, the carboxyl groups of sodium alginate in the composite shell are in a protonated state, and the composite shell shrinks to form a dense barrier, preventing the external environment from contacting the porous carrier loaded with the natural pH indicator. In alkaline environments, the carboxyl groups of sodium alginate in the composite shell deprotonate, generating electrostatic repulsion, and the composite shell expands to increase porosity, allowing volatile alkaline substances to enter the porous carrier loaded with the natural pH indicator and triggering the natural pH indicator to change color.
3. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, The preprocessing operation performed on the target food image in step S1 specifically includes: The target food image is subjected to denoising filtering to eliminate noise interference in the target food image; A white balance algorithm is used to correct the color temperature parameters of the target food image to compensate for the influence of light source color shift. The brightness of the target food image is normalized and adjusted according to a preset dynamic range.
4. The food freshness detection method based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, Step S2 further includes: S21: Divide the standardized image data into multiple two-dimensional image blocks according to the preset block size parameters; S22: Perform a flattening transformation on multiple two-dimensional image blocks to convert them into multiple one-dimensional vector representations; S23: Using a linear projection layer, multiple one-dimensional vector representations are mapped to a unified-dimensional embedding space to generate multiple image patch embedding vectors; S24: Based on the spatial coordinates of multiple two-dimensional image blocks in the standardized image data, add positional encoding to the corresponding image block embedding vector to form a feature embedding vector sequence.
5. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, Step S3 further includes: S31: Feed the feature embedding vector sequence into the multi-head self-attention layer of the visual encoder transformer architecture; S32: In the multi-head self-attention layer, the query matrix, key matrix, and value matrix are calculated based on the feature embedding vector sequence; S33: Quantify the dependency strength between different image patch features in the feature embedding vector sequence using the attention score calculation mechanism, and generate attention-enhanced feature representations by weighted summation; S34: Perform residual connection and layer normalization processing on the attention-enhanced feature representation to obtain a normalized feature representation; S35: The normalized feature representation is fed into a feedforward neural network to perform a nonlinear transformation, and after residual connection and layer normalization, a global feature representation is output.
6. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 5, characterized in that, The training process of the visual encoder transformer architecture in step S3 includes: S311: Construct a labeled dataset containing multiple sets of labeled samples. Each set of labeled samples includes a food image covered with the pH response unit, the corresponding freshness category label, the volatile basic nitrogen content measured in the laboratory, the thiobarbituric acid reactant value, the pH value, and the total number of colonies. S312: Divide the labeled dataset into a training set and a test set according to a preset ratio; S313: The visual encoder transformer architecture is trained end-to-end using the training set, and the model parameters of the visual encoder transformer architecture are continuously optimized through the backpropagation algorithm so that the weighted sum of the classification loss function and the regression loss function converges to the minimum value. S314: Use the test set to evaluate the prediction task performance of the trained visual encoder transformer architecture, and complete the model training when both the classification accuracy and regression prediction error meet the preset thresholds.
7. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, Step S4 further includes: S41: Extract the category label feature vector from the global feature representation; S42: Input the category label feature vector into a multilayer perceptron, and perform a nonlinear mapping transformation on the category label feature vector through multiple fully connected layers; S43: Apply the softmax activation function to the output layer of the multilayer perceptron to calculate the predicted probabilities of multiple freshness categories and form a probability distribution; S44: Select the category corresponding to the maximum predicted probability in the probability distribution as the freshness discrimination result of the target food. The freshness discrimination result includes fresh, less fresh, and spoiled.
8. The method for detecting food freshness based on machine vision and functionalized metal-organic framework composite materials according to claim 1, characterized in that, Also includes: S5: Based on the global feature representation, predict food quality indicators and obtain a comprehensive evaluation report; Step S5 further includes: S51: Based on the global feature representation, estimate the volatile basic nitrogen content, thiobarbituric acid reactant value and pH value of the target food through regression prediction branch; S52: Based on the global feature representation, predict the total number of colonies in the target food, and output the microbial risk result corresponding to the total number of colonies according to the preset safety threshold. The microbial risk result includes high risk level, medium risk level and low risk level. S53: Integrate the freshness assessment results, the volatile basic nitrogen content, the thiobarbituric acid reactant value, the pH value, and the microbial risk results to generate a comprehensive assessment report on the freshness of the target food.
9. A food freshness detection system based on machine vision and functionalized metal-organic framework composite materials, characterized in that, include: Acquisition module: used to acquire images of target food covered with pH response units, perform preprocessing operations on the target food images, and generate standardized image data; Transformation module: used to divide the standardized image data into multiple two-dimensional image blocks, perform linear projection transformation on the multiple two-dimensional image blocks and superimpose position encoding information to form a feature embedding vector sequence; Extraction module: used to perform feature extraction on the feature embedding vector sequence based on the visual encoder transformer architecture, calculate the correlation weight between image patches in the feature embedding vector sequence using a multi-head self-attention mechanism, and output the global feature representation after processing by a feedforward neural network; Prediction module: It is used to receive the global feature representation, map it through the built-in multilayer perceptron to obtain the probability distribution of food freshness category, and output the freshness discrimination result according to the probability distribution.
10. A food freshness detection device based on machine vision and functionalized metal-organic framework composite materials, characterized in that, include: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a food freshness detection device based on machine vision and functionalized metal-organic framework composite material to perform a food freshness detection method based on machine vision and functionalized metal-organic framework composite material as described in any one of claims 1 to 8.