A method for calculating the recommendation degree of digital samples of cigarette defects
Through a method of calculating the recommended degree of cigarette defects that combines deep learning models and feature image similarity measurements, the problem of automated collection and recommendation degree calculation of tobacco defect detection in the prior art is solved, and the automated construction of the digital sample library for tobacco defects and the stability of tobacco quality is realized.
Patent Information
- Application Number
- CN202411940289.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-04
AI Technical Summary
In the detection of the appearance defect of tobacco branches, the prior art is difficult to fully cover various forms of tobacco branches, which leads to the need to manually make physical samples during equipment inspection, and the defect picture classification does not meet the tobacco standards, and lacks automated method for calculating the recommended degree of defect digital samples.
A method of calculating the recommended degree of cigarette defect digital samples is adopted, including obtaining calculating defect pictures, calculating a prior probability, obtaining feature images, calculating the recommended degree, and using it to generate a defect digital sample library. This method combines deep learning models and feature image similarity measurements, and realizes automated recommendation calculations through weight assignment and prior probability calculations.
The automatic collection and recommendation calculation of the digital sample library for tobacco defects is realized, the production efficiency is improved, the production process of tobacco span detection is improved, and the stability of tobacco span quality is ensured.
Smart Images

Figure QLYQS_1 
Figure QLYQS_3 
Figure QLYQS_8
Abstract
Description
Technical Field
[0001] The invention belongs to the field of computer vision, and in particular to a method for calculating the recommendation degree of a digital sample of cigarette defects. Background Art
[0002] In the detection of appearance defects in cigarettes, the appearance inspection equipment needs to input physical samples of defective cigarettes. This requires manual production of physical samples. Artificially produced physical samples are made by making specific defects on cigarettes based on the experience of the operator. Then the equipment detects it. If it can be detected smoothly, it is considered that the equipment is operating normally, otherwise the equipment needs to be repaired and debugged. However, in actual production, cigarette defects are of various types and in different shapes. Operators cannot produce them all on physical samples. This requires a new technical means to make full use of the defect images detected in production and generate a defect digital sample library to guide production. In addition, there are too many defect images on the equipment side, and the classification does not meet the tobacco standards. A method is needed to automatically calculate the recommendation degree of defect digital samples, so as to provide a reference for improving the defect digital sample library. Summary of the invention
[0003] The present invention aims to solve the deficiencies of the above-mentioned prior art and proposes a method for calculating the recommendation degree of digital samples of cigarette defects, so as to accurately and effectively complete the collection of digital samples of cigarette defects, thereby realizing the establishment of a digital sample library of cigarette defects, which can be used to replace physical samples in production to check whether the equipment is normal, thereby improving production efficiency, improving the production process of cigarette detection, and ensuring the stability of cigarette quality.
[0004] In order to achieve the above-mentioned purpose, the present invention adopts the following technical scheme:
[0005] The method for calculating the recommendation degree of a digital sample of cigarette defects of the present invention is characterized in that it comprises the following steps:
[0006] Step 1: Obtain defective cigarette images and count the number of defective cigarette images of each category, and then use formula (1) to calculate the prior probability p of the i-th category of defective cigarette images: i :
[0007] (1)
[0008] In formula (1), n i represents the total number of images of cigarette defects of the i-th category; N represents the total category of cigarette defects;
[0009] Step 2: Let the weight of the i-th type of cigarette defect be w i ,and ;
[0010] Step 3: Sample a cigarette defect image P from the visual detection terminal and input it into the defect detection model for processing to obtain the category k to which the defect in the cigarette defect image P belongs, and take the position coordinates of the cigarette defect area in P as (x min , y min , x max , y max ), where x min and y min are respectively the abscissa and ordinate of the upper left corner of the cigarette defect area, and x max and y max are respectively the abscissa and ordinate of the lower right corner of the cigarette defect area;
[0011] Step 4: Obtain the feature image F of the cigarette defect area in P:
[0012] Step 4.1. Take P as the grayscale cigarette defect map G;
[0013] Step 4.2. Sort the pixel values in the cigarette defect area in G to obtain the sorted pixel value set G sort = {g1, g2, …, g p , …, g K}, where g p represents the p-th pixel value after sorting in the cigarette defect area, and K is the total number of pixels in the cigarette defect area;
[0014] Step 4.3. Calculate the median pixel value of the cigarette defect area using Equation (2):
[0015] (2)
[0016] Step 4.4. Generate a two-dimensional matrix flag with width and height W and H respectively, where W = x max - x min , H = y max - y min ;
[0017] Step 4.5. Compare the pixel value G(m, n) at the m-th row and n-th column in the defect area of G with the median:
[0018] If G(m, n) < median, then set the original value flag(m - x min row and n - y min column in the two-dimensional matrix flag to 0, otherwise, set flag(m - x min , n - y min ) = 1; where xmin ≤m≤x max ,y min ≤m≤y max ;
[0019] Step 4.6. Use bilinear interpolation to scale flag to obtain an intermediate matrix fm with a dimension of M×M;
[0020] Step 4.7. If the value of the element in row ii and column jj in fm is If it is greater than 1, then let the eigenvalue of the iith row and jjth column in the feature image F be is 1, otherwise, let is 0; thus obtaining a feature image F with a dimension of M×M;
[0021] Step 5: If the number of defective digital samples of the kth category in the defective digital sample library is zero, then the recommendation degree of P is set to = 100, and P, F, the position coordinates of the defect area (x min , y min , x max , y max ) as a k-th defect digital sample and stored in the defect digital sample library; otherwise, proceed to step 6;
[0022] Step 6: Use formula (3) to calculate the weighted quantity ratio of the k-th type of defects in the defect digital sample library: k :
[0023] (3)
[0024] In formula (3), w k is the weight of the k-th defect, represents the weight of the i-th defect; is the total number of k-th type defect digital samples in the defect digital sample library; Represents the total number of defect digital samples of the i-th category in the defect digital sample library;
[0025] Step 7: Calculate F using formula (4) and the characteristic image F of the cigarette defect area in the jth cigarette defect image in the defect digital sample library j The distance metric d j :
[0026] (4)
[0027] In formula (4), The feature image F represents the cigarette defect area in the j-th cigarette defect image j The eigenvalue of the mth row and nth column in ; Represents the eigenvalue of the mth row and nth column in the feature image F;
[0028] Step 8: Use formula (5) to obtain the distance measurement d between image F and all feature images of the k-th type of defect digital samples in the defect sample library: avg :
[0029] (5)
[0030] Step 9: Calculate the recommendation degree of the k-th defect digital sample using formula (6) :
[0031] =w s1 ×d avg + w s2 ×pre k + w s3 ×p k (6)
[0032] In formula (6), p k is the prior probability of the k-th defective digital sample appearing, w s1 , w s2 , w s3 There are 3 weights respectively;
[0033] Step 10: If <score min , then let =score min ,if >score max , then let =score max , where score min and score max are the minimum and maximum thresholds of the recommendation degree respectively;
[0034] Step 11: Use formula (7) to convert the result Normalized to (0,100), thus obtaining the final recommendation degree of the k-th defect digital sample :
[0035] (7).
[0036] An electronic device of the present invention includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the recommendation degree calculation method, and the processor is configured to execute the program stored in the memory.
[0037] The present invention provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and the computer program executes the steps of the recommendation degree calculation method when the computer program is executed by a processor.
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] 1. The present invention adopts a deep learning model to classify defect images, and the result has good generalization ability.
[0040] 2. The present invention uses feature images as a similarity measurement algorithm, which can effectively eliminate the interference of noise points.
[0041] 3. The present invention assigns weights to each type of defect sample, and can process defects at different levels, which can effectively meet production needs.
[0042] 4. The present invention comprehensively considers the prior probability of defects, similarity, and sample number balance, thereby ensuring the effectiveness of the defect digital sample library. DETAILED DESCRIPTION
[0043] In this embodiment, a method for calculating the recommendation degree of a digital sample of cigarette defects includes the following steps:
[0044] Step 1: Collect a large number of defective images from the visual inspection terminal in the packaging workshop, and count the number of defective images of each type of cigarette, so as to calculate the prior probability p of the i-th type of cigarette defective image using formula (1): i :
[0045] (1)
[0046] In formula (1), n i represents the total number of defective images of the i-th category of cigarettes; N represents the total category of cigarette defects; in order to reflect the actual production situation, sample balancing is not required here.
[0047] Step 2: Let the weight of the i-th type of cigarette defect be w i ,and ;
[0048] Step 3: Sample a cigarette defect image P from the visual inspection terminal and input it into the defect detection model for processing, obtain the category k to which the defect in the cigarette defect image P belongs, and set the position coordinates of the cigarette defect area in P as (x min , y min , x max , y max ), where x min and min are the horizontal and vertical coordinates of the upper left corner of the cigarette defect area, respectively. max and maxThey are respectively the abscissa and ordinate of the lower right corner of the cigarette rod defect area.
[0049] Step 4: To accurately describe the local texture features of the defect, obtain the feature image F of the cigarette rod defect area in P:
[0050] Step 4.1: Take P as the grayscale cigarette rod defect map G;
[0051] Step 4.2: Sort the pixel values in the cigarette rod defect area in G to obtain the sorted pixel value set G sort ={g1, g2, …, g p , …, g K}, where g p represents the p-th pixel value after sorting in the cigarette rod defect area, and K is the total number of pixels in the cigarette rod defect area;
[0052] Step 4.3: Calculate the median pixel value of the cigarette rod defect area using Equation (2):
[0053] (2)
[0054] Step 4.4: Generate a two-dimensional matrix flag with width and height of W and H respectively, where W = x max - x min , H = y max - y min ;
[0055] Step 4.5: Compare the pixel value G(m, n) at the m-th row and n-th column in the defect area in G with the median:
[0056] If G(m, n) < median, then set the original value flag(m - x min row n - y min column flag(m - x min , n - y min ) = 0, otherwise, set flag(m - x min , n - y min ) = 1; where x min ≤ m ≤ x max , y min ≤ m ≤ y max ;
[0057] Step 4.6: Scale flag using bilinear interpolation to obtain the intermediate matrix fm with dimensions M×M; Normalizing the size of the feature matrix can ensure more stable and effective subsequent distance measurement.
[0058] Step 4.7: If the element value at the ii-th row and jj-th column in fm If it is greater than 1, then let the eigenvalue of the iith row and jjth column in the feature image F be is 1, otherwise, let is 0; thus obtaining a feature image F with a dimension of M×M;
[0059] Step 5: If the number of defective digital samples of the kth category in the defective digital sample library is zero, then the recommendation degree of P is set to = 100, and P, F, the position coordinates of the defect area (x min , y min , x max , y max ) as a k-th defect digital sample and stored in the defect digital sample library; otherwise, go to step six.
[0060] Step 6: Use formula (3) to calculate the weighted quantity ratio of the k-th type of defects in the defect digital sample library: k :
[0061] (3)
[0062] In formula (3), w k is the weight of the k-th defect, represents the weight of the i-th defect; is the total number of k-th type defect digital samples in the defect digital sample library; The total number of defect digital samples of category i in the defect digital sample library;
[0063] Step 7: Calculate F using formula (4) and the characteristic image F of the cigarette defect area in the jth cigarette defect image in the defect digital sample library j The distance metric d j :
[0064] (4)
[0065] In formula (4), The feature image F represents the cigarette defect area in the j-th cigarette defect image j The eigenvalue of the mth row and nth column in ; Represents the eigenvalue of the mth row and nth column in the feature image F.
[0066] Step 8: Use formula (5) to obtain the distance measurement d between image F and all feature images of the k-th type of defect digital samples in the defect sample library: avg :
[0067] (5)
[0068] In formula (5), is the number of digital samples of the kth type of defects in the defect sample library;
[0069] Step 9: Calculate the recommendation degree of the k-th defect digital sample using formula (6) :
[0070] =w s1 ×d avg + w s2 ×pre k + w s3 ×p k (6)
[0071] In formula (6), p k is the prior probability of the k-th defective digital sample appearing, w s1 , w s2 , w s3 There are three weights respectively; here, the similarity with the existing digital samples, the prior probability, and the existing quantity are considered at the same time, which can ensure that the calculated recommendation degree is more representative.
[0072] Step 10: If <score min , then let =score min ,if >score max , then let =score max , where score min and score max are the minimum and maximum thresholds of the recommendation degree respectively;
[0073] Step 11: Use formula (7) to convert the result Normalized to (0,100), thus obtaining the final recommendation degree of the k-th defect digital sample :
[0074] (7).
[0075] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.
[0076] In this embodiment, a computer-readable storage medium stores a computer program on the computer-readable storage medium, and the computer program executes the steps of the above method when executed by a processor.
Claims
1. A method for calculating the recommendation degree of a digital sample of cigarette defects, characterized in that: The steps include: Step 1: Obtain defective cigarette images and count the number of defective cigarette images of each category, and then use formula (1) to calculate the prior probability p of the i-th category of defective cigarette images: i : (1) In formula (1), n i represents the total number of images of cigarette defects of the i-th category; N represents the total category of cigarette defects; Step 2: Let the weight of the i-th type of cigarette defect be w i ,and ; Step 3: Sample a cigarette defect image P from the visual inspection terminal and input it into the defect detection model for processing, obtain the category k to which the defect in the cigarette defect image P belongs, and set the position coordinates of the cigarette defect area in P as (x min ,y min , x max , y max ), where x min and min are the horizontal and vertical coordinates of the upper left corner of the cigarette defect area, respectively. max and max They are the horizontal and vertical coordinates of the lower right corner of the defective area of the cigarette; Step 4: Obtain the characteristic image F of the cigarette defect area in P: Step 4.
1. Let P be the grayscale cigarette defect image G; Step 4.
2. Sort the pixel values in the defective area of the cigarette in G to obtain the sorted pixel value set G sort ={g1, g2, … ,g p , … ,g K }, where g p represents the pth pixel value after sorting in the defective area of the cigarette, and K is the total number of pixels in the defective area of the cigarette; Step 4.
3. Use formula (2) to calculate the median pixel value of the cigarette defect area: (2) Step 4.
4. Generate a two-dimensional matrix flag with width W and height H, where W=x max -x min , H = y max -y min ; Step 4.
5. Compare the pixel value G(m, n) at the mth row and nth column in the defect area of G with median: If G(m, n) < median, then set the original value of the element at the (m - x)-th row and (n - y)-th column in the two-dimensional matrix flag to 0. Otherwise, set flag(m - x, n - y) = 1; where x ≤ m ≤ x, y ≤ m ≤ y; min row and the (n - y)-th min column to 0. Otherwise, set flag(m - x min , n - y min ) = 1; where x min , n - y min ) = 1; where x min ≤ m ≤ x max , y min ≤ m ≤ y max ; It should be noted that there may be some inaccuracies in the original text's logical expressions such as "x ≤ m ≤ x" and "y ≤ m ≤ y", which might need to be further verified and corrected in the actual context. Step 4.
6. Use bilinear interpolation to scale flag to obtain an intermediate matrix fm with a dimension of M×M; Step 4.
7. If the value of the element in row ii and column jj in fm is If it is greater than 1, then let the eigenvalue of the iith row and jjth column in the feature image F be is 1, otherwise, let is 0; thus obtaining a feature image F with a dimension of M×M; Step 5: If the number of defective digital samples of the kth category in the defective digital sample library is zero, then the recommendation degree of P is set to = 100, and P, F, the position coordinates of the defect area (x min , y min , x max , y max ) as a k-th defect digital sample and stored in the defect digital sample library; otherwise, proceed to step 6; Step 6: Use formula (3) to calculate the weighted quantity ratio of the k-th type of defects in the defect digital sample library: k : (3) In formula (3), w k is the weight of the k-th defect, represents the weight of the i-th defect; is the total number of k-th type defect digital samples in the defect digital sample library; Represents the total number of defect digital samples of the i-th category in the defect digital sample library; Step 7: Calculate F using formula (4) and the characteristic image F of the cigarette defect area in the jth cigarette defect image in the defect digital sample library j The distance metric d j : (4) In formula (4), The feature image F represents the cigarette defect area in the j-th cigarette defect image j The eigenvalue of the mth row and nth column in ; Represents the eigenvalue of the mth row and nth column in the feature image F; Step 8: Use formula (5) to obtain the distance measurement d between image F and all feature images of the k-th type of defect digital samples in the defect sample library: avg : (5) Step 9: Calculate the recommendation degree of the k-th defect digital sample using formula (6) : =in s1 ×d avg + in s2 ×pre k + in s3 ×p k (6) In formula (6), p k is the prior probability of the k-th defective digital sample appearing, w s1 , w s2 , w s3 There are 3 weights respectively; Step 10: If <score min , then let =score min ,if >score max , then let =score max , where score min and score max are the minimum and maximum thresholds of the recommendation degree respectively; Step 11: Use formula (7) to convert the result Normalized to (0,100), thus obtaining the final recommendation degree of the k-th defect digital sample : (7)。 2. An electronic device, comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the recommendation degree calculation method according to claim 1, and the processor is configured to execute the program stored in the memory.
3. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the recommendation degree calculation method according to claim 1 are executed.
Citation Information
Cited By
Unstructured image data structured processing method based on CCD visual inspection
CN122175928A