A Method for Detecting Impurities in Peanut Oil Based on Image Recognition Analysis
By setting a detection window, calculating the Reynolds number and exposure time in peanut oil testing, constructing the impurity movement trajectory, and using K-means clustering, the problems of low efficiency and poor accuracy in peanut oil impurity detection in existing technologies are solved, achieving efficient and accurate online quality control.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OCEAN UNIVERSITY
- Filing Date
- 2025-09-29
- Publication Date
- 2026-04-24
AI Technical Summary
In the process of peanut oil refining and bottling, existing technologies suffer from low efficiency and risk of missed detection due to manual sampling and inspection. Static image detection is difficult to distinguish impurities with different motion states, resulting in high false alarm and false alarm rates, which cannot meet the requirements of high-precision and high-efficiency online quality control.
By setting a detection window, the real-time flow rate and viscosity of peanut oil are collected, the Reynolds number and exposure time interval are calculated, the movement trajectory of impurities is constructed, and the K-means clustering method is used to distinguish the impurity type and provide real-time alarm.
It achieves efficient and accurate detection of impurities in peanut oil, enabling real-time detection of impurity exceeding standards, ensuring product quality and safety, and reducing false alarm and false alarm rates.
Smart Images

Figure CN121027131B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of peanut oil impurity detection methods, specifically a peanut oil impurity detection method based on image recognition analysis. Background Technology
[0002] In the refining and bottling of edible oils such as peanut oil, pipeline transportation is a critical link. Tiny solid impurities mixed in with the oil, such as raw material residues and carbonized particles generated during processing, can seriously affect the purity, quality, and safety of the product. Existing technologies often employ manual sampling inspection or online detection systems based on static image analysis. However, manual sampling is inefficient, carries the risk of missed detections, and cannot achieve real-time monitoring; while traditional static image detection methods struggle to effectively distinguish between impurities moving with the flow in the oil and image noise caused by factors such as light and oil refraction. They lack effective means to identify impurities with varying motion states, such as light particles floating, heavy particles settling, or suspended in the flow, resulting in high false alarm and false negative rates, failing to meet the urgent needs of the modern food industry for high-precision, high-efficiency online quality control.
[0003] In the prior art, CN120275351A discloses a method that significantly improves the comprehensiveness of impurity detection through a multimodal sensing collaborative mechanism. This method employs donor-acceptor quantum dot pairs to achieve dual-channel FRET labeling, uses a dynamic threshold based on fluorescence intensity ratio, combines a super-oscillating lens group with near-field scanning technology to overcome diffraction poles, and uses a graph neural network classifier based on an attention mechanism to construct a multi-dimensional decision boundary by dynamically weighting and fusing FRET, morphology, and motion features. However, this method is costly, requiring significant time and manpower for peanut oil inspection. It does not consider the impact of camera exposure time on continuous frame images of peanut oil, nor does it comprehensively consider the motion characteristics of peanut oil impurities, such as the movement speed and angle of change of impurities in each frame image. Consequently, it fails to acquire the motion trajectory of each impurity in the peanut oil, making it impossible to distinguish the type and quantity of each impurity and trigger an alarm. Therefore, an efficient and reliable method for detecting peanut oil impurities is urgently needed.
[0004] The information disclosed in the background section is only intended to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] The purpose of this invention is to provide a method for detecting impurities in peanut oil based on image recognition analysis, so as to solve the problems mentioned in the background art.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A method for detecting impurities in peanut oil based on image recognition analysis, comprising the following steps:
[0008] S1: Set the detection window of the peanut oil flow pipe, collect the real-time flow rate of peanut oil, calculate the field depth based on the refractive index of peanut oil, collect the density and viscosity of peanut oil, calculate the Reynolds number of peanut oil in the current pipe, and calculate the camera exposure time interval based on the real-time flow rate, field depth and Reynolds number of peanut oil. Based on the camera exposure time interval, collect continuous frame images of peanut oil to form an image set.
[0009] S2: For each frame of image, convert it into a grayscale image and perform edge detection. Based on the edge detection results, identify impurities in the image, extract the edge features and grayscale value features of each impurity, pair each impurity in all frames of images based on the edge features and grayscale value features of the impurities in each frame of image, determine the position of each impurity in each image, and construct the motion trajectory of each impurity based on the position of each impurity in each frame of image.
[0010] S3: Based on the motion trajectory of each impurity, except for the last frame of the image set, starting from the first frame, compare the position in the previous frame with the position of the corresponding impurity in the next frame, calculate the motion feature data of the same impurity between adjacent frames, and obtain the motion feature matrix of each impurity.
[0011] S4: Based on the motion feature matrix of each impurity, calculate the mean and variance of the angle and velocity of each impurity, construct the motion feature vector of each impurity, standardize the motion feature vector, and use the Kmeans clustering method to cluster the standardized motion feature vector. Count the number of each type of impurity in the image and compare it with the preset threshold. If the number of any type of impurity exceeds the preset threshold, output an alarm message.
[0012] Furthermore, since the peanut oil flow pipe is a glass pipe, the steps for calculating the camera's exposure time interval are as follows:
[0013] The real-time flow rate of peanut oil is collected, and the depth of view is calculated based on the refractive index of peanut oil using the following formula:
[0014] ;
[0015] in, This indicates the refractive index of peanut oil; The refractive index of the glass in the peanut oil flow pipe; Indicates the camera's nominal field of view depth; Indicates the depth of the field of view;
[0016] Collect the density and viscosity of peanut oil, and calculate the Reynolds number of the peanut oil in the current pipeline:
[0017] ;
[0018] in, This indicates the Reynolds number of the peanut oil in the pipeline; This indicates the density of peanut oil; This indicates the speed at which peanut oil flows at a constant rate. This indicates the inner diameter of the pipe through which peanut oil flows. This indicates the viscosity of peanut oil;
[0019] Based on the real-time flow rate, depth of field, and Reynolds number of peanut oil, the camera exposure time interval is calculated using the following formula:
[0020] ;
[0021] in, This indicates the camera's exposure time interval.
[0022] Furthermore, the method for extracting the edge features and grayscale features of each impurity is as follows:
[0023] For each frame of the image, it is converted into a grayscale image, and the multi-scale Sobel operator is used to perform edge detection on the grayscale image to filter out all edge pixels.
[0024] All edge pixels are grouped according to their spatial location, and each connected region composed of adjacent edge pixels is identified. Each connected region is regarded as an impurity in the image of that frame.
[0025] For each impurity, the number of pixels in its connected region is calculated as the edge feature, the average gray value of all pixels in the region is calculated as the gray value feature, and the position of the center pixel of each impurity is taken as the position of the impurity in the image.
[0026] Furthermore, pairing each impurity across all frames based on its edge and grayscale features specifically includes the following steps:
[0027] Based on the motion trajectory of each impurity, starting from the first frame of the image set, the edge features and grayscale features of the impurities in the previous frame are compared with the edge features and grayscale features of each impurity in the subsequent frame, and the matching degree is calculated accordingly. The formula is as follows:
[0028] ;
[0029] in, and They represent the first Impurities in frame images With the Impurities in frame image The degree of matching and the degree of difference, and They represent the first Frame impurities The number of pixels and the average grayscale value, and They represent the first Frame impurities The number of pixels and the average grayscale value, The weight coefficients representing edge features. This indicates a matching sensitive adjustment factor, and , ;
[0030] if Then it is considered that the first Impurities in frame images With the Impurities in frame image If two impurities are identified as the same impurity, meaning they are projections of the same impurity in different frames, then one pairing is completed. Indicates the matching threshold;
[0031] By continuously performing feature matching and pairing on all impurity targets between adjacent frames, the correspondence of the same impurity in different frames is established, the position of the same impurity in different frame images is obtained, and the motion trajectory of the impurity is constructed according to the acquisition order of the frame images.
[0032] Furthermore, the motion feature data includes motion angle data and motion velocity data. The method used to calculate the motion feature data of the same impurity between adjacent frames and obtain the motion feature matrix of each impurity is as follows:
[0033] Obtain the position data of the same impurity in the previous frame image. and position data in the next frame image The motion angle and velocity data of the impurity are calculated using the following formula:
[0034] ;
[0035] in, and They represent the first Impurities in frame images x and y coordinates and They represent the first Impurities in frame images x and y coordinates and These represent impurities. From the Frame image to the ground Motion angle data and motion speed data of the frame image;
[0036] impurities The motion feature matrix is:
[0037] ;
[0038] in, Indicates impurities The motion feature matrix; This indicates the total number of image frames.
[0039] Furthermore, based on the motion feature matrix of each impurity, its angle sequence and velocity sequence are extracted respectively. The mean and variance of the angle sequence are calculated to reflect the overall motion direction trend and the degree of directional fluctuation, respectively. The mean and variance of the velocity sequence are calculated to reflect the average motion speed and the magnitude of velocity change, respectively. The four feature values of the mean and variance of the angle sequence and the mean and variance of the velocity sequence are combined into a four-dimensional motion feature vector. The motion feature vector is standardized by subtracting the global mean of the motion feature vector of all impurities in that dimension and dividing by the global standard deviation of that dimension for the feature value of each dimension.
[0040] Furthermore, the standardized motion feature vector is represented as:
[0041] ;
[0042] in, and These represent impurities. The mean and variance-standardized eigenvalues of the angle sequence; and These represent impurities. The mean and variance-standardized eigenvalues of the velocity sequence; Indicates impurities Standardized motion feature vectors;
[0043] The standardized feature vectors are clustered using the K-means clustering method. The specific steps are as follows:
[0044] Select from all impurity-normalized motion feature vectors Each motion feature vector serves as the initial cluster center for each cluster;
[0045] For each impurity-normalized motion feature vector, calculate its distance to each cluster center and assign it to the nearest cluster.
[0046] For each cluster, calculate the mean of the four eigenvalues of all the standardized motion feature vectors assigned to that cluster, and use the four mean values as the new cluster centers for that cluster.
[0047] Check if the cluster center has changed. If the cluster center no longer changes, the clustering ends. Otherwise, recalculate the distance to each cluster center after the motion feature vector of each impurity is standardized, and then iterate again until the clustering ends.
[0048] After clustering is completed, the clustering result of each cluster is treated as an impurity type.
[0049] Furthermore, after clustering is completed, all impurities are divided into multiple different types based on the clustering results. For each type of impurity, the total number of impurities belonging to that type is counted. After the count is completed, the number of each impurity type is compared with the preset threshold. If the threshold is exceeded, an alarm is issued.
[0050] Compared with the prior art, the beneficial effects of the present invention are:
[0051] By constructing an impurity detection method that integrates fluid dynamics parameters and dynamic visual analysis, the shortcomings of existing technologies are effectively overcome. First, by introducing Reynolds number calculation and adaptively adjusting the camera exposure strategy, clear and continuous images of impurity motion sequences can be captured under different flow rates and viscosities, laying a data foundation for subsequent accurate analysis. Second, by tracking the trajectory of each impurity and extracting its multidimensional motion features such as velocity and angle changes, cluster analysis is performed. This method significantly improves the automation and accuracy of detection, enabling real-time detection and alarm of impurity exceedances. It provides a reliable basis for timely intervention and quality control in the production process, thereby ensuring the quality and safety of the final product. Attached Figure Description
[0052] Figure 1 This is a schematic diagram of the overall method flow of the present invention.
[0053] Figure 2 This is a schematic diagram illustrating the changes in matching degree and difference degree between adjacent frames of impurities in this invention. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.
[0055] It should be noted that, unless otherwise defined, the technical or scientific terms used in this invention should have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0056] Example:
[0057] Please see Figures 1-2 The present invention provides a technical solution:
[0058] A method for detecting impurities in peanut oil based on image recognition analysis, comprising the following steps:
[0059] S1: Set the detection window of the peanut oil flow pipe, collect the real-time flow rate of peanut oil, calculate the field depth based on the refractive index of peanut oil, collect the density and viscosity of peanut oil, calculate the Reynolds number of peanut oil in the current pipe, and calculate the camera exposure time interval based on the real-time flow rate, field depth and Reynolds number of peanut oil. Based on the camera exposure time interval, collect continuous frame images of peanut oil to form an image set.
[0060] The peanut oil flow pipe is a glass pipe. The steps for calculating the camera's exposure time interval are as follows:
[0061] The real-time flow rate of peanut oil is collected, and the depth of view is calculated based on the refractive index of peanut oil using the following formula:
[0062] ;
[0063] in, This indicates the refractive index of peanut oil; The refractive index of the glass in the peanut oil flow pipe; Indicates the camera's nominal field of view depth; Indicates the depth of the field of view;
[0064] Dependent variable The time-corrected effective field of view reflects the actual depth range within the peanut oil medium where the camera can achieve a clear image after light passes through the glass pipe wall and the peanut oil medium. Alternatively, the camera's nominal field of view can be used directly. Significant errors can arise due to differences in the refractive index of the medium. This formula employs physical optics corrections to ensure that subsequent calculations are based on an accurate imaging spatial scale. With independent variable Positively correlated with The correlation is negative because when light enters peanut oil from glass, the angle of refraction is greater than the angle of incidence, causing the actual focal point to shift backward, thus increasing the effective field of view depth. , The smaller the value, the more pronounced this effect. The more it increases.
[0065] Collect the density and viscosity of peanut oil, and calculate the Reynolds number of the peanut oil in the current pipeline:
[0066] ;
[0067] in, This indicates the Reynolds number of the peanut oil in the pipeline; This indicates the density of peanut oil; This indicates the speed at which peanut oil flows at a constant rate. This indicates the inner diameter of the pipe through which peanut oil flows. This indicates the viscosity of peanut oil;
[0068] Dependent variable It is a dimensionless number used to quantify the flow state of peanut oil in a pipeline; it measures the inertial force of the fluid. With viscous force The comparison provides key flow parameters for the next step of exposure time calculation. Different flow states can significantly affect the trajectory of impurities in the fluid and the difficulty of image acquisition. The size of peanut oil is determined by the physical properties of the fluid. Peanut oil viscosity The speed at which peanut oil flows at a constant speed and pipe geometry inner diameter Both factors contribute to the flow. Inertial forces cause flow instability and tend towards turbulence, while viscous forces suppress disturbances and maintain laminar flow. Therefore, It is the core variable characterizing the flow state by integrating these factors, and, and They are directly proportional to each other, and Inversely proportional.
[0069] Based on the real-time flow rate, depth of field, and Reynolds number of peanut oil, the camera exposure time interval is calculated using the following formula:
[0070] ;
[0071] in, This indicates the camera's exposure time interval.
[0072] This determines the time required for an impurity to traverse the entire effective field of view under ideal laminar flow, i.e., smooth flow conditions. The larger the size, the shorter the time required, therefore and Inversely proportional to, with Proportional; This indicates the transition of flow from laminar to turbulent. As the volume increases, random vortices are generated in the fluid, causing impurities to vibrate or tumble non-directionally at high frequencies. This motion can cause image blurring. Therefore, at high... In such cases, the exposure time needs to be shortened to "freeze" this random motion. The correction term in the denominator... The term describes the turbulence intensity as a function of... The nonlinear relationship increases with the increase, and the value of the entire correction term increases with... By increasing the size and decreasing it, a correction for shortening the base exposure time is achieved. The larger the imaging area, the longer the exposure time should be. and It is directly proportional; the faster the flow rate, the shorter the exposure time should be, that is... and Inversely proportional; the more turbulent the flow, the shorter the exposure time should be to reduce motion blur, i.e. and Inversely proportional.
[0073] S2: For each frame of image, convert it into a grayscale image and perform edge detection. Based on the edge detection results, identify impurities in the image, extract the edge features and grayscale value features of each impurity, pair each impurity in all frames of images based on the edge features and grayscale value features of the impurities in each frame of image, determine the position of each impurity in each image, and construct the motion trajectory of each impurity based on the position of each impurity in each frame of image.
[0074] The method for extracting the edge features and grayscale features of each impurity is as follows:
[0075] For each frame of the image, it is converted into a grayscale image, and the multi-scale Sobel operator is used to perform edge detection on the grayscale image to filter out all edge pixels.
[0076] All edge pixels are grouped according to their spatial location, and each connected region composed of adjacent edge pixels is identified. Each connected region is regarded as an impurity in the image of that frame.
[0077] For each impurity, the number of pixels in its connected region is calculated as the edge feature, the average gray value of all pixels in the region is calculated as the gray value feature, and the position of the center pixel of each impurity is taken as the position of the impurity in the image.
[0078] The above steps, through multi-scale Sobel operators combined with connected component analysis, can accurately capture the edge contours of impurities of different sizes, effectively adapting to the diversity of impurity morphology. By statistically analyzing the number of pixels in connected components to reflect the impurity area characteristics and the average grayscale value to reflect the differences in the impurity's optical properties, combined with center coordinate localization, multi-dimensional feature extraction of impurity morphology and spatial location is achieved. This method significantly improves the accuracy of impurity identification, reduces the risk of missed detections and false detections caused by differences in impurity size, and provides a stable and reliable feature foundation for subsequent cross-frame impurity pairing and motion trajectory construction, thereby improving the overall robustness of impurity classification and anomaly detection.
[0079] Pairing each impurity across all frames of images based on its edge and grayscale features specifically includes the following steps:
[0080] Based on the motion trajectory of each impurity, starting from the first frame of the image set, the edge features and grayscale features of the impurities in the previous frame are compared with the edge features and grayscale features of each impurity in the subsequent frame, and the matching degree is calculated accordingly. The formula is as follows:
[0081] ;
[0082] in, and They represent the first Impurities in frame images With the Impurities in frame image The degree of matching and the degree of difference, and They represent the first Frame impurities The number of pixels and the average grayscale value, and They represent the first Frame impurities The number of pixels and the average grayscale value, The weight coefficients representing edge features. This indicates a matching sensitive adjustment factor, and , ;
[0083] In the above formula, Indicates the first Impurities in frame images With the Impurities in frame image The difference degree is a dimensionless relative value. Its technical effect is to normalize and merge the differences between two impurities in area and grayscale into a single, comparable quantitative indicator. Indicates impurities area relative to impurities The relative change in area means that the projected area of the same impurity in consecutive frames should remain relatively stable. The smaller this value, the better the area characteristics match. Indicates impurities Average gray level relative to impurities The relative change in average grayscale. The material and optical properties of the same impurity are usually stable; the smaller this value, the better the grayscale characteristics match. Weighting coefficient. This is used to adjust the relative importance of these two features in the total variance. The larger the value, the more importance is placed on the stability of the edge shape during pairing; The smaller the value, the more importance is placed on the consistency of grayscale. Both edge feature differences and grayscale feature differences are positively correlated; that is, the greater the difference in area or grayscale between two impurities, the higher the calculated overall difference. The larger it is.
[0084] Dependent variable Indicates the first Impurities in frame images With the Impurities in frame image The matching degree, whose value ranges from 0 to 1. It measures the difference degree. Converted into an intuitive similarity probability score, The closer the value is to 1, the higher the probability that the two are the same impurity; The closer it is to 0, the lower the probability. The value is entirely determined by the degree of difference and matching sensitive regulatory factors Decide, It is an amplification factor that controls the matching degree. For difference The degree of sensitivity; With difference It exhibits a negative exponential correlation. The smaller, The larger; exponential function It effectively simulates the characteristic that similarity decays rapidly as differences increase. With sensitive factors It also shows a negative correlation. A higher value means a stricter matching standard.
[0085] This process involves collecting data from known correctly matched impurity samples, ensuring the samples cover different impurity sizes, gray levels, and motion speeds. The distribution of differences between correctly matched pairs in adjacent frames is statistically analyzed. A critical difference value is selected that causes the mean matching score of correctly matched pairs to reach a preset confidence level threshold. This is then calculated using a reverse formula. Determine parameters The value of , where, This indicates the preset confidence level threshold; This represents the critical difference value.
[0086] if Then it is considered that the first Impurities in frame images With the Impurities in frame image If two impurities are identified as the same impurity, meaning they are projections of the same impurity in different frames, then one pairing is completed. Indicates the matching threshold;
[0087] By continuously performing feature matching and pairing on all impurity targets between adjacent frames, the correspondence of the same impurity in different frames is established, the position of the same impurity in different frame images is obtained, and the motion trajectory of the impurity is constructed according to the acquisition order of the frame images.
[0088] The above process transforms discrete impurity detection data into motion trajectories with spatiotemporal continuity. This not only allows for precise tracking of impurity displacement trajectories to quantify their dynamic characteristics such as speed and direction, but also provides a data foundation for statistical analysis of impurity distribution density and migration patterns. Ultimately, this results in a comprehensive monitoring system that integrates single-frame static detection with multi-frame dynamic analysis.
[0089] In the above embodiments, 10 sets of data on matching degree and difference degree are given to reflect the relationship between the matching degree and difference degree of impurities, as shown in Table 1:
[0090] Table 1: Relationship between the matching degree and the difference degree of impurities
[0091]
[0092] As can be seen from Table 1 above, as the difference between impurities in adjacent frames increases, the matching degree of impurities in adjacent frames gradually decreases, which is consistent with the dynamic matching degree of impurities in adjacent frame images changing with the difference.
[0093] S3: Based on the motion trajectory of each impurity, except for the last frame of the image set, starting from the first frame, compare the position in the previous frame with the position of the corresponding impurity in the next frame, calculate the motion feature data of the same impurity between adjacent frames, and obtain the motion feature matrix of each impurity.
[0094] The motion feature data includes motion angle data and motion velocity data. The method for calculating the motion feature data of the same impurity between adjacent frames and obtaining the motion feature matrix of each impurity is as follows:
[0095] Obtain the position data of the same impurity in the previous frame image. and position data in the next frame image The motion angle and velocity data of the impurity are calculated using the following formula:
[0096] ;
[0097] in, and They represent the first Impurities in frame images x and y coordinates and They represent the first Impurities in frame images x and y coordinates and These represent impurities. From the Frame image to the ground Motion angle data and motion speed data of the frame image;
[0098] Dependent variable Indicates impurities From the Frame image to the ground The motion angle data of the frame image transforms the displacement vector of the impurity on the two-dimensional image plane into a precise angle value, thereby quantifying the direction of impurity motion. The value is determined by the difference in coordinates of the impurities between two adjacent frames; specifically, it is the arctangent of the ratio of the vertical component to the horizontal component of the displacement vector. It is directly related to the ratio of vertical displacement to horizontal displacement. When the vertical displacement increases or the horizontal displacement decreases, the angle... The absolute value will increase.
[0099] Indicates impurities From the Frame image to the ground Motion velocity data of a frame image; it is obtained by calculating the amount of impurities per unit time. The linear distance of the internal movement quantifies the speed of impurity movement. The value is determined by the actual displacement of the impurity in two adjacent frames and the time elapsed for that displacement to occur. The factors jointly determine the magnitude of the displacement and show a positive correlation with time. They show a negative correlation; the larger the displacement or the shorter the time interval, the faster the calculated instantaneous velocity.
[0100] impurities The motion feature matrix is:
[0101] ;
[0102] in, Indicates impurities The motion feature matrix; This indicates the total number of image frames.
[0103] Indicates impurities The motion feature matrix systematically organizes the motion angle and velocity data of impurities between all adjacent frames in the entire image sequence into a two-dimensional data structure, i.e., a matrix. Each column represents an adjacent frame pair. The first row is the angle feature of all frame pairs, and the second row is the velocity feature of all frame pairs. This matrix completely depicts the temporal changes of the motion behavior of a single impurity. Each element in the matrix is the result of the angle and velocity formulas described above for a specific frame pair. This matrix is entirely composed of impurities. The sequence of position coordinates in all frame images and the known time intervals The result is determined by the sequence of impurity position coordinates, and changes in the coordinates directly lead to changes in the element values in the matrix.
[0104] S4: Based on the motion feature matrix of each impurity, calculate the mean and variance of the angle and velocity of each impurity, construct the motion feature vector of each impurity, standardize the motion feature vector, and use the Kmeans clustering method to cluster the standardized motion feature vector. Count the number of each type of impurity in the image and compare it with the preset threshold. If the number of any type of impurity exceeds the preset threshold, output an alarm message.
[0105] Based on the motion feature matrix of each impurity, its angle sequence and velocity sequence are extracted respectively. The mean and variance of the angle sequence are calculated to reflect the overall motion direction trend and the degree of directional fluctuation, respectively. The mean and variance of the velocity sequence are calculated to reflect the average motion speed and the magnitude of velocity change, respectively. The four feature values of the mean and variance of the angle sequence and the mean and variance of the velocity sequence are combined into a four-dimensional motion feature vector. The motion feature vector is standardized by subtracting the global mean of the motion feature vector of all impurities in that dimension and dividing by the global standard deviation of that dimension for the feature value of each dimension.
[0106] The standardized motion feature vector is represented as:
[0107] ;
[0108] in, and These represent impurities. The mean and variance-standardized eigenvalues of the angle sequence; and These represent impurities. The mean and variance-standardized eigenvalues of the velocity sequence; Indicates impurities Standardized motion feature vectors;
[0109] The standardized feature vectors are clustered using the K-means clustering method. The specific steps are as follows:
[0110] Select from all impurity-normalized motion feature vectors Each motion feature vector serves as the initial cluster center for each cluster;
[0111] For each impurity-normalized motion feature vector, calculate its distance to each cluster center and assign it to the nearest cluster.
[0112] For each cluster, calculate the mean of the four eigenvalues of all the standardized motion feature vectors assigned to that cluster, and use the four mean values as the new cluster centers for that cluster.
[0113] Check if the cluster center has changed. If the cluster center no longer changes, the clustering ends. Otherwise, recalculate the distance to each cluster center after the motion feature vector of each impurity is standardized, and then iterate again until the clustering ends.
[0114] After clustering is completed, the clustering result of each cluster is treated as an impurity type.
[0115] After clustering is completed, all impurities are divided into multiple different types according to the clustering results. For each type of impurity, the total number of impurities belonging to that type is counted. After the count is completed, the number of each impurity type is compared with the preset threshold. If the threshold is exceeded, an alarm is issued.
[0116] After completing K-means clustering, the system first defines each cluster as a specific impurity type and categorizes all impurities based on their motion feature vectors, generating type labels. Then, it iterates through all impurity samples, counts the number of impurities within each type, forms a type-quantity mapping table, and compares the statistical value (the number of impurities) with a threshold for each type. If the number of impurities in a certain type exceeds its threshold, it is considered abnormal, triggering a multi-level alarm mechanism.
[0117] The above formulas are all dimensionless calculations. The formulas are derived from software simulations based on a large amount of collected data to obtain the most recent real-world results. The preset parameters in the formulas are set by those skilled in the art according to the actual situation.
[0118] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented in software, the above embodiments can be implemented, in whole or in part, as a computer program product. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution.
[0119] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0120] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for detecting impurities in peanut oil based on image recognition analysis, characterized in that the steps include... include: S1: Set the detection window of the peanut oil flow pipe, collect the real-time flow rate of peanut oil, calculate the field depth based on the refractive index of peanut oil, collect the density and viscosity of peanut oil, calculate the Reynolds number of peanut oil in the current pipe, and calculate the camera exposure time interval based on the real-time flow rate, field depth and Reynolds number of peanut oil. Based on the camera exposure time interval, collect continuous frame images of peanut oil to form an image set. S2: For each frame image, convert it into a grayscale image and perform edge detection. Based on the edge detection results, identify the impurities in each frame image, extract the edge features and grayscale value features of each impurity, pair each impurity in all frames image according to the edge features and grayscale value features of the impurities in each frame image, determine the position of each impurity in each frame image, and construct the motion trajectory of each impurity based on the position of each impurity in each frame image. S3: Based on the motion trajectory of each impurity, except for the last frame of the image set, starting from the first frame, compare the position in the previous frame with the position of the corresponding impurity in the next frame, calculate the motion feature data of the same impurity between adjacent frames, and obtain the motion feature matrix of each impurity. S4: Based on the motion feature matrix of each impurity, calculate the mean and variance of the angle sequence and the mean and variance of the velocity sequence of each impurity, construct the motion feature vector of each impurity, standardize the motion feature vector, use the Kmeans clustering method to cluster the standardized motion feature vector, count the number of each impurity type in the image set, and compare it with the preset threshold. If the number of any type of impurity exceeds the preset threshold, an early warning is issued. The peanut oil flow channel is a glass tube. The steps for calculating the camera's exposure time interval are as follows: The real-time flow rate of peanut oil is collected, and the depth of view is calculated based on the refractive index of peanut oil using the following formula: in, This indicates the refractive index of peanut oil; The refractive index of the glass in the peanut oil flow pipe; Indicates the camera's nominal field of view depth; Indicates the depth of the field of view; Collect the density and viscosity of peanut oil, and calculate the Reynolds number of the peanut oil in the current pipeline: in, This represents the Reynolds number of the peanut oil in the pipeline; This indicates the density of peanut oil; This indicates the speed at which peanut oil flows at a constant rate. This indicates the inner diameter of the pipe through which peanut oil flows. Indicates the viscosity of peanut oil; Based on the real-time flow rate, depth of field, and Reynolds number of peanut oil, the camera exposure time interval is calculated using the following formula: in, This indicates the camera's exposure time interval.
2. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 1, characterized in that, The method for extracting the edge features and grayscale features of each impurity is as follows: For each frame of the image, it is converted into a grayscale image, and the multi-scale Sobel operator is used to perform edge detection on the grayscale image to filter out all edge pixels. All edge pixels are grouped according to their spatial location, and each connected region composed of adjacent edge pixels is identified. Each connected region is regarded as an impurity in the image of that frame. For each impurity, the number of pixels in its connected region is calculated as the edge feature, the average gray value of all pixels in the connected region is calculated as the gray value feature, and the position of the center pixel of each impurity is taken as the position of the impurity in each frame of the image.
3. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 2, characterized in that, Pairing each impurity across all frames of images based on its edge and grayscale features specifically includes the following steps: Based on the motion trajectory of each impurity, starting from the first frame of the image set, the edge features and grayscale features of the impurities in the previous frame are compared with the edge features and grayscale features of each impurity in the subsequent frame, and the matching degree is calculated accordingly. The formula is as follows: in, and They represent the first Impurities in frame images With the Impurities in frame image The degree of matching and the degree of difference, and They represent the first Frame impurities The number of pixels and the average grayscale value, and They represent the first Frame impurities The number of pixels and the average grayscale value, The weight coefficients representing edge features. This indicates a matching sensitive adjustment factor, and , ; if Then it is considered that the first Impurities in frame images With the Impurities in frame image If two impurities are identified as the same impurity, meaning they are projections of the same impurity in different frames, then one pairing is completed. Indicates the matching threshold; By continuously performing feature matching and pairing on all impurity targets between adjacent frames, the correspondence of the same impurity in different frames is established, the position of the same impurity in each frame image is obtained, and the motion trajectory of the impurity is constructed according to the acquisition order of consecutive frame images.
4. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 1, characterized in that, The motion feature data includes motion angle data and motion velocity data. The method for calculating the motion feature data of the same impurity between adjacent frames and obtaining the motion feature matrix of each impurity is as follows: Obtain the position data of the same impurity in the previous frame image. and position data in the next frame image The motion angle and velocity data of the impurity are calculated using the following formula: in, and They represent the first Impurities in frame images x and y coordinates and They represent the first Impurities in frame images x and y coordinates and These represent impurities. From the Frame image to the ground Motion angle data and motion speed data of the frame image; impurities The motion feature matrix is: in, Indicates impurities The motion feature matrix; This indicates the total number of image frames.
5. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 1, characterized in that, Based on the motion feature matrix of each impurity, its angle sequence and velocity sequence are extracted respectively. The mean and variance of the angle sequence are calculated to reflect the overall motion direction trend and the degree of directional fluctuation, respectively. The mean and variance of the velocity sequence are calculated to reflect the average motion speed and the magnitude of velocity change, respectively. The four feature values of the mean and variance of the angle sequence and the mean and variance of the velocity sequence are combined into a four-dimensional motion feature vector. The motion feature vector is standardized by subtracting the global mean of the motion feature vector of all impurities in that dimension and dividing by the global standard deviation of that dimension for the feature value of each dimension.
6. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 5, characterized in that, The standardized motion feature vector is represented as: in, and These represent impurities. The mean and variance-standardized eigenvalues of the angle sequence; and These represent impurities. The mean and variance-standardized eigenvalues of the velocity sequence; Indicates impurities Standardized motion feature vectors; The standardized feature vectors are clustered using the K-means clustering method. The specific steps are as follows: Select from all impurity-normalized motion feature vectors Each motion feature vector serves as the initial cluster center for each cluster; For each impurity-normalized motion feature vector, calculate its distance to each initial cluster center and assign it to the nearest cluster; For each cluster, calculate the mean of the four eigenvalues of all the standardized motion feature vectors assigned to that cluster, and use the four mean values as the new cluster centers for that cluster. Check if the cluster centers have changed. If the cluster centers no longer change, the clustering ends; otherwise, iterate again until the clustering ends. After clustering is completed, the clustering result of each cluster is treated as an impurity type.
7. The method for detecting impurities in peanut oil based on image recognition analysis according to claim 1, characterized in that, After clustering is completed, all impurities are divided into multiple different types based on the clustering results. For each type of impurity, the total number of impurities belonging to that type is counted. After the count is completed, the number of each impurity type is compared with a preset threshold. If the threshold is exceeded, an alert is issued.
Citation Information
Patent Citations
Peanut oil impurity detection method based on image recognition analysis
CN120275351A
Edible oil impurity detection method based on image background probability graph
CN105973904A
Porous medium permeability prediction method based on three-dimensional convolutional neural network
CN112991277A