Moon cake sorting method and system based on visual inspection
Through the image fusion model, the multi-angle mooncake images are fused and the mooncake detection model is improved, which solves the problem that the mooncake image detection device is difficult to detect the defects in shooting blind spots, and realizes panoramic detection and efficient detection of mooncakes.
Patent Information
- Application Number
- CN202411710695.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-02-28
AI Technical Summary
Existing mooncake image detection devices are difficult to provide accurate mooncake panoramic detection images, resulting in the inability to detect the defects in the mooncake image of the shooting dead corners.
Through the image fusion model, the mooncake images at multiple angles are fused, and the mooncake images are intelligently calculated and the mooncake detection model is improved to improve the accuracy and efficiency of detection.
Panoramic inspection of mooncakes has been achieved, making up for the defects of shooting blind spots, improving the accuracy and speed of detection, and reducing manual intervention and cost.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a mooncake sorting method and system based on visual detection. Background Art
[0002] Visual inspection technology is widely used in the inspection of various products, including industrial products, food, medicine, cosmetics, etc. It is a non-contact, non-destructive automatic inspection technology that can realize equipment automation, intelligence and precision control. It has the advantages of safety and reliability, wide spectral response range, long-term operation in harsh environments and high production efficiency. The visual inspection system obtains the surface image of the product through appropriate light sources and image sensors (such as CCD cameras), extracts the feature information of the image using the corresponding image processing algorithm, and then locates, identifies, and classifies surface defects and performs operations such as statistics, storage, and query based on the feature information. Visual inspection does not require direct contact with the object being inspected, avoiding physical damage. Through high-precision image processing algorithms, defects can be accurately identified and located. It can work for a long time in harsh environments and is not affected by factors such as light changes. It can realize automated inspection, improve production efficiency, and reduce manual intervention.
[0003] During the mooncake production process, the shape and color of the mooncakes need to be classified. The machine vision sorting system can efficiently and accurately complete the sorting of goods through automated and intelligent control. For example, Microshen machine vision detection technology combined with barcode readers, smart cameras and recognition technology equipped with deep learning can achieve efficient and accurate sorting of goods, greatly improving work efficiency. In addition, machine vision technology can also be applied in loading and transportation management. Through path planning and transportation tracking, automated loading and transportation management can be achieved, thereby improving the efficiency and safety of the entire transportation.
[0004] Mooncake image detection refers to the detection and identification of mooncakes using image recognition technology. Specifically, by collecting mooncake image data, using machine learning or deep learning algorithms to train and annotate these images, a model that can automatically identify mooncakes is finally constructed. This technology can be applied to many aspects such as quality monitoring of mooncake production lines and food safety testing to improve production efficiency and product quality. However, mooncake image detection currently has high requirements for image quality. Due to the limitations of shooting equipment and production scenarios, it is difficult to provide accurate mooncake panoramic detection images for current mooncake image detection devices, and the defects of missing mooncake blind spot images cannot be detected. At present, there is no detection and sorting method specifically for mooncakes. Summary of the invention
[0005] The purpose of the present invention is to provide a mooncake sorting method and system based on visual inspection. The method fuses mooncake images taken at multiple angles and intelligently calculates mooncake images in blind spots, thereby making up for the technical problem that mooncake defects cannot be detected in blind spots. The mooncake detection model is improved so that defective mooncakes can be detected more quickly and accurately, greatly improving the production efficiency of mooncakes.
[0006] A mooncake sorting method based on visual detection, comprising:
[0007] Obtain mooncake images to be sorted;
[0008] Preprocess the mooncake images to be sorted;
[0009] Judge and sort the processed mooncake images.
[0010] Preferably, the preprocessing of the moon cake images to be sorted includes:
[0011] Carry out grayscale processing, image enhancement and adaptive threshold division on the mooncake images to be sorted;
[0012] Perform image fusion on the processed mooncake images at multiple different angles;
[0013] Extract defect features of the fused mooncake image;
[0014] The defect features of the fused mooncake image are fused to obtain a fused defect feature.
[0015] Preferably, the step of judging and sorting the processed mooncake images includes:
[0016] Improve the mooncake sorting model;
[0017] Input the fused features into the improved mooncake sorting model;
[0018] The improved mooncake sorting model outputs the mooncake sorting results.
[0019] Preferably, the grayscale processing, image enhancement and adaptive threshold division of the mooncake images to be sorted include:
[0020] Divide a mooncake image into multiple sub-images;
[0021] The most suitable threshold of the current sub-image is calculated according to the average gray value and gray level of the sub-image.
[0022] Preferably, the image fusion of the processed moon cake images at different angles comprises:
[0023] Input multiple mooncake images from different angles into the image fusion model;
[0024] The image fusion model outputs the fused mooncake image;
[0025] The loss function of the image fusion model is improved by combining the pixel loss, gradient loss, perceptual loss and color loss of the mooncake image as the loss function of the image fusion model;
[0026] The pixel loss is used to calculate the pixel error between the fused mooncake image and the original mooncake image;
[0027] The gradient loss is used to calculate the edge information loss of the fused mooncake image and the original mooncake image;
[0028] The perceptual loss is used to calculate the feature error between the fused mooncake image and the original mooncake image;
[0029] The color loss is used to calculate the color histogram error between the fused mooncake image and the original mooncake image.
[0030] Preferably, fusing the defect features of the fused mooncake image to obtain fused defect features comprises:
[0031] Suppose the standard mooncake image after binary processing and the fused mooncake image, the mooncake defect area features are obtained by difference method;
[0032] Calculate the average mooncake defect area characteristics;
[0033] The average mooncake defect area features are fused iteratively according to the preset rules to obtain the final fusion result.
[0034] Preferably, the improvement of the mooncake sorting model includes:
[0035] Through Taylor decomposition of cross entropy loss function and focal loss function;
[0036] Adjust the first polynomial coefficient of the Taylor expansion polynomial term and calculate the loss function of the mooncake sorting model.
[0037] A mooncake sorting system based on visual inspection, comprising:
[0038] Obtain mooncake images to be sorted;
[0039] Preprocess the mooncake images to be sorted;
[0040] Judge and sort the processed mooncake images.
[0041] An electronic device includes: a processor and a memory, wherein the memory is used to store computer program codes, and the computer program codes include computer instructions. When the processor executes the computer instructions, the electronic device executes a mooncake sorting method based on visual detection.
[0042] A computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor of an electronic device, the processor executes a mooncake sorting method based on visual detection.
[0043] The beneficial effects of the present invention are as follows: 1. The present invention fuses mooncake images from multiple angles through an image fusion model, intelligently compensates for mooncake images in blind spots, overcomes the technical problem that defects in mooncake images in blind spots cannot be detected, and the fused mooncake images can also perform volume judgment, further improving the accuracy of mooncake detection; 2. The present invention fuses various defects that may occur in mooncakes into a feature representation, thereby improving the detection efficiency of the mooncake defect detection model, eliminating the need to detect mooncake images multiple times, and greatly improving the mooncake detection speed; 3. The present invention also improves the mooncake detection model, and greatly improves the accuracy of mooncake detection by optimizing the loss function; 4. The present invention processes the original captured mooncake images, and subjects the mooncake images to grayscale processing, image enhancement, and adaptive threshold division, so that the defect features of the mooncake images are easier to capture, the processing efficiency is higher, and the processing accuracy becomes higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0046] Figure 1 A schematic diagram of the flow of a mooncake sorting method based on visual inspection according to the present invention;
[0047] Figure 2 A schematic diagram of a process for preprocessing moon cake images to be sorted according to the present invention;
[0048] Figure 3 It is a schematic diagram of the process of judging and sorting the processed moon cake images according to the present invention;
[0049] Figure 4 The figure is a schematic diagram of the hardware structure of an electronic device of the present invention. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] It should be noted that all directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0052] In addition, the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0053] Mooncake image detection refers to the detection and identification of mooncakes using image recognition technology. Specifically, by collecting mooncake image data, using machine learning or deep learning algorithms to train and annotate these images, a model that can automatically identify mooncakes is finally constructed. This technology can be applied to many aspects such as quality monitoring of mooncake production lines and food safety testing to improve production efficiency and product quality. However, mooncake image detection currently has high requirements for image quality. Due to the limitations of shooting equipment and production scenarios, it is difficult to provide accurate mooncake panoramic detection images for current mooncake image detection devices, and the defects of missing mooncake blind spot images cannot be detected. At present, there is no detection and sorting method specifically for mooncakes.
[0054] The present invention fuses mooncake images from multiple angles through an image fusion model, intelligently compensates for mooncake images in blind spots, overcomes the technical problem that defects in mooncake images in blind spots cannot be detected, and the fused mooncake images can also perform volume judgment, further improving the accuracy of mooncake detection; the present invention fuses various defects that may occur in mooncakes into a feature representation, thereby improving the detection efficiency of the mooncake defect detection model, eliminating the need to detect mooncake images multiple times, and greatly improving the mooncake detection speed; the present invention also improves the mooncake detection model, and greatly improves the accuracy of mooncake detection by optimizing the loss function; the present invention processes the original captured mooncake images, and subjects the mooncake images to grayscale processing, image enhancement, and adaptive threshold division, so that the defect features of the mooncake images are easier to capture, the processing efficiency is higher, and the processing accuracy becomes higher.
[0055] Example 1
[0056] A mooncake sorting method based on visual inspection, reference Figure 1 ,include:
[0057] S100, obtaining an image of moon cakes to be sorted;
[0058] The mooncakes to be sorted include those in a certain link of the mooncake factory or food factory, where the mooncakes are being sorted, organized or packaged. Mooncakes need to be sorted after they have been baked. For example, they have various flavors and fillings, such as classic lotus seed paste, five-nut paste, red bean paste, egg yolk, ham, etc., as well as emerging flavors such as fruit mooncakes, fermented rice mooncakes, and lava mooncakes. Due to the different flavors and fillings, the mooncake wrapping paper is different. The same flavor of mooncakes uses the same wrapping paper. In the process of mooncake production, the baked mooncakes may also have defects, which are defective products. At this time, the defective products need to be picked out, which is also an important link in mooncake sorting.
[0059] S200, pre-processing the moon cake images to be sorted;
[0060] Preprocessing mooncake images can improve image quality: by removing noise, enhancing contrast and other means, the image can be made clearer and easier to process later.
[0061] Enhance useful information: Highlight useful information in the image to make features more obvious and easier to identify and process.
[0062] Simplify subsequent processing: Preprocessing can simplify the complexity of subsequent processing such as image segmentation, feature extraction and recognition, thereby improving processing efficiency.
[0063] S300, judging and sorting the processed mooncake images.
[0064] The present invention adopts a mooncake sorting model to intelligently sort mooncakes, which can improve production efficiency: the image sorting system can automatically process a large amount of image data, and can complete the identification, classification and sorting of materials in a short time, thereby significantly improving production efficiency. Reduce errors: the intelligent visual inspection system has high precision and accuracy, which can reduce the sorting error rate and ensure the accuracy of material sorting. Reduce costs: the automated sorting system reduces manual intervention and reduces labor costs, while reducing errors and delays caused by human factors, thereby reducing overall costs. Strong adaptability: the intelligent visual inspection system can adapt to the sorting needs of materials of different types and shapes. Through algorithm optimization and model training, the system can continuously adapt to new materials and sorting scenarios. Real-time monitoring and feedback: the system can monitor the sorting process in real time, promptly detect and handle abnormal situations, ensure the stability and reliability of the sorting process, and improve overall operational efficiency.
[0065] Preferably, reference Figure 2 , S200, pre-processing the moon cake image to be sorted includes:
[0066] S210, performing grayscale processing, image enhancement and adaptive threshold division on the mooncake images to be sorted;
[0067] In order to eliminate image defects and enhance feature saliency, the mooncake image was preprocessed to ensure the reliability of mooncake image feature matching. The preprocessing includes grayscale processing, image enhancement and image matching to enhance image contrast and improve the distinction of mooncake image texture.
[0068] In life, images are defined in two different forms according to reality and virtuality. One is the picture seen on TV, camera and various displays, which is called image. This is a broad definition based on reality. The other is digital image and analog image existing in virtuality. Digital image is to divide the color into different values and then express the image in digital form. In all visual systems, the images collected by the camera are color (RGB) images, so that the image is displayed in numerical form. The grayscale value range of RGB image is 0 to 255, which is the value of R matrix, G matrix and B matrix to represent the three colors of Red, Green and Blue in different proportions. To get a single grayscale image, the values of the three matrices must be equal. It can be seen from this that the grayscale image contains only one channel compared to the RGB image, and the natural matrix is also determined by one. At the same time, the feature points in the image are not lost, which significantly improves the operation efficiency. At present, the commonly used grayscale processing methods of images include maximum value method, average value method and weighted average value method.
[0069] In the detection system, the mooncake image needs to be collected through the light source and the camera. The collection process is affected by the light source and the production environment. The image often contains noise, which mainly includes Gaussian noise and salt and pepper noise. If Gaussian noise and salt and pepper noise are not processed for noise reduction, they will interfere with the subsequent defect detection process, thereby reducing the accuracy of defect detection. Therefore, in order to improve the quality of the mooncake image, the interference items in the image should be eliminated to prevent low detection efficiency, so the use of filtering is the key to reducing noise.
[0070] S220, performing image fusion on the processed moon cake images at different angles;
[0071] The core role of image fusion is to improve the quality and clarity of images, enhance the availability of information, and assist in diagnosis and decision-making. Image fusion generates a new information image by spatially registering multi-source data to obtain a consistent description of the research object, while integrating the advantages of various examinations to achieve the purpose of auxiliary diagnosis. In addition, image fusion can significantly improve the spatial resolution of multispectral images and retain their multispectral characteristics, thereby enhancing the reliability of interpretation, reducing ambiguity, and improving classification accuracy.
[0072] S230, extracting defect features of the fused mooncake image;
[0073] S240, fusing the defect features of the fused mooncake image to obtain a fused defect feature.
[0074] The main functions of feature fusion include the following aspects: Improve classification accuracy: By combining different features together, the classification accuracy of the model can be improved. For example, in computer vision, the color features and texture features of the image are fused together to obtain better classification results. Improve the robustness of the model: Using multiple features can make the model more robust because different features can capture different information. When some features fail, other features can make up for their shortcomings, thereby improving the robustness of the model. Reduce overfitting: By using multiple features, the risk of overfitting of the model can be reduced because different features can provide more information, making the model more generalized. Improve model performance: Feature fusion can help machine learning models better understand the data, thereby improving the performance and generalization ability of the model. For example, in object detection, multi-scale feature fusion can combine image features of different resolutions to improve the performance of the model. It can also improve the accuracy of the system.
[0075] Preferably, reference Figure 3 S300, judging and sorting the processed moon cake images includes:
[0076] S310, improve the mooncake sorting model;
[0077] S320, inputting the fused features into the improved mooncake sorting model;
[0078] S330, the improved mooncake sorting model outputs the mooncake sorting results.
[0079] The main function of the mooncake sorting model is to improve the efficiency of mooncake packaging and sorting and reduce labor costs. The mooncake sorting model can improve sorting efficiency and accuracy: the mooncake sorting model can quickly and accurately sort according to the characteristics of mooncakes (such as shape, size, weight, etc.) through learning and training. This method is more efficient than traditional manual sorting and can greatly reduce labor costs and time. Reduce human errors: the manual sorting process is easily affected by factors such as fatigue and lack of concentration, resulting in sorting errors. The mooncake sorting model can reduce human errors and improve sorting accuracy through algorithms and training data. Strong adaptability: the mooncake sorting model can adapt to new sorting requirements and standards through continuous learning and optimization, and has good flexibility and adaptability. Automation and intelligence: through the mooncake sorting model, the automation and intelligence of mooncake sorting can be realized, reducing dependence on manual labor and improving production efficiency. Data analysis and optimization: the mooncake sorting model can collect and analyze data in the mooncake sorting process, helping enterprises optimize the sorting process and improve overall operational efficiency. In an embodiment of the present invention, by improving the ordinary neural network model, a mooncake sorting model that is most suitable for mooncake sorting is obtained. It can quickly identify and judge mooncake images and quickly screen out defective mooncakes. It is more efficient than traditional manual sorting and can greatly reduce labor costs and time.
[0080] Preferably, S210, grayscale processing, image enhancement and adaptive threshold division of the mooncake image to be sorted includes:
[0081] Assume that the total size of a mooncake image is a×b, and the size of the blocks is c×d, then the total number of blocks S of the mooncake image is expressed as:
[0082]
[0083] Each image block is represented as R x , x=1,2,3,…S;
[0084] Assume R x The most suitable threshold is T x It is expressed as:
[0085]
[0086] Among them, f1 is the proportion of the first part of the image divided into two parts by any gray level, f2 is the proportion of the second part of the image divided into two parts by any gray level, G xis the average gray value of the block image, and g is the average gray value obtained by adding the average gray value of the block image to the gray level. When the denominator reaches the maximum extreme value, the gray level of each block image at this moment is the most suitable threshold.
[0087] The embodiment of the present invention proposes an adaptive threshold algorithm based on the grayscale of each block. By adopting the averaging processing method of each block, it can ensure that the algorithm is more flexible to adapt to various lighting environments and image contrast changes, thereby improving the reliability and stability of feature point detection. And the adaptive threshold is determined by using the maximum variance, which helps to flexibly adjust the sensitivity of feature point detection according to the grayscale characteristics of the image. For image areas with uneven brightness or low contrast, by lowering the threshold, feature points can be captured more effectively. In the face of high contrast and uniform lighting areas, moderately increasing the threshold helps to reduce noise interference and reduce the false detection rate. The grayscale averaging method and adaptive threshold selection strategy of the present invention can reduce the influence of external factors such as lighting changes on feature descriptors, thereby improving the accuracy of feature matching. The optimized algorithm performs better when dealing with a diverse set of mooncake images. Whether it is an image of the same scene under different lighting conditions, or an image of different scenes but with similar mooncake texture structures, stable feature points can be accurately extracted and described, thereby improving the adaptability and accuracy of the algorithm.
[0088] Preferably, S220, performing image fusion on the processed mooncake images at different angles includes:
[0089] Input multiple mooncake images from different angles into the image fusion model;
[0090] The image fusion model outputs the fused mooncake image;
[0091] The loss function of the image fusion model is improved by converting the pixel loss L of the mooncake image into a , gradient loss L b , Perceptual loss L c and color loss L d Combined as the loss function of the image fusion model, it is expressed as:
[0092] L r =L a +αL b +βL c +γL d
[0093] Among them, α, β, and γ are weights used to balance the above four losses;
[0094] Pixel loss is used to calculate the pixel error between the fused mooncake image and the original mooncake image, expressed as:
[0095]
[0096] Wherein, N is the number of images to be fused, O is the fused mooncake image, and I is the mooncake image to be fused;
[0097] The gradient loss is used to calculate the edge information loss of the fused mooncake image and the original mooncake image, expressed as:
[0098] L b =MSE(Gradient(O),Gradient(I))
[0099] Among them, the Gradient(x) function represents the gradient map obtained by Laplace operation;
[0100] The perceptual loss is used to calculate the feature error between the fused mooncake image and the original mooncake image, expressed as:
[0101]
[0102] Among them, q k ( ) represents the features of the i-th layer obtained by inputting the mooncake image into a specific network for training;
[0103] The color loss is used to calculate the color histogram error between the fused mooncake image and the original mooncake image, expressed as:
[0104] L d =||Histogram(O)-Histogram(I)||
[0105] Where Histogram(x) represents the color histogram of x.
[0106] Image fusion technology is to combine two or more images of the same scene or object into a new image through various fusion algorithms in the same coordinate system. The purpose of this process is to integrate data acquired by different sensors to enhance the availability of image information, thereby facilitating target recognition or further image analysis. In an embodiment of the present invention, multiple mooncake images from different angles are fused into a stereoscopic image of a mooncake image, which can improve the data samples input into the mooncake sorting model, avoid missed detection due to blind spots, and improve the accuracy of mooncake detection.
[0107] Traditional image fusion algorithms usually manually design fusion rules in the spatial domain or transform domain to achieve image fusion. Although traditional fusion algorithms can produce good results in most cases, manually designed fusion rules cannot handle complex images. In order to obtain a fused image containing rich information, the present invention combines pixel loss, gradient loss, perception loss and color loss to form a loss function.
[0108] Preferably, S240, fusing the defect features of the fused mooncake image to obtain the fused defect features includes:
[0109] Suppose the standard mooncake image F after binary processing i and the fused mooncake image F j , the mooncake defect area feature F obtained by the difference method t It is expressed as:
[0110] F t =xor(F i , F j )
[0111] After the mooncake image is processed by image registration and binarization, the computational complexity of image operations is greatly reduced. At this time, the image is obtained after binarization processing. The image information only covers two pixels. 0 can represent black and 1 can represent white. The difference area obtained by matching the mooncake image to be tested with the standard mooncake image is identified as a defect. Since defect errors will be caused in the image preprocessing and registration process, affecting the defect accuracy, in order to eliminate the inaccuracy caused by the defect error, morphological processing is used to judge and clean up the defect error.
[0112] Suppose there are j mooncake defect area features F to be merged t , calculate the average mooncake defect area feature, expressed as:
[0113]
[0114] Among them, function m: 2 θ →[0, 1];
[0115] The average mooncake defect area features are fused iteratively according to the following rules to obtain the final fusion result:
[0116]
[0117] Among them, D and G are both recognition frameworks for defect fusion, and m(F) is the final fusion result.
[0118] In the embodiment of the present invention, a variety of defect features are integrated to make the mooncake sorting result more reasonable, with less information to be processed and higher processing efficiency.
[0119] Preferably, S310, improving the mooncake sorting model includes:
[0120] Through Taylor decomposition of cross entropy loss function and focal loss function:
[0121]
[0122] Among them, a n∈R represents the weight coefficient of the polynomial, P n represents the probability of defect prediction of the mooncake sorting model;
[0123] Adjust the first polynomial coefficient of the Taylor expansion polynomial term, and the loss function of the mooncake sorting model is expressed as:
[0124] L = -log(P n )+ε(1-P n )
[0125] Among them, ε represents the penalty weight coefficient of the mooncake sorting model.
[0126] The loss function plays a vital role in the training process, mainly including the following aspects: Measuring model performance: The loss function is used to measure the difference between the model's prediction results and the true label. A good model should be able to minimize the loss, that is, the prediction results are as close to the actual label as possible, so as to complete the task more accurately. Optimizing model parameters: The training process of machine learning and deep learning models is an optimization problem, and the goal is to minimize the loss function. By continuously adjusting the parameters of the model, the loss function is gradually reduced, and the prediction ability of the model is gradually improved. Commonly used optimization algorithms such as gradient descent update model parameters by calculating the gradient of the loss function. Preventing overfitting: Overfitting refers to the phenomenon that the model performs well on the training data but performs poorly on new data. The loss function can help monitor the overfitting of the model during the training process. By observing the loss on the training set and the validation set, it is possible to detect whether the model is overfitting early, so as to take corresponding measures, such as regularization. Model selection and parameter adjustment: Different tasks and models may require different loss functions. Choosing an appropriate loss function can affect the performance of the model on a specific task. For example, regression tasks usually use the mean square error (MSE), and classification tasks often use the cross entropy loss function. In the process of parameter adjustment, the performance of the loss function is often used to evaluate the effect of different hyperparameters. Weighted and multi-objective optimization: In some cases, different samples or different objectives may have different importance. The loss function can introduce weights to balance the importance of different samples or objectives, thereby more accurately measuring model performance.
[0127] In an embodiment of the present invention, the designed loss function can be adjusted according to the positive sample coefficients and negative sample coefficients of different data sets, so that the mooncake sorting model is more suitable for identifying mooncakes and can judge mooncake defects faster and more accurately.
[0128] Example 2
[0129] A mooncake sorting system based on visual inspection, comprising:
[0130] Obtain mooncake images to be sorted;
[0131] Preprocess the mooncake images to be sorted;
[0132] Judge and sort the processed mooncake images.
[0133] Example 3
[0134] An electronic device includes: a processor and a memory, the memory is used to store computer program codes, the computer program codes include computer instructions, when the processor executes the computer instructions, the electronic device executes a moon cake sorting method based on visual detection.
[0135] refer to Figure 4 , the electronic device 2 includes a processor 21, a memory 22, an input device 23, and an output device 24. The processor 21, the memory 22, the input device 23, and the output device 24 are coupled via a connector, and the connector includes various interfaces, transmission lines, or buses, etc., which are not limited in the embodiments of the present invention. It should be understood that in various embodiments of the present invention, coupling refers to mutual connection in a specific manner, including direct connection or indirect connection through other devices, for example, through various interfaces, transmission lines, buses, etc.
[0136] The processor 21 may be one or more graphics processing units (GPUs). When the processor 21 is a GPU, the GPU may be a single-core GPU or a multi-core GPU. Optionally, the processor 21 may be a processor group consisting of multiple GPUs, and the multiple processors are coupled to each other via one or more buses. Optionally, the processor may also be other types of processors, etc., which are not limited in the embodiments of the present invention.
[0137] The memory 22 can be used to store computer program instructions and various computer program codes including program codes for executing the scheme of the present invention. Optionally, the memory includes but is not limited to random access memory (RAM), read-only memory (ROM), erasable programmable read only memory (EPROM), or portable read only memory (CD-ROM), which is used for related instructions and data.
[0138] The input device 23 is used to input data and / or signals, and the output device 24 is used to output data and / or signals. The output device 24 and the input device 23 may be independent devices or an integrated device.
[0139] Example 4
[0140] A computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor of an electronic device, the processor executes a mooncake sorting method based on visual detection.
[0141] The present invention fuses mooncake images from multiple angles through an image fusion model, intelligently compensates for mooncake images in blind spots, overcomes the technical problem that defects in mooncake images in blind spots cannot be detected, and the fused mooncake images can also perform volume judgment, further improving the accuracy of mooncake detection; the present invention fuses various defects that may occur in mooncakes into a feature representation, thereby improving the detection efficiency of the mooncake defect detection model, eliminating the need to detect mooncake images multiple times, and greatly improving the mooncake detection speed; the present invention also improves the mooncake detection model, and greatly improves the accuracy of mooncake detection by optimizing the loss function; the present invention processes the original captured mooncake images, and subjects the mooncake images to grayscale processing, image enhancement, and adaptive threshold division, so that the defect features of the mooncake images are easier to capture, the processing efficiency is higher, and the processing accuracy becomes higher.
[0142] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A mooncake sorting method based on visual inspection, characterized in that: include: Obtain mooncake images to be sorted; Preprocess the mooncake images to be sorted; Judge and sort the processed mooncake images.
2. A mooncake sorting method based on visual inspection according to claim 1, characterized in that: The preprocessing of the moon cake images to be sorted includes: Carry out grayscale processing, image enhancement and adaptive threshold division on the mooncake images to be sorted; Perform image fusion on the processed mooncake images at multiple different angles; Extract defect features of the fused mooncake image; The defect features of the fused mooncake image are fused to obtain a fused defect feature.
3. The mooncake sorting method based on visual inspection according to claim 1, characterized in that: The judging and sorting of the processed moon cake images comprises: Improve the mooncake sorting model; Input the fused features into the improved mooncake sorting model; The improved mooncake sorting model outputs the mooncake sorting results.
4. The mooncake sorting method based on visual inspection according to claim 2 is characterized in that: The grayscale processing, image enhancement and adaptive threshold division of the moon cake image to be sorted include: Divide a mooncake image into multiple sub-images; The most suitable threshold of the current sub-image is calculated according to the average gray value and gray level of the sub-image.
5. The mooncake sorting method based on visual inspection according to claim 2, characterized in that: The image fusion of the processed moon cake images at different angles includes: Input multiple mooncake images from different angles into the image fusion model; The image fusion model outputs the fused mooncake image; The loss function of the image fusion model is improved by combining the pixel loss, gradient loss, perceptual loss and color loss of the mooncake image as the loss function of the image fusion model; The pixel loss is used to calculate the pixel error between the fused mooncake image and the original mooncake image; The gradient loss is used to calculate the edge information loss of the fused mooncake image and the original mooncake image; The perceptual loss is used to calculate the feature error between the fused mooncake image and the original mooncake image; The color loss is used to calculate the color histogram error between the fused mooncake image and the original mooncake image.
6. A mooncake sorting method based on visual inspection according to claim 2, characterized in that: The step of fusing the defect features of the fused mooncake image to obtain the fused defect features comprises: Suppose the standard mooncake image after binary processing and the fused mooncake image, the mooncake defect area features are obtained by difference method; Calculate the average mooncake defect area characteristics; The average mooncake defect area features are fused iteratively according to the preset rules to obtain the final fusion result.
7. The mooncake sorting method based on visual inspection according to claim 3, characterized in that: The improvement of the mooncake sorting model includes: Through Taylor decomposition of cross entropy loss function and focal loss function; Adjust the first polynomial coefficient of the Taylor expansion polynomial term and calculate the loss function of the mooncake sorting model.
8. A mooncake sorting system based on visual inspection, characterized in that: include: Obtain mooncake images to be sorted; Preprocess the mooncake images to be sorted; Judge and sort the processed mooncake images.
9. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store computer program codes, wherein the computer program codes include computer instructions. When the processor executes the computer instructions, the electronic device executes a mooncake sorting method based on visual detection as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which includes program instructions. When the program instructions are executed by a processor of an electronic device, the processor executes a mooncake sorting method based on visual inspection as described in any one of claims 1 to 7.
Citation Information
Cited By
Food production process and production equipment thereof
CN120694285A
A food production process and production equipment therefor
CN120694285B