Cigarette packet appearance defect classification method, device and equipment and storage medium
By establishing a dynamic mapping database and a visual inspection system, and combining SIFT, HOG, and LBP algorithms to dynamically adjust the inspection window, the problem of low efficiency in existing cigarette pack visual inspection systems has been solved, achieving high-precision, real-time classification of cigarette pack appearance defects.
Patent Information
- Application Number
- CN202511785796.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-01
- Publication Date
- 2026-03-06
Smart Images

Figure CN121614905A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of tobacco production technology, and in particular to a method, apparatus, equipment and storage medium for classifying appearance defects in cigarette packs. Background Technology
[0002] In the tobacco packaging production process, the appearance quality inspection of cigarette packs is a crucial step in ensuring product qualification. However, existing cigarette pack visual inspection systems have the following limitations: First, the static, manually preset inspection windows cannot adapt to the rapid switching between multiple specifications of cigarette packs (different grades and brands), which easily leads to missed inspections. For example, when switching brands, each system requires manual intervention for 25 to 40 minutes. Second, many complex process defects (such as poor adhesion, missing hot stamping, etc.) require manual matching of the inspection window area, resulting in low efficiency. Summary of the Invention
[0003] The main objective of this application is to provide a method, apparatus, device, and storage medium for classifying appearance defects in cigarette packs, in order to solve the problem that existing visual inspection systems for cigarette packs require manual matching of inspection window areas, resulting in low efficiency.
[0004] To achieve the above objectives, this application provides the following technical solution: A method for classifying appearance defects in cigarette packs, the method being applied to cigarette packs located on an assembly line, the method comprising: Step S1: Construct a mapping database based on the pre-collected data, including cigarette pack defect type numbers, detection window coordinates, and image feature identifiers; Step S2: Real-time acquisition of cigarette pack images on the production line using a visual inspection system, and extraction of visual feature identifiers from the cigarette pack images; Step S3: Calculate the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database; Step S4: Determine whether the cosine similarity is less than a preset similarity threshold. If so, proceed to step S5. Step S5: The visual feature identifier is compared with the image feature identifier in the mapping database using the nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack.
[0005] Beneficial effects: Steps S1 to S5 utilize the dynamic mapping database established in step S1 to standardize the association between cigarette pack defect type numbers, detection window coordinates, and image feature identifiers, providing a complete data foundation for subsequent classification. This database not only contains predefined process defect codes (such as "missing side ears" and "missing hot stamping"), but also stores the reference coordinates and dynamic offset parameters of the detection window, ensuring adaptability to the detection needs of cigarette packs of different specifications. Step S2 uses a vision inspection system to acquire cigarette pack images in real time and extract visual feature identifiers. A multi-dimensional feature vector is constructed using the Scale Invariant Feature Transform (SIFT) algorithm combined with Histogram of Oriented Gradients (HOG) and Local Binary Pattern (LBP) texture features, which can comprehensively capture the visual characteristics of the cigarette pack surface, including key information such as edges, corners, and textures. Step S... 3. Intelligent matching of real-time features and database features is achieved by calculating cosine similarity. L2 norm normalization is used to ensure the accuracy of vector comparison. The dot product operation directly reflects the directional consistency of feature vectors, providing a reliable similarity measure for defect identification. Step S4 introduces a similarity threshold judgment mechanism, forming an intelligent screening process. The classification process is only triggered when the similarity between real-time features and database features is lower than a preset threshold, effectively eliminating interference items and improving the system's decision-making efficiency. Step S5 uses the nearest neighbor classification algorithm to achieve accurate matching through feature distance measurement (1-cosine similarity). The minimum distance principle ensures the reliability of the classification results. The system can directly convert the feature matching results into specific defect type numbers based on the association relationships in the mapping database, realizing a fully automated process from image acquisition to defect identification. The synergistic effect of these five steps enables the cigarette pack appearance defect classification system to have high accuracy, real-time performance, and adaptability, meeting the quality inspection needs of assembly line production.
[0006] As a further improvement to this application, step S4 determines whether the cosine similarity is less than a preset similarity threshold. If so, step S5 is executed, followed by: Step S10: If not, determine whether there is a deviation between the real-time detection window coordinates and the detection window coordinates; if yes, proceed to step S20. Step S20: Calculate the offset of the current real-time detection window coordinates using equation (1): (1); in, The offset is... The calibration coefficient is... The feature vector that identifies the visual features. The feature vector that identifies the image features; Step S30: Adjust the coordinates of the current real-time detection window using an adaptive window matching algorithm to eliminate the offset; Step S40: Repeat steps S2 to S5 based on the adjusted detection window coordinates to identify the defect type number corresponding to the cigarette pack.
[0007] Beneficial effects: Steps S10 to S40, through a dynamic detection window coordinate adjustment mechanism, significantly improve the adaptability and detection accuracy of the cigarette pack appearance defect classification system. When the cosine similarity does not reach a preset threshold, the system can automatically identify the coordinate deviation between the real-time detection window and the standard window, and accurately calculate the offset using the formula ΔP=K×(F_current-F_base), where the calibration coefficient K ensures the accuracy of the offset calculation. Subsequently, an adaptive window matching algorithm is used to adjust the detection window coordinates in real time, effectively eliminating positioning deviations caused by differences in cigarette pack specifications or production line vibrations. This dynamic adjustment mechanism allows the system to automatically adapt to the detection needs of cigarette packs of different specifications without interrupting production, solving the limitations of traditional fixed window detection methods in multi-specification production scenarios. By re-executing the image acquisition and feature matching process after adjustment, the system significantly improves the accuracy of defect identification and reduces false detections and missed detections caused by inaccurate window positioning. In addition, this mechanism operates fully automatically, completing window calibration without manual intervention, greatly reducing production line downtime and manual adjustment costs, and improving overall production efficiency. Meanwhile, dynamic window adjustment enhances the system's robustness to fluctuations in the production line environment, effectively addressing complex situations such as cigarette pack position shifts and angle changes, ensuring stable detection performance even in high-speed assembly line environments. This adaptive detection window adjustment technology provides a more flexible and reliable solution for classifying cigarette pack appearance defects, and is particularly suitable for the modern flexible production needs of multi-variety, small-batch manufacturing.
[0008] As a further improvement to this application, step S5 involves comparing the visual feature identifier with the image feature identifier in the mapping database using a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack. Following this, the process includes: Step S100: Send the defect type number and visual feature identifier corresponding to the cigarette pack to the external visualization terminal.
[0009] Beneficial effects: Step S100 provides an interface for manual intervention, allowing staff to understand the classification process in real time and then proactively intervene based on actual needs or decisions.
[0010] As a further improvement to this application, step S1 involves constructing a mapping database based on pre-collected data, including cigarette pack defect type numbers, detection window coordinates, and image feature identifiers, comprising: Step S11: Obtain several process defect image data of the production line, and extract the image feature identifier of each process defect image data respectively; Step S12: Classify and encode all process defect image data, and construct a defect type number mapping table based on the same encoding standard. The defect type number mapping table includes several cigarette pack defect type numbers. Step S13: Obtain the detection window coordinates corresponding to each process defect image data; Step S14: Associate and map the defect type number, detection window coordinates, and image feature identifier of the same process defect image data to obtain the mapping database.
[0011] Preferably, steps S11 to S14 establish a digital representation of the visual features of defects by acquiring image data of process defects in the production line and extracting image feature identifiers, ensuring that each defect has a corresponding feature vector description. Secondly, all process defect data are uniformly classified and coded, constructing a defect type number mapping table to achieve standardized management of defect types. This ensures that different defect types, such as "missing side ears" and "missing hot stamping," have unique number identifiers, eliminating the subjective differences of manual classification. Simultaneously, by acquiring the detection window coordinates corresponding to each process defect image data, a correlation between the spatial location of the defect and its visual features is established, providing accurate positioning basis for subsequent real-time detection. Finally, the defect type number, detection window coordinates, and image feature identifiers are correlated and mapped to form a structured dynamic mapping database, enabling the system to quickly retrieve other related information through any element. This database construction process not only covers all known defect patterns in the cigarette packaging production process, but its standardized data structure also supports expansion and updates when new defects are discovered, ensuring the continuous applicability of the defect classification system. Through this multi-dimensional correlation mapping, the system can achieve rapid and accurate identification from visual features to defect types, providing reliable data support for real-time quality inspection on the production line.
[0012] As a further improvement to this application, step S2 involves acquiring images of cigarette packs on the production line in real time using a visual inspection system and extracting visual feature identifiers from the cigarette pack images, including: Step S21: When the cigarette pack passes through the inspection station of the production line, the image of the cigarette pack on the production line is collected in real time based on the vision inspection system. Step S22: Preprocess each cigarette pack image and locate the detection area in the preprocessed cigarette pack image based on the detection window coordinates in the mapping database; Step S23: Based on the detection area, extract key point feature descriptors using the scale-invariant feature transformation algorithm, and construct a visual feature vector by weighted averaging of the directional gradient histogram features and local binary pattern texture features. Step S24: Normalize the visual feature vector to obtain the visual feature identifier.
[0013] Beneficial effects: Steps S21 to S24, through a systematic image acquisition and feature extraction process, provide a high-precision and reliable data foundation for classifying cigarette pack appearance defects. When a cigarette pack passes through the inspection station, the vision inspection system accurately triggers image acquisition, ensuring real-time acquisition of a complete image of the pack's surface. This synchronization mechanism effectively avoids image blurring or misalignment caused by high-speed movement on the production line. The acquired raw images undergo preprocessing, including grayscale conversion, histogram equalization, and Gaussian filtering, significantly improving image quality and eliminating uneven lighting and noise interference, creating ideal input conditions for subsequent feature extraction. Based on the detection window coordinates in the mapping database, the system can accurately locate the detection area of the cigarette pack image. This coordinate-driven positioning method ensures a strict correspondence between the detection window and the standard position, providing spatial consistency for defect identification. In the feature extraction stage, keypoint feature descriptors are extracted using the Scale Invariant Feature Transform (SIFT) algorithm. These descriptors are then combined with Histogram of Oriented Gradients (HOG) and Local Binary Pattern (LBP) texture features to construct a multi-dimensional visual feature vector. This multi-feature fusion strategy comprehensively captures the visual characteristics of the cigarette pack surface, including key information such as edges, corners, and textures, significantly improving the robustness and discriminative power of feature description. Finally, the feature vectors are normalized to generate standardized visual feature identifiers. This step eliminates the influence of vector magnitude differences, allowing the feature vectors to purely reflect directional similarity. This provides a standardized data format for subsequent cosine similarity calculations and nearest neighbor classification, enabling direct comparison. The entire process achieves efficient conversion from raw images to structured feature identifiers, providing accurate and stable front-end data support for the defect classification system.
[0014] As a further improvement to this application, step S3, calculating the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database, includes: Step S31: Obtain the visual feature vector and extract all image feature vectors from the mapping database to form a baseline feature vector set; Step S32: Convert each image feature vector and each visual feature vector into unit vector form using the L2 norm, and obtain an image feature unit vector and a visual feature unit vector based on an image feature vector and each visual feature vector, respectively. Step S33: Perform a dot product operation between the current visual feature unit vector and each image feature unit vector. Based on a visual feature unit vector, obtain several dot product results. Each dot product result is a cosine similarity.
[0015] Beneficial effects: Steps S31 to S33 establish a complete feature comparison data framework by acquiring real-time visual feature vectors and extracting the benchmark feature set from the mapping database, ensuring that subsequent calculations can cover all predefined defect patterns. This step structurally associates real-time detected features with the standard feature library, providing clear data objects for similarity analysis. Secondly, step S32 normalizes the feature vectors using the L2 norm, converting them into unit vectors by dividing the vector by its magnitude, effectively eliminating the influence of vector length on similarity calculations. This normalization process ensures that subsequent similarity calculations purely reflect the alignment of feature vectors in direction, avoiding misjudgments caused by differences in feature scale, and is particularly suitable for situations where there may be changes in illumination or fluctuations in local feature intensity in cigarette pack images. Finally, step S33 directly obtains the cosine similarity value through the unit vector dot product operation, utilizing the mathematical property (the dot product of two unit vectors equals the cosine of their included angle) to achieve efficient and accurate similarity measurement. These three steps together construct a rigorous feature matching process: from data preparation to standardization and then to mathematical calculation, ensuring that the system can accurately quantify the similarity between real-time cigarette pack features and standard defect templates. This calculation method is particularly crucial for identifying subtle defects on the surface of cigarette packs, because even very small feature deviations (such as edge offsets in hot stamping) can be sensitively captured through changes in the cosine similarity value, providing a high-resolution similarity index for subsequent defect classification decisions.
[0016] As a further improvement to this application, step S5, comparing the visual feature identifier with the image feature identifier in the mapping database using a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack, includes: Step S51: Obtain all cosine similarities less than the preset similarity threshold, and subtract each cosine similarity from 1 to convert it into a feature distance metric based on a cosine similarity. Step S52: Based on each feature distance metric, find the corresponding image feature identifier in the mapping database, and select the image feature identifier with the smallest feature distance metric as the nearest neighbor; Step S53: Query the defect type number stored in the mapping database based on the nearest neighbor image feature identifier to obtain the defect type number corresponding to the cigarette pack.
[0017] Beneficial effects: Steps S51 to S53 convert cosine similarity into a feature distance metric (step S51), establishing a mathematical expression more suited to classification requirements. The conversion of 1 minus cosine similarity not only preserves the information content of the original similarity but also constructs a rigorous distance metric space, enabling subsequent nearest neighbor search to operate based on a clear distance standard. This conversion ensures the mathematical rigor of feature comparison, laying a theoretical foundation for accurate classification. Secondly, the nearest neighbor search based on the feature distance metric (step S52) traverses all image feature labels in the mapping database, selecting the label with the smallest feature distance as the matching result. This method fully utilizes… The complete information in the database avoids coarse judgments based on a single threshold, effectively distinguishing similar but different defect patterns. Especially when dealing with multiple types of small-difference cigarette pack defects, the minimum distance principle significantly improves the discrimination and accuracy of classification. Finally, by querying the defect type number through nearest-neighbor image feature identifiers (step S53), a direct association between feature matching and specific defect types is established. This database-based query mechanism ensures the traceability and consistency of classification results. Each identified defect type number has a corresponding standard feature template as support, guaranteeing the reliability of the classification results and providing structured data support for quality analysis and process improvement. These three steps together constitute a complete classification decision-making closed loop. From mathematical transformation to feature matching to result output, each step is optimized for the specific needs of cigarette pack defect classification, ultimately achieving high-precision and interpretable defect identification.
[0018] To achieve the above objectives, this application also provides the following technical solutions: A device for classifying appearance defects in cigarette packs, wherein the appearance defect classification device is applied to the appearance defect classification method described above, and the appearance defect classification device comprises: The mapping database construction module is used to build a mapping database based on pre-collected data, including cigarette pack defect type numbers, detection window coordinates, and image feature identifiers. The visual feature identification extraction module is used to acquire images of cigarette packs on the production line in real time through a visual inspection system and extract the visual feature identification of the cigarette pack images. The cosine similarity calculation module is used to calculate the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database. The cosine similarity determination module is used to determine whether the cosine similarity is less than a preset similarity threshold; The defect type number identification module is used to identify the defect type number corresponding to the cigarette pack by comparing the visual feature identifier with the image feature identifier in the mapping database through the nearest neighbor classification algorithm if the defect type is found to be found.
[0019] To achieve the above objectives, this application also provides the following technical solutions: An electronic device includes a processor and a memory coupled to the processor, the memory storing program instructions executable by the processor; when the processor executes the program instructions stored in the memory, it implements the appearance defect classification method described above.
[0020] To achieve the above objectives, this application also provides the following technical solutions: A computer-readable storage medium storing program instructions that, when executed by a processor, can implement the appearance defect classification method described above. Attached Figure Description
[0021] Figure 1 This is a flowchart illustrating the steps of an embodiment of a method for classifying appearance defects in cigarette packs according to this application. Figure 2 This is a functional module diagram of an embodiment of a cigarette pack appearance defect classification device according to this application; Figure 3 This is a schematic diagram of the structure of an embodiment of the electronic device of this application; Figure 4 This is a schematic diagram of the structure of one embodiment of the storage medium of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0023] The terms "first," "second," and "third" in this application are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. All directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of this application are only used to explain the relative positional relationships and movement of components in a specific orientation (as shown in the figures). If the specific orientation changes, the directional indications also change accordingly. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to those processes, methods, products, or devices.
[0024] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0025] like Figure 1 As shown, this embodiment provides an example of a method for classifying appearance defects in cigarette packs. In this embodiment, the appearance defect classification method is applied to cigarette packs located on an assembly line.
[0026] Specifically, the method for classifying appearance defects includes the following steps: Step S1: Construct a mapping database based on the pre-collected data, including the defect type number of the cigarette pack, the coordinates of the detection window, and the image feature identifier.
[0027] Further, step S1 involves constructing a mapping database based on the pre-collected data, including cigarette pack defect type numbers, detection window coordinates, and image feature identifiers. Specifically, this includes: Step S11: Obtain several process defect image data of the production line, and extract the image feature identifier of each process defect image data.
[0028] Preferably, all possible process defects in cigarette packaging production need to be systematically classified and coded, and a defect type numbering system should be established according to a unified standard. For example, "missing side ear" is coded as "1", "missing hot stamping" is coded as "2", and "loose lid" is coded as "12", etc., to ensure that each defect type has a unique identifier, laying the foundation for subsequent database association.
[0029] Preferably, the mainstream defect types are shown in Table 1 below: Table 1: Types of Process Defects.
[0030] Step S12: Classify and encode all process defect image data, and construct a defect type number mapping table based on the same encoding standard. The defect type number mapping table includes several cigarette pack defect type numbers.
[0031] Preferably, after completing the defect coding, it is necessary to define corresponding detection window spatial position parameters for each defect category. These parameters include two core elements: reference coordinates and dynamic offset. The reference coordinates correspond to the edge positioning in the camera-captured image and are used to determine the initial position of the detection window in the image; the dynamic offset serves as a reserved parameter for subsequent adjustments based on real-time image features.
[0032] Step S13: Obtain the detection window coordinates corresponding to each process defect image data.
[0033] Preferably, image feature identifiers are extracted from standard cigarette pack sample images based on the defined detection window positions. These feature identifiers use a unified feature vector representation method, which can accurately describe the visual characteristics of the corresponding defects. For example, the code "NG:9" represents a specific image feature pattern, namely the smoke content on the top edge of the box lid in Table 1 above. These feature identifiers, along with the defect category number and detection window coordinates, are stored in the database.
[0034] Step S14: Associate and map the defect type number, detection window coordinates, and image feature identifier of the same process defect image data to obtain a mapping database.
[0035] Preferably, the defect category number, detection window coordinates, and image feature identifier obtained in the previous steps are associated and mapped. By establishing the correspondence between the three, a complete dynamic mapping database structure is formed, enabling the system to quickly locate the corresponding defect category and detection window position based on the image features acquired in real time.
[0036] Beneficial effects: Steps S11 to S14 acquire process defect image data from the production line and extract image feature identifiers to establish a digital representation of the visual features of defects, ensuring that each defect has a corresponding feature vector description. Secondly, all process defect data are uniformly classified and coded, constructing a defect type number mapping table to achieve standardized management of defect types. This ensures that different defect types, such as "missing side ears" and "missing hot stamping," have unique number identifiers, eliminating the subjective differences of manual classification. Simultaneously, by acquiring the detection window coordinates corresponding to each process defect image data, a correlation between the spatial location of the defect and its visual features is established, providing accurate positioning basis for subsequent real-time detection. Finally, the defect type number, detection window coordinates, and image feature identifiers are mapped together to form a structured dynamic mapping database, enabling the system to quickly retrieve other related information using any element. This database construction process not only covers all known defect patterns in the cigarette packaging production process, but its standardized data structure also supports expansion and updates when new defects are discovered, ensuring the continuous applicability of the defect classification system. Through this multi-dimensional correlation mapping, the system can achieve rapid and accurate identification from visual features to defect types, providing reliable data support for real-time quality inspection on the production line.
[0037] Step S2: Real-time images of cigarette packs on the production line are acquired through a visual inspection system, and visual feature identifiers of the cigarette pack images are extracted.
[0038] Further, step S2 involves acquiring images of cigarette packs on the production line in real time using a visual inspection system and extracting visual feature identifiers from the cigarette pack images. This specifically includes the following steps: Step S21: When the cigarette packs pass through the inspection station of the production line, the images of the cigarette packs on the production line are collected in real time based on the vision inspection system.
[0039] Preferably, the camera focal length, exposure time, and light source intensity can be adjusted according to the cigarette pack specifications by activating an industrial vision inspection system pre-installed on the production line. The system synchronizes with the production line speed via a trigger signal to ensure accurate image capture when the cigarette pack arrives at the inspection station. The camera resolution must meet the inspection accuracy requirements; typically, a high-resolution industrial camera combined with a ring light source is used to eliminate glare interference and highlight the edge features of the cigarette pack.
[0040] Step S22: Preprocess each cigarette pack image and locate the detection area in the preprocessed cigarette pack image based on the detection window coordinates in the mapping database.
[0041] Preferably, when the cigarette pack passes through the inspection station, the vision system automatically triggers image acquisition to obtain a complete image of the cigarette pack's surface. The acquired raw image needs to undergo quality verification to check for issues such as blurriness, overexposure, or occlusion. If the image quality is unsatisfactory, the system will re-trigger the acquisition process; if the quality meets the standards, it will proceed to subsequent processing steps to ensure the reliability of feature extraction.
[0042] Step S23: Based on the detection region, extract key point feature descriptors using the scale-invariant feature transformation algorithm, and construct a visual feature vector by weighted averaging of the directional gradient histogram features and local binary pattern texture features.
[0043] Preferably, within the pre-defined detection window area, the Scale Invariant Feature Transform (SIFT) algorithm is used to extract key point feature descriptors. Simultaneously, this is combined with Histogram of Oriented Gradients (HOG) features and Local Binary Pattern (LBP) texture features to construct a comprehensive visual feature vector. These feature vectors can comprehensively describe the visual characteristics of the cigarette pack surface, including key information such as edges, corners, and textures.
[0044] Step S24: Normalize the visual feature vector to obtain the visual feature identifier.
[0045] Preferably, the extracted multi-dimensional feature vectors are normalized to eliminate dimensional differences, and dimensionality reduction or completion operations are performed according to preset dimensionality requirements. Finally, standardized image feature identifiers are generated. These identifiers have the same dimensions and feature space structure as the baseline feature vectors stored in the database, providing a directly comparable data format for subsequent similarity matching.
[0046] Beneficial effects: Steps S21 to S24, through a systematic image acquisition and feature extraction process, provide a high-precision and reliable data foundation for classifying cigarette pack appearance defects. When a cigarette pack passes through the inspection station, the vision inspection system accurately triggers image acquisition, ensuring real-time acquisition of a complete image of the pack's surface. This synchronization mechanism effectively avoids image blurring or misalignment caused by high-speed movement on the production line. The acquired raw images undergo preprocessing, including grayscale conversion, histogram equalization, and Gaussian filtering, significantly improving image quality and eliminating uneven lighting and noise interference, creating ideal input conditions for subsequent feature extraction. Based on the detection window coordinates in the mapping database, the system can accurately locate the detection area of the cigarette pack image. This coordinate-driven positioning method ensures a strict correspondence between the detection window and the standard position, providing spatial consistency for defect identification. In the feature extraction stage, keypoint feature descriptors are extracted using the Scale Invariant Feature Transform (SIFT) algorithm. These descriptors are then combined with Histogram of Oriented Gradients (HOG) and Local Binary Pattern (LBP) texture features to construct a multi-dimensional visual feature vector. This multi-feature fusion strategy comprehensively captures the visual characteristics of the cigarette pack surface, including key information such as edges, corners, and textures, significantly improving the robustness and discriminative power of feature description. Finally, the feature vectors are normalized to generate standardized visual feature identifiers. This step eliminates the influence of vector magnitude differences, allowing the feature vectors to purely reflect directional similarity. This provides a standardized data format for subsequent cosine similarity calculations and nearest neighbor classification, enabling direct comparison. The entire process achieves efficient conversion from raw images to structured feature identifiers, providing accurate and stable front-end data support for the defect classification system.
[0047] Step S3: Calculate the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database.
[0048] Further, step S3, calculating the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database, includes: Step S31: Obtain visual feature vectors and extract all image feature vectors from the mapping database to form a baseline feature vector set.
[0049] Preferably, the real-time cigarette pack image visual feature vector generated in step S2 can be read from the system cache, and all pre-stored image feature identifiers can be extracted from the dynamic mapping database to form a baseline feature vector set. The two vector sets constitute the data basis for similarity calculation, where the real-time feature vector represents the visual characteristics of the currently detected cigarette pack, and the database feature set contains standard feature patterns for all known defect categories.
[0050] Step S32: Convert each image feature vector and each visual feature vector into unit vector form using the L2 norm. Based on an image feature vector and each visual feature vector, obtain an image feature unit vector and a visual feature unit vector respectively.
[0051] Preferably, the real-time feature vector and each baseline feature vector in the database are normalized separately. By calculating the L2 norm of each vector and dividing the vector by its norm, the feature vector is converted into a unit vector. This eliminates the influence of vector magnitude on similarity calculation, ensuring that subsequent calculations purely reflect similarity in the vector direction.
[0052] Step S33: Perform a dot product operation between the current visual feature unit vector and each image feature unit vector. Based on a visual feature unit vector, obtain several dot product results. Each dot product result is a cosine similarity.
[0053] Preferably, the normalized real-time feature vectors are sequentially multiplied by each normalized reference feature vector in the database using a dot product operation. The dot product calculation is achieved by multiplying the corresponding dimension values and then summing the results, yielding a series of dot product results. Each dot product result reflects the alignment degree between the real-time feature vector and the corresponding reference feature vector in the direction. Since the feature vectors have been normalized, all vectors are unit vectors, and their product of magnitudes is always 1. This characteristic simplifies the calculation process, allowing cosine similarity to be directly represented by the dot product results without the need for additional magnitude calculation steps.
[0054] Beneficial effects: Steps S31 to S33 establish a complete feature comparison data framework by acquiring real-time visual feature vectors and extracting the benchmark feature set from the mapping database, ensuring that subsequent calculations can cover all predefined defect patterns. This step structurally associates real-time detected features with the standard feature library, providing clear data objects for similarity analysis. Secondly, step S32 normalizes the feature vectors using the L2 norm, converting them into unit vectors by dividing the vector by its magnitude, effectively eliminating the influence of vector length on similarity calculations. This normalization process ensures that subsequent similarity calculations purely reflect the alignment of feature vectors in direction, avoiding misjudgments caused by differences in feature scale, and is particularly suitable for situations where there may be changes in illumination or fluctuations in local feature intensity in cigarette pack images. Finally, step S33 directly obtains the cosine similarity value through the unit vector dot product operation, utilizing the mathematical property (the dot product of two unit vectors equals the cosine of their included angle) to achieve efficient and accurate similarity measurement. These three steps together construct a rigorous feature matching process: from data preparation to standardization and then to mathematical calculation, ensuring that the system can accurately quantify the similarity between real-time cigarette pack features and standard defect templates. This calculation method is particularly crucial for identifying subtle defects on the surface of cigarette packs, because even very small feature deviations (such as edge offsets in hot stamping) can be sensitively captured through changes in the cosine similarity value, providing a high-resolution similarity index for subsequent defect classification decisions.
[0055] Step S4: Determine whether the cosine similarity is less than the preset similarity threshold. If so, proceed to step S5.
[0056] Preferably, in the cigarette pack appearance defect classification method of this embodiment, the cosine similarity threshold can typically be set in the range of 0.85-0.95. The threshold setting must also consider the actual operating conditions of the production line, including factors such as the cigarette pack moving speed, lighting conditions, and camera resolution. High-speed production lines typically require higher thresholds (0.90-0.95) to address dynamic blurring issues during image acquisition; while low-speed production lines can use relatively lower thresholds (0.85-0.90) to improve detection sensitivity. Different thresholds should be set for different defect categories. Critical process defects (such as "loose lid" or "missing side ears") require higher thresholds (≥0.92) to ensure strict control, while minor appearance defects can use standard thresholds (0.85-0.90). This refined configuration can significantly improve the practicality and efficiency of the classification system.
[0057] Preferably, a trial run can be conducted using 0.90 as the initial threshold, followed by precise adjustments based on the detection statistics (false positive rate, false negative rate) over a week. The classification performance under different thresholds is recorded to find the optimal threshold best suited for the current production line.
[0058] Step S5: The visual feature identifier is compared with the image feature identifier in the mapping database using the nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack.
[0059] Further, in step S5, the visual feature identifier is compared with the image feature identifier in the mapping database using a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack, including: Step S51: Obtain all cosine similarities less than the preset similarity threshold, and subtract each cosine similarity from 1 to convert it into a feature distance metric based on a cosine similarity.
[0060] Preferably, based on the cosine similarity calculation results determined in step S4 to exceed the preset similarity threshold, all data pairs that meet the conditions are selected to form a candidate feature set to be classified. This set contains matching pairs of real-time visual feature identifiers and image feature identifiers in the database, as well as the corresponding similarity values, providing input data for nearest neighbor classification.
[0061] The selected cosine similarity values are converted into feature distance metrics, and the distance matrix is calculated using the formula D=1-S, where D represents the feature distance and S represents the cosine similarity. This conversion ensures that higher similarity corresponds to smaller distances, which aligns with the basic principle of nearest neighbor classification algorithms: "the smaller the distance, the more similar the data."
[0062] Step S52: Based on each feature distance metric, find the corresponding image feature identifier in the mapping database, and select the image feature identifier with the smallest feature distance metric as the nearest neighbor.
[0063] Preferably, in the transformed feature distance matrix, the database image feature identifier with the smallest distance to the real-time visual feature identifier is found. By traversing all candidate feature pairs, the database feature identifier with the smallest feature distance value is identified; this identifier represents the known defect pattern most similar to the current cigarette pack image. Based on the found nearest neighbor database image feature identifier, the corresponding relationship stored in the dynamic mapping database is queried back to obtain the cigarette pack defect category number associated with this feature identifier. This step establishes a mapping connection from feature matching to specific defect categories.
[0064] Step S53: Query the defect type number stored in the mapping database based on the nearest neighbor image feature identifier to obtain the defect type number corresponding to the cigarette pack.
[0065] Beneficial effects: Steps S51 to S53 convert cosine similarity into a feature distance metric (step S51), establishing a mathematical expression more suited to classification requirements. The conversion of 1 minus cosine similarity not only preserves the information content of the original similarity but also constructs a rigorous distance metric space, enabling subsequent nearest neighbor search to operate based on a clear distance standard. This conversion ensures the mathematical rigor of feature comparison, laying a theoretical foundation for accurate classification. Secondly, the nearest neighbor search based on the feature distance metric (step S52) traverses all image feature labels in the mapping database, selecting the label with the smallest feature distance as the matching result. This method fully utilizes… The complete information in the database avoids coarse judgments based on a single threshold, effectively distinguishing similar but different defect patterns. Especially when dealing with multiple types of small-difference cigarette pack defects, the minimum distance principle significantly improves the discrimination and accuracy of classification. Finally, by querying the defect type number through nearest-neighbor image feature identifiers (step S53), a direct association between feature matching and specific defect types is established. This database-based query mechanism ensures the traceability and consistency of classification results. Each identified defect type number has a corresponding standard feature template as support, guaranteeing the reliability of the classification results and providing structured data support for quality analysis and process improvement. These three steps together constitute a complete classification decision-making closed loop. From mathematical transformation to feature matching to result output, each step is optimized for the specific needs of cigarette pack defect classification, ultimately achieving high-precision and interpretable defect identification.
[0066] Beneficial effects of steps S1 to S5: Steps S1 to S5 utilize the dynamic mapping database established in step S1 to standardize the association between cigarette pack defect type numbers, detection window coordinates, and image feature identifiers, providing a complete data foundation for subsequent classification. This database not only contains predefined process defect codes (such as "missing side ears" and "missing hot stamping"), but also stores the reference coordinates and dynamic offset parameters of the detection window, ensuring adaptability to the detection needs of cigarette packs of different specifications. Step S2 uses a vision inspection system to acquire cigarette pack images in real time and extract visual feature identifiers. A multi-dimensional feature vector is constructed using the Scale Invariant Feature Transform (SIFT) algorithm combined with Histogram of Oriented Gradients (HOG) and Local Binary Pattern (LBP) texture features, which can comprehensively capture the visual characteristics of the cigarette pack surface, including key information such as edges, corners, and textures. Step S... 3. Intelligent matching of real-time features and database features is achieved by calculating cosine similarity. L2 norm normalization is used to ensure the accuracy of vector comparison. The dot product operation directly reflects the directional consistency of feature vectors, providing a reliable similarity measure for defect identification. Step S4 introduces a similarity threshold judgment mechanism, forming an intelligent screening process. The classification process is only triggered when the similarity between real-time features and database features is lower than a preset threshold, effectively eliminating interference items and improving the system's decision-making efficiency. Step S5 uses the nearest neighbor classification algorithm to achieve accurate matching through feature distance measurement (1-cosine similarity). The minimum distance principle ensures the reliability of the classification results. The system can directly convert the feature matching results into specific defect type numbers based on the association relationships in the mapping database, realizing a fully automated process from image acquisition to defect identification. The synergistic effect of these five steps enables the cigarette pack appearance defect classification system to have high accuracy, real-time performance, and adaptability, meeting the quality inspection needs of assembly line production.
[0067] Further, in step S4, it is determined whether the cosine similarity is less than a preset similarity threshold. If so, step S5 is executed, followed by: Step S10: If not, determine whether there is a deviation between the real-time detection window coordinates and the detection window coordinates; if yes, proceed to step S20.
[0068] Preferably, the deviation can be set to be greater than 0.5 pixels to determine if there is a deviation.
[0069] Step S20: Calculate the offset of the current real-time detection window coordinates using equation (1): (1).
[0070] in, This is the offset. For calibration coefficients, The feature vector that identifies visual features. The feature vector that identifies the image features.
[0071] Preferably, the calibration coefficient K is typically between 0.1 and 1.0 under normal production conditions; the K value for fine detection can be set between 0.05 and 0.5; and the K value for high-sensitivity detection can reach 1.0 or higher.
[0072] Preferably, to determine the most suitable K value for the production line, start with an intermediate value (such as 0.5), observe the detection effect through testing, and fine-tune the K value according to the false detection rate and the missed detection rate to find the best balance point.
[0073] Step S30: Adjust the coordinates of the current real-time detection window using an adaptive window matching algorithm to eliminate the offset.
[0074] Preferably, the calculated offset ΔP is applied to the current detection window coordinates. If the original window coordinates are (X, Y), the adjusted new coordinates are (X + ΔX, Y + ΔY), thus achieving precise positioning of the detection window.
[0075] Preferably, the adjusted window position can also be verified to ensure that the window can completely cover the area to be detected. The system evaluates the adjustment effect by comparing the feature matching degree before and after the adjustment, and makes fine-tuning optimizations when necessary.
[0076] Step S40: Repeat steps S2 to S5 based on the adjusted detection window coordinates to identify the defect type number corresponding to the cigarette pack.
[0077] Beneficial effects: Steps S10 to S40, through a dynamic detection window coordinate adjustment mechanism, significantly improve the adaptability and detection accuracy of the cigarette pack appearance defect classification system. When the cosine similarity does not reach a preset threshold, the system can automatically identify the coordinate deviation between the real-time detection window and the standard window, and accurately calculate the offset using the formula ΔP=K×(F_current-F_base), where the calibration coefficient K ensures the accuracy of the offset calculation. Subsequently, an adaptive window matching algorithm is used to adjust the detection window coordinates in real time, effectively eliminating positioning deviations caused by differences in cigarette pack specifications or production line vibrations. This dynamic adjustment mechanism allows the system to automatically adapt to the detection needs of cigarette packs of different specifications without interrupting production, solving the limitations of traditional fixed window detection methods in multi-specification production scenarios. By re-executing the image acquisition and feature matching process after adjustment, the system significantly improves the accuracy of defect identification and reduces false detections and missed detections caused by inaccurate window positioning. In addition, this mechanism operates fully automatically, completing window calibration without manual intervention, greatly reducing production line downtime and manual adjustment costs, and improving overall production efficiency. Meanwhile, dynamic window adjustment enhances the system's robustness to fluctuations in the production line environment, effectively addressing complex situations such as cigarette pack position shifts and angle changes, ensuring stable detection performance even in high-speed assembly line environments. This adaptive detection window adjustment technology provides a more flexible and reliable solution for classifying cigarette pack appearance defects, and is particularly suitable for the modern flexible production needs of multi-variety, small-batch manufacturing.
[0078] Further, in step S5, the visual feature identifier is compared with the image feature identifier in the mapping database using a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack. Afterwards, the process includes: Step S100: Send the defect type number and visual feature identifier corresponding to the cigarette pack to the external visualization terminal.
[0079] Beneficial effects: Step S100 provides an interface for manual intervention, allowing staff to understand the classification process in real time and then proactively intervene based on actual needs or decisions.
[0080] See Figure 2 This embodiment provides an example of a device for classifying the appearance defects of cigarette packs, which is applied to the appearance defect classification method described in the above method embodiment.
[0081] Specifically, the appearance defect classification device includes a mapping database construction module 1, a visual feature identification extraction module 2, a cosine similarity calculation module 3, a cosine similarity judgment module 4, and a defect type number identification module 5, which are connected electrically or by signal in sequence.
[0082] The system comprises the following modules: a mapping database construction module 1, which constructs a mapping database based on pre-collected data, including cigarette pack defect type numbers, detection window coordinates, and image feature identifiers; a visual feature identifier extraction module 2, which collects cigarette pack images on the production line in real time through a visual inspection system and extracts the visual feature identifiers of the cigarette pack images; a cosine similarity calculation module 3, which calculates the cosine similarity between the visual feature identifier and each image feature identifier in the mapping database; a cosine similarity judgment module 4, which determines whether the cosine similarity is less than a preset similarity threshold; and a defect type number identification module 5, which, if the defect type is less than a preset threshold, compares the visual feature identifier with the image feature identifier in the mapping database using a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette pack.
[0083] Furthermore, the appearance defect classification device includes a detection window coordinate deviation judgment module, an offset calculation module, a real-time detection window coordinate adjustment module, and a repetitive execution module that are electrically or signal-connected in sequence; the detection window coordinate deviation judgment module is electrically or signal-connected to the cosine similarity judgment module 4, and the repetitive execution module is electrically or signal-connected to the visual feature identification extraction module 2.
[0084] The detection window coordinate deviation judgment module is used to determine whether there is a deviation between the real-time detection window coordinates and the detection window coordinates if the condition is not met.
[0085] The offset calculation module is used to calculate the offset of the current real-time detection window coordinates using equation (1) if the condition is met: (1).
[0086] in, This is the offset. For calibration coefficients, The feature vector that identifies visual features. The feature vector that identifies the image features.
[0087] The real-time detection window coordinate adjustment module is used to adjust the coordinates of the current real-time detection window through an adaptive window matching algorithm to eliminate offset.
[0088] The repeat execution module is used to repeatedly execute steps S2 to S5 based on the adjusted detection window coordinates to identify the defect type number corresponding to the cigarette pack.
[0089] Furthermore, the appearance defect classification device includes a data transmission module that is electrically or signalally connected to the repetitive execution module. This module is used to send the defect type number and visual feature identifier corresponding to the cigarette pack to an external visualization terminal.
[0090] Furthermore, the mapping database construction module 1 specifically includes a first mapping database construction unit, a second mapping database construction unit, a third mapping database construction unit, and a fourth mapping database construction unit that are electrically or signal-connected in sequence; the fourth mapping database construction unit is electrically or signal-connected to the visual feature identification extraction module 2.
[0091] The first mapping database construction unit is used to acquire several process defect image data of the production line and extract the image feature identifier of each process defect image data. The second mapping database construction unit is used to classify and encode all process defect image data and construct a defect type number mapping table based on the same encoding standard. The defect type number mapping table includes several cigarette pack defect type numbers. The third mapping database construction unit is used to acquire the detection window coordinates corresponding to each process defect image data. The fourth mapping database construction unit is used to associate and map the defect type number, detection window coordinates, and image feature identifier of the same process defect image data to obtain the mapping database.
[0092] Furthermore, the visual feature extraction module 2 specifically includes a first visual feature extraction unit, a second visual feature extraction unit, a third visual feature extraction unit, and a fourth visual feature extraction unit that are electrically or signal-connected in sequence; the first visual feature extraction unit is electrically or signal-connected to the fourth mapping database construction unit, and the fourth visual feature extraction unit is electrically or signal-connected to the cosine similarity calculation module 3.
[0093] The system comprises four main components: a first visual feature extraction unit, a second visual feature extraction unit, and a third visual feature extraction unit. The first visual feature extraction unit is used to collect images of cigarette packs on the production line in real time based on the visual inspection system when the cigarette packs pass through the inspection station. The second visual feature extraction unit is used to preprocess each cigarette pack image and locate the detection area in the preprocessed cigarette pack image based on the detection window coordinates in the mapping database. The third visual feature extraction unit is used to extract key point feature descriptors based on the detection area using the scale-invariant feature transformation algorithm and to construct a visual feature vector by weighted averaging of the directional gradient histogram features and local binary pattern texture features. The fourth visual feature extraction unit is used to normalize the visual feature vector to obtain the visual feature identifier.
[0094] Furthermore, the cosine similarity calculation module 3 specifically includes a first cosine similarity calculation unit, a second cosine similarity calculation unit, and a third cosine similarity calculation unit that are electrically or signal-connected in sequence; the first cosine similarity calculation unit is electrically or signal-connected to the fourth visual feature identification extraction unit, and the third cosine similarity calculation unit is electrically or signal-connected to the cosine similarity judgment module 4.
[0095] The first cosine similarity calculation unit is used to obtain visual feature vectors and extract all image feature vectors from the mapping database to form a set of baseline feature vectors. The second cosine similarity calculation unit is used to convert each image feature vector and each visual feature vector into a unit vector form using the L2 norm, and obtain an image feature unit vector and a visual feature unit vector based on an image feature vector and each visual feature vector. The third cosine similarity calculation unit is used to perform a dot product operation between the current visual feature unit vector and each image feature unit vector, and obtain several dot product results based on a visual feature unit vector. Each dot product result is a cosine similarity.
[0096] Furthermore, the defect type number identification module 5 specifically includes a first defect type number identification unit, a second defect type number identification unit, and a third defect type number identification unit that are electrically or signal-connected in sequence; the first defect type number identification unit is electrically or signal-connected to the cosine similarity judgment module 4.
[0097] The first defect type number identification unit is used to obtain all cosine similarities less than a preset similarity threshold, and convert each cosine similarity into a feature distance metric by subtracting 1 from each cosine similarity. The second defect type number identification unit is used to find the corresponding image feature identifier in the mapping database based on each feature distance metric, and select the image feature identifier with the smallest feature distance metric as the nearest neighbor. The third defect type number identification unit is used to query the defect type number stored in the mapping database based on the image feature identifier of the nearest neighbor to obtain the defect type number corresponding to the cigarette pack.
[0098] It should be noted that this embodiment is a functional module embodiment based on the above method embodiment. For the preferred, extended, limited, exemplified, and principle-explained parts of this embodiment, please refer to the above embodiments. This embodiment will not repeat them here.
[0099] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Figure 3 As shown, the electronic device 6 includes a processor 61 and a memory 62 coupled to the processor 61.
[0100] The memory 62 stores program instructions for implementing the federated learning-based collaborative energy-saving method for government data clusters in any of the above embodiments.
[0101] The processor 61 is used to execute program instructions stored in the memory 62 for collaborative energy saving of government data clusters based on federated learning.
[0102] The processor 61 can also be referred to as a CPU (Central Processing Unit). The processor 61 may be an integrated circuit chip with signal processing capabilities. The processor 61 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor.
[0103] Furthermore, Figure 4 This is a schematic diagram of the structure of a storage medium according to an embodiment of this application. See also: Figure 4 In this embodiment of the application, the storage medium 7 stores program instructions 71 capable of implementing all the above methods. These program instructions 71 can be stored in the storage medium in the form of a software product, including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods in each embodiment of the application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, or terminal devices such as computers, servers, mobile phones, and tablets.
[0104] In the several embodiments provided in this application, it should be understood that the disclosed systems, methods, and approaches can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between systems or units may be electrical, mechanical, signal, or other forms.
[0105] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units. The above are merely embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made based on the description and drawings of this application, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A method of classifying appearance defects of a tobacco pack, the method of classifying appearance defects being applied to a tobacco pack located on a flow line, characterized in that, The appearance defect classification method comprises: Step S1, constructing a mapping database comprising cigarette packet defect type numbers, detection window coordinates and image feature identifiers based on pre-acquired data; Step S2, acquiring cigarette packet images on a production line in real time through a visual detection system and extracting visual feature identifiers of the cigarette packet images; Step S3, calculating cosine similarity of the visual feature identifiers with each image feature identifier in the mapping database respectively; Step S4, judging whether the cosine similarity is less than a preset similarity threshold, and if so, executing Step S5; Step S5, comparing the visual feature identifiers with image feature identifiers in the mapping database through a nearest neighbor classification algorithm to identify a defect type number corresponding to the cigarette packet.
2. The appearance defect classification method according to claim 1, characterized by, Step S4, judging whether the cosine similarity is less than a preset similarity threshold, and if so, executing Step S5, and then comprising: Step S10, if not, judging whether there is deviation between real-time detection window coordinates and the detection window coordinates, and if so, executing Step S20; Step S20, calculating an offset of the current real-time detection window coordinates through formula (1): (1); wherein, is the offset, is the calibration factor, is a feature vector of the visual feature identifier, is a feature vector of the image feature identifier; Step S30, adjusting the current real-time detection window coordinates through an adaptive window matching algorithm to eliminate the offset; Step S40, repeatedly executing Steps S2 to S5 based on the adjusted detection window coordinates to identify the defect type number corresponding to the cigarette packet.
3. The appearance defect classification method according to claim 1, characterized by, Step S5, comparing the visual feature identifiers with image feature identifiers in the mapping database through a nearest neighbor classification algorithm to identify a defect type number corresponding to the cigarette packet, and then comprising: Step S100, sending the defect type number corresponding to the cigarette packet and the visual feature identifier to an external visual terminal.
4. The appearance defect classification method according to claim 1, characterized by, Step S1, constructing a mapping database comprising cigarette packet defect type numbers, detection window coordinates and image feature identifiers based on pre-acquired data, comprising: Step S11, acquiring a plurality of process defect image data of the production line and extracting image feature identifiers of each process defect image data respectively; Step S12, classifying and coding all process defect image data and constructing a defect type number mapping table based on a same coding standard, the defect type number mapping table comprising a plurality of cigarette packet defect type numbers; Step S13, acquiring detection window coordinates corresponding to each process defect image data respectively; Step S14, associating and mapping defect type numbers, detection window coordinates and image feature identifiers of a same process defect image data to obtain the mapping database.
5. The appearance defect classification method according to claim 1, characterized by, Step S2, acquiring cigarette packet images on a production line in real time through a visual detection system and extracting visual feature identifiers of the cigarette packet images, comprising: Step S21, acquiring cigarette packet images on a production line in real time based on the visual detection system when the cigarette packets pass through a detection station of the production line; Step S22, pre-processing each cigarette packet image respectively and locating a detection area in the pre-processed cigarette packet image based on the detection window coordinates in the mapping database; Step S23, extracting key point feature descriptors based on the detection area through a scale-invariant feature transform algorithm, and constructing a visual feature vector according to weighted average of a histogram of oriented gradients feature and a local binary pattern texture feature; Step S24, performing normalization processing on the visual feature vector to obtain the visual feature identifier.
6. The appearance defect classification method according to claim 5, characterized by, Step S3, calculating cosine similarities of the visual feature identifier with each image feature identifier in the mapping database, including: Step S31, obtaining the visual feature vector and extracting all image feature vectors from the mapping database to form a reference feature vector set; Step S32, converting each image feature vector and each visual feature vector into a unit vector form through an L2 norm, respectively obtaining an image feature unit vector and a visual feature unit vector based on one image feature vector and one visual feature vector; Step S33, performing dot product operations on the current visual feature unit vector and each image feature unit vector, respectively, obtaining a plurality of dot product results based on one visual feature unit vector, and one dot product result being one cosine similarity.
7. The appearance defect classification method according to claim 1, characterized by, Step S5, comparing the visual feature identifier with the image feature identifiers in the mapping database through a nearest neighbor classification algorithm to identify the defect type number corresponding to the cigarette packet, including: Step S51, obtaining all cosine similarities less than the preset similarity threshold, and converting one cosine similarity into one feature distance measure by subtracting one from each cosine similarity, respectively; Step S52, finding corresponding image feature identifiers in the mapping database based on each feature distance measure, and selecting an image feature identifier with the smallest feature distance measure as the nearest neighbor; Step S53, querying the defect type number stored in the mapping database according to the image feature identifier of the nearest neighbor to obtain the defect type number corresponding to the cigarette packet.
8. A cigarette packet appearance defect classification device applied to the appearance defect classification method according to any one of claims 1 to 7, characterized by, The appearance defect classification device includes: A mapping database construction module configured to construct a mapping database including a cigarette packet defect type number, a detection window coordinate, and an image feature identifier based on pre-acquired data; A visual feature identifier extraction module configured to acquire cigarette packet images on a production line in real time through a visual detection system and extract visual feature identifiers of the cigarette packet images; A cosine similarity calculation module configured to calculate cosine similarities of the visual feature identifier with each image feature identifier in the mapping database; A cosine similarity judgment module configured to judge whether the cosine similarity is less than a preset similarity threshold; A defect type number identification module configured to, if yes, compare the visual feature identifier with the image feature identifiers in the mapping database through a nearest neighbor classification algorithm to identify a defect type number corresponding to the cigarette packet.
9. An electronic device, comprising: A processor and a memory coupled to the processor, the memory storing program instructions executable by the processor; the processor executes the program instructions stored in the memory to implement the appearance defect classification method in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores program instructions, and the program instructions are executed by the processor to implement the appearance defect classification method in any one of claims 1 to 7.