Multi-specification card image recognition and packaging parameter self-adaption method and system
By constructing a specification feature library and decomposing detection parameters, and combining metric learning and few-sample fine-tuning, rapid production changeover and high-precision detection in multi-specification playing card production were achieved. This solved the problems of long parameter adjustment time and poor adaptability in existing systems for multi-specification playing card production, and improved production efficiency and detection accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG WANGJING CARD TECH CO LTD
- Filing Date
- 2026-01-26
- Publication Date
- 2026-05-05
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing visual inspection systems are time-consuming to adjust parameters during production changes in multi-specification playing card manufacturing, have poor adaptability, cannot quickly adapt to multi-variety, small-batch production, and their inspection accuracy is difficult to meet high-quality requirements.
A specification feature library is constructed, and a specification classification network based on metric learning is used for rapid specification identification. The detection parameters are decomposed into specification-independent, specification-related, and batch-related levels, which are then fused through a multi-granularity parameter inheritance mechanism. A few-sample fine-tuning strategy and an online continuous learning module are used to optimize the parameters to achieve autonomous adaptation.
It enables rapid changeover for multiple playing cards, shortening changeover time to within 2 minutes. New specifications can be entered with only 5 sample images, and the specification recognition accuracy reaches 99.9%, significantly improving production efficiency and detection accuracy.
Smart Images

Figure CN121982402A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision inspection technology, specifically to a method and system for multi-size playing card image recognition and packaging parameter adaptation. Background Technology
[0002] In the modern playing card manufacturing industry, visual inspection systems have become a crucial link in ensuring product quality. With the diversification of market demands, playing card manufacturers need to simultaneously produce various specifications of products, including playing cards, tarot cards, trading cards, and board game cards. These products differ significantly in geometric dimensions, printing features, and material properties. However, existing visual inspection systems face serious adaptability issues when dealing with multi-variety, small-batch production models.
[0003] Chinese patent CN118762243A discloses a machine vision detection method and system based on feature calibration. This method dynamically acquires continuous image sequences of the object to be detected, performs scale transformation on the image sequences to generate a multi-level resolution image pyramid, extracts features from the image pyramid levels and performs real-time calibration, identifies the category and changes of features by comparing them with a pre-set dynamic feature template library, and finally uses an adaptive decision algorithm to adjust the detection strategy. While this technical solution achieves a certain degree of environmental adaptability, its feature template library update mechanism relies on passive learning, requiring gradual accumulation of samples and manual adjustment during the detection process, making it unable to achieve proactive adaptation in rapid production change scenarios. Furthermore, the support vector machine classifier used in this solution requires sufficient training samples to achieve ideal classification results, which contradicts the reality of sample scarcity in multi-variety, small-batch production.
[0004] In real-world production environments, when a playing card production line needs to switch from one specification to another, existing vision inspection systems typically require manual recalibration of camera parameters, manual adjustment of inspection area boundaries, and replacement or retraining of template images. This process often takes 20 to 30 minutes, severely restricting production efficiency. This is especially true for high-end products such as collectible cards and customized board games, where single-batch production may only involve a few hundred to a few thousand cards. The excessively high proportion of changeover time in total production time leads to low equipment utilization and increased production costs.
[0005] Furthermore, when new specifications of playing cards emerge, existing systems require the collection of a large number of sample images for model training. This not only prolongs the product launch cycle but also increases the workload of technical personnel. Some companies have attempted to adopt universal detection parameters to reduce adjustments during product changes, but this approach often leads to a decrease in detection accuracy, failing to meet the detection requirements of high-quality products.
[0006] Therefore, there is an urgent need for an intelligent detection method that can quickly adapt to various playing card specifications, support the input of new specifications under conditions of few samples, and have the ability to continuously learn online, in order to solve the problem of rapid production changeover in the production of multiple varieties of small batches of playing cards. Summary of the Invention
[0007] To address the technical problems of long parameter adjustment time and poor adaptability of existing visual inspection systems when changing production of multi-specification playing card products, this invention provides a method and system for multi-specification playing card image recognition and packaging parameter adaptation.
[0008] The first aspect of this invention provides a method for multi-size playing card image recognition and packaging parameter adaptation, comprising the following steps: Step S1: Construct a specification feature library by structurally encoding and storing the geometric parameters, printing features, and material properties of various specifications of playing cards to form a specification feature knowledge base. Step S2: When the playing card enters the inspection station, the specifications of the acquired image are identified through the specification classification network, the specification embedding vector of the current playing card is extracted, and its specification category is determined in the specification embedding space based on metric learning. Step S3: Based on the identified specification category, retrieve the corresponding parameter template from the specification feature library, decompose the detection parameters into three levels: specification-independent layer parameters, specification-related layer parameters, and batch-related layer parameters, and perform parameter fusion through a multi-granularity parameter inheritance mechanism; Step S4: A few-sample fine-tuning strategy is used to perform batch-level optimization and adaptation of the fused parameters, and the gradient of the batch-related layer parameters is updated using a small number of sample images of the current batch. Step S5: During normal detection, start the online continuous learning module to continuously collect boundary samples near the decision boundary and optimize the classifier decision boundary in an unsupervised manner. Step S6: Calculate the feature distance between the specification embedding vector of the current input image and all known specification prototype vectors. When all distances exceed the preset feature distance threshold, trigger the abnormal specification warning mechanism and support one-click input of new specifications.
[0009] A second aspect of the present invention provides a multi-size playing card image recognition and packaging parameter adaptive system, comprising: The specification feature library construction module is used to structurally encode and store the geometric parameters, printing features and material properties of various sizes of playing cards, forming a specification feature knowledge base; The specification recognition module is used to identify the specifications of the captured image through a specification classification network when the playing card enters the inspection station, extract the specification embedding vector of the current playing card, and determine its specification category in the specification embedding space based on metric learning. The parameter retrieval and fusion module is used to retrieve the corresponding parameter template from the specification feature library based on the identified specification category. It decomposes the detection parameters into three levels: specification-independent layer parameters, specification-related layer parameters, and batch-related layer parameters, and performs parameter fusion through a multi-granularity parameter inheritance mechanism. The few-shot fine-tuning module is used to perform batch-level optimization and adaptation of the fused parameters using a few-shot fine-tuning strategy, and to update the gradient of the batch-related layer parameters using a small number of sample images of the current batch. The online continuous learning module is used to continuously collect boundary samples located near the decision boundary during normal detection, and to optimize the classifier decision boundary in an unsupervised manner. The abnormal specification warning module is used to calculate the feature distance between the specification embedding vector of the current input image and all known specification prototype vectors. When all distances exceed the preset feature distance threshold, the abnormal specification warning mechanism is triggered and one-click input of new specifications is supported.
[0010] The beneficial effects of this invention are as follows: By constructing a specification embedding space based on metric learning, different specifications of playing cards are mapped to a high-dimensional feature space to form a clustered distribution, allowing new specifications to be located in the embedding space with only a small number of samples; through a multi-granularity parameter inheritance mechanism, incremental adaptation of detection parameters is achieved, significantly shortening the changeover time; and through an online continuous learning module, the detection system's autonomous optimization capability is realized. This invention supports automatic recognition of playing cards of any specification within the range of 54mm×86mm to 89mm×127mm, with the changeover parameter adaptation time shortened to less than 2 minutes, new specifications requiring only 5 sample images for input, and a specification recognition accuracy rate of 99.9%. Attached Figure Description
[0011] Figure 1 This is a flowchart of the multi-specification playing card image recognition and packaging parameter adaptive method according to an embodiment of the present invention; Figure 2 This is a system architecture diagram of multi-specification playing card image recognition and packaging parameter adaptive system according to an embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. It should be noted that, unless otherwise defined, the terms and technical features involved in the present invention should be understood in their ordinary sense by those skilled in the art.
[0013] like Figure 1As shown, this invention provides a method for multi-specification playing card image recognition and packaging parameter adaptation. This method constructs a multi-level adaptive detection architecture to achieve automatic configuration of detection parameters in rapid changeover scenarios on playing card production lines. In one embodiment of this invention, the method includes the following six core steps, each forming a deeply coupled closed-loop collaborative relationship.
[0014] Step S1: Construction of the specification feature library.
[0015] The core objective of step S1 is to establish a structured knowledge base for playing card specifications, providing a data foundation for subsequent specification identification and parameter retrieval. Preferably, this invention encodes and stores playing card specification features in three dimensions: geometric parameters, printing features, and material properties.
[0016] In terms of geometric parameters, this invention standardizes and encodes the size information of playing cards. Specifically, the system records the length, width, and thickness parameters of each size of playing card. Taking common playing card sizes as an example, the size of a standard playing card is 63mm × 88mm, and the thickness is approximately 0.32mm; the typical size of a tarot card is 70mm × 120mm, and the thickness is approximately 0.35mm; trading cards such as Magic: The Gathering are 63mm × 88mm in size, but due to the use of different cardstock materials, their thickness is approximately 0.30mm; while board game cards cover a wider range of sizes, from mini cards of 44mm × 67mm to large cards of 89mm × 127mm. In one embodiment of this invention, the system normalizes these geometric parameters, mapping the length and width to the [0,1] interval, with the normalization benchmark selected as the maximum supported size of 89mm × 127mm, and the thickness using a Z-score normalization method centered at 0.30mm with a standard deviation of 0.10mm.
[0017] In terms of printing features, this invention constructs a multi-level feature description system. First, regarding color space distribution features, the system uses the HSV color space to statistically analyze the color distribution of the card's front pattern, extracting parameters such as the peak position of the hue histogram, the mean saturation, and the dynamic range of brightness. Preferably, the hue histogram is quantized using 36 bins, each covering a 10-degree hue range, thus forming a 36-dimensional color distribution vector. Second, regarding printing accuracy features, the system records the nominal printing resolution of each card size, typically in dpi, and extracts parameters such as edge sharpness index and color registration error tolerance. In one embodiment of this invention, the edge sharpness index is characterized by the average gradient magnitude calculated using the Sobel operator, typically ranging from 50 to 200. Third, regarding pattern complexity features, the system uses image entropy and fractal dimension to describe the complexity of the card pattern. Image entropy is calculated based on the grayscale histogram, and the fractal dimension is estimated using box counting.
[0018] In terms of material properties, this invention primarily focuses on optical characteristics related to visual inspection. These characteristics include surface gloss, reflectance curves, and transmittance parameters. Surface gloss is characterized using specular reflectance at a 60-degree angle. The gloss levels of playing cards vary significantly depending on the material: ordinary paper playing cards typically have a gloss level in the range of 20 to 40 GU, while coated collectible cards can reach 60 to 80 GU. The reflectance curve describes the reflectivity of the card surface at different incident angles. This invention uses reflectance values at four typical angles—0 degrees, 30 degrees, 45 degrees, and 60 degrees—to construct a 4-dimensional reflectance vector. The transmittance parameter characterizes the card's light-blocking performance; this parameter is crucial for detecting the presence of bleed-through defects in the card.
[0019] Preferably, the feature parameters of the above three dimensions are concatenated to form a complete feature descriptor for each size of playing card. In one embodiment of the present invention, the geometric parameter dimension contributes 3-dimensional features, the printing feature dimension contributes 64-dimensional features, and the material attribute dimension contributes 5-dimensional features, forming a total of 72-dimensional specification feature vector. The system pre-stores 15 to 20 common playing card sizes, forming the initial knowledge base of the specification feature library.
[0020] Step S2: Specification identification and embedding space mapping.
[0021] Step S2 is one of the core innovative aspects of this invention. By designing a specification classification network based on metric learning, it achieves rapid specification recognition of the input playing card image. Unlike traditional classification networks, the specification classification network used in this invention does not directly output the category probability distribution. Instead, it maps the input image to a high-dimensional embedding space, where it performs classification decisions based on distance metrics.
[0022] In one embodiment of the present invention, the specification classification network employs a lightweight convolutional neural network architecture. The backbone of the network comprises four convolutional blocks, each consisting of a 3×3 convolutional layer, a batch normalization layer, and a ReLU activation function. The convolutional blocks are downsampled through 2×2 max pooling layers. Preferably, the output channels of the four convolutional blocks are set to 64, 128, 256, and 512, respectively. This increasing channel number design allows the network to extract visual features from low to high levels layer by layer. A global average pooling layer follows the backbone network, compressing the spatial dimension to 1×1. Subsequently, two fully connected layers map the feature dimensions to 256-dimensional embedding vectors. The first fully connected layer maps the 512-dimensional input to a 512-dimensional intermediate representation and applies ReLU activation. The second fully connected layer maps the 512-dimensional intermediate representation to a 256-dimensional embedding output and applies L2 normalization, ensuring that all embedding vectors lie on a unit hypersphere.
[0023] This invention introduces a metric learning training strategy to optimize the structure of the embedding space. Specifically, the system adopts a prototype network-based training paradigm, defining the prototype vector for each specification as the mean center of the embedding vectors of all training samples for that specification. Let the set of specification categories be... ,in Given the total number of known specifications, each specification The corresponding training sample set is Then the first Prototype vector of class specification Calculate as follows: , in: For the first The prototype vector of the class specification, with a dimension of 256, represents the center position of the specification in the embedding space; For the first The number of training samples for each class is typically between 50 and 500. For the first Class Specifications There are 124×224 pixel training sample images; For parameters The specification classification network maps the input image into a 256-dimensional embedding vector. It includes all learnable parameters in the network, with a total of approximately 2.5M parameters.
[0024] During training, this invention employs a contrastive learning loss function to optimize the geometry of the embedding space, ensuring that samples of the same size cluster together while samples of different sizes are spaced further apart. Preferably, this invention uses an improved triplet loss function: , in: The value of the triplet loss function is within the range of... Ideally, the value should approach 0. The technical effect of this loss function is to make the distance between samples of the same class smaller than the distance between samples of different classes. To maximize training efficiency within the GPU memory limit, the number of triples in the training batch is set to 64 in this embodiment. For the first An anchor sample embedding vector of a triplet, that is, a 256-dimensional embedding representation of a randomly selected training sample; For the first The positive sample embedding vector of a triplet, that is, the embedding representation of another sample that belongs to the same specification category as the anchor sample; For the first The negative sample embedding vector of a triple, that is, the embedding representation of a sample that belongs to a different specification category than the anchor sample; The Euclidean distance function is calculated using the following formula: ; The interval boundary parameter is set to 0.5 in this embodiment to ensure that there is a sufficient distance between positive and negative samples. The selection of this parameter is based on the premise that the inter-class distance is at least 1.5 times the intra-class distance, thereby ensuring the robustness of classification.
[0025] In the actual reasoning stage, when an image of a playing card enters the inspection station, the system first acquires its image data through the image acquisition module. Preferably, the image acquisition module uses an automatic zoom industrial camera, which presets the initial working distance and optical magnification based on the specification information of the previous batch. In one embodiment of the invention, the working distance of the camera can be adjusted within the range of 100mm to 300mm, and the optical magnification can be adjusted within the range of 0.5× to 2.0× to accommodate the size differences of playing cards of different specifications. After preprocessing, the acquired image is input into the specification classification network to obtain a 256-dimensional specification embedding vector. .
[0026] Specification category determination is based on distance calculation between the embedding vector and the prototype vectors of each specification. The system employs a softmax-based similarity scoring mechanism. , in: The input sample belongs to the specification category The posterior probability, with a value range of . The sum of the probabilities of all categories is 1, and the category with the highest probability is the prediction result; This is the embedding vector of the current input sample, with a dimension of 256; For the first The prototype vector of the class specification is calculated during the training phase and stored in the specification feature library; For the first The prototype vector of the class specification; It is the Euclidean distance function; The temperature coefficient is used to control the sharpness of the probability distribution. In this embodiment, it is set to 0.2. A smaller temperature coefficient makes the probability distribution more concentrated in the nearest neighbor class, thereby improving the certainty of the classification decision. The selection range of this parameter is usually from 0.1 to 1.0. Given the total number of known specification categories, this embodiment supports a maximum of 50 specifications. The final specification determination result is the category with the highest probability. .
[0027] Step S3: Inheritance and fusion of multi-granularity parameters.
[0028] Step S3 is the core technical mechanism of this invention for achieving rapid changeover. Traditional visual inspection systems require reconfiguration of all inspection parameters when switching product specifications, which is the main reason for excessively long changeover times. This invention decomposes the inspection parameters into three levels, achieving incremental parameter adaptation and significantly shortening the parameter configuration time.
[0029] This invention divides the parameter system of the detection system into three levels: a specification-independent layer, a specification-dependent layer, and a batch-dependent layer. Specification-independent layer parameters... This refers to parameters that are independent of specific playing card specifications and are only related to the detection hardware and environmental conditions. These parameters include light source intensity, camera gain, exposure time reference value, and image sensor bias correction parameters. In one embodiment of the present invention, the light source intensity is controlled by an 8-bit digital value ranging from 0 to 255, the camera gain ranges from 0 dB to 24 dB, and the exposure time reference value ranges from 100 μs to 10000 μs. Specification-independent layer parameters are typically determined during initial system installation and commissioning, remain stable during normal production, and only require recalibration when the detection environment changes significantly.
[0030] Specification-related layer parameters These parameters are closely related to specific playing card specifications but remain consistent across different production batches of the same specification. These parameters include the region of interest (ROI) segmentation scheme, the threshold setting for the edge detection algorithm, the color space mapping matrix, and the similarity tolerance for template matching. In one embodiment of this invention, the ROI segmentation uses relative coordinates, with the top-left corner of the playing card as the origin and the length and width of the playing card as the normalization benchmark, dividing the detection area into multiple sub-regions such as the main image region, the border region, and the corner mark region. The edge detection threshold uses a dual-threshold Canny operator, with a low threshold range of 20 to 60 and a high threshold range of 60 to 180. The optimal threshold setting varies for different playing card specifications due to differences in printing precision and pattern complexity. The color space mapping matrix is used to convert the RGB images captured by the camera to a standard color space to eliminate potential color differences between different batches of playing cards; the mapping matrix is a 3×3 transformation matrix. Specification-related layer parameters are stored in a specification feature library, with each specification corresponding to a set of parameter templates.
[0031] Batch-related layer parameters These are parameters that need to be fine-tuned for each production batch. These parameters include the template reference image for the current batch of playing cards, the sensitivity coefficient for defect detection, and the color difference tolerance range for a specific batch. In one embodiment of the invention, the template reference image is selected from the first five qualified samples of the current batch, and its characteristic mean is used as the reference. The defect detection sensitivity coefficient ranges from 0.5 to 2.0, with a higher coefficient indicating more stringent detection. The color difference tolerance range is calculated using the ΔE*ab color difference formula and is typically set to 2.0 to 6.0 units, with the specific value determined based on product quality requirements. Batch-related layer parameters are updated online using a few-sample fine-tuning strategy.
[0032] The core of the multi-granularity parameter inheritance mechanism lies in achieving the orderly fusion of three levels of parameters. When the system identifies the specification category of the current batch... Then, the specification-related layer parameter template corresponding to the specification is first retrieved from the specification feature library. Then, the system fuses the specification-independent layer parameters, specification-dependent layer parameters, and initialized batch-dependent layer parameters to form a complete detection parameter configuration. Parameter fusion adopts a layered overlay strategy: , in: This is the final detection parameter vector, containing all the configurable parameters required by the detection system, with a dimension of approximately 200; This is a specification-independent layer parameter vector with a dimension of approximately 20, containing basic hardware-related configurations. Specifications The corresponding specification-related layer parameter vector has a dimension of approximately 100 and includes the detection area and algorithm parameters for that specification. This is the initialization vector for batch-related layer parameters, derived from specification-related layer parameters, with a dimension of approximately 80. The fusion weights of the three-layer parameters satisfy... The constraints are set as follows in this embodiment: This weighting reflects the contribution of different level parameters to the detection effect. The specification-related layer parameters have the highest proportion because they directly determine the core logic of the detection algorithm. This is a parameter fusion operator. For parameters in the same functional position, a weighted average or selective overlay strategy is used, while for non-overlapping parameters, a direct concatenation strategy is used.
[0033] In one embodiment of the present invention, the specific implementation of parameter fusion varies depending on the parameter type. For numerical parameters, a weighted average method is used for fusion; for range-type parameters, an inheritance-fine-tuning method is used, that is, based on specification-related layer parameters, batch-related layer parameters are allowed to be adjusted within a certain range; for enumerated parameters, the settings of specification-related layer parameters are prioritized, and switching is only performed when batch-level verification fails. The technical advantage of this type-specific fusion strategy is that it provides sufficient flexibility while ensuring parameter stability.
[0034] Step S4: Few-sample fine-tuning strategy.
[0035] Step S4 is a key technical step in achieving batch-level parameter adaptation. Even for playing card products of the same specifications, there may be subtle differences between different production batches, such as color deviations caused by ink batches or thickness fluctuations caused by paper batches. This invention uses a few-sample fine-tuning strategy to quickly optimize batch-related layer parameters using a small number of sample images of the current batch.
[0036] In one embodiment of this invention, the few-shot fine-tuning strategy is implemented based on a model-independent meta-learning framework. The core idea of this strategy is to learn a set of initialization parameters sensitive to new tasks, enabling the model to quickly adapt to new tasks through a small number of gradient update steps. In the application scenario of this invention, each production batch is considered a new task, and the batch-related layer parameters... It is considered a subset of parameters that require rapid adaptation.
[0037] The input for few-sample fine-tuning is the support set samples of the current batch. Preferably, after the system starts at the detection station, it automatically acquires the first 5 playing card images as the support set. ,in For the first The sample images have a resolution of 224×224 pixels. The corresponding annotation information is provided. In practical applications, these 5 sample images are usually quickly visually inspected and annotated manually, or pre-annotated using the previous batch of detection models and then manually reviewed and confirmed. The selection of the number of support set samples is based on striking a balance between annotation cost and fine-tuning effect. Experiments show that 5 samples can usually achieve a fit of over 95%.
[0038] The optimization objective of few-sample fine-tuning is to minimize the loss function on the support set. This invention employs a combined loss function, considering both detection accuracy and parameter stability: , in: The total loss function value for the fine-tuning process, with a range of values of [value missing]. The optimization objective is to minimize it; Batch-related layer parameters In support set The detection loss includes a weighted sum of multiple components such as positioning error and classification error. This loss reflects the degree to which the parameter configuration is adapted to the detection task. This is the current batch-related layer parameter vector, with a dimension of approximately 80; The initialization vector for the batch-related layer parameters is obtained by parameter fusion in step S3; The regularization coefficient is used to control the magnitude of parameter offset. In this embodiment, it is set to 0.01. The basis for selecting this coefficient is to keep the parameter offset within 10% of the initial value, thereby avoiding overfitting. The sum of squares of the parameter offsets is calculated using the square of the L2 norm, which has the effect of imposing a stronger penalty on large offsets.
[0039] Parameter updates are performed using the gradient descent optimizer, with the following specific update rules: ,in The learning rate is set to 0.001 in this embodiment. This learning rate is selected based on the premise that convergence is achieved after 10 to 20 iterations with 5 samples. For about The gradient operator is calculated using the backpropagation algorithm.
[0040] Preferably, to further improve the efficiency and stability of few-sample fine-tuning, this invention introduces an adaptive learning rate adjustment strategy. Specifically, the system monitors the changing trend of the loss function value. When the loss decreases by less than 1% for three consecutive iterations, the learning rate is reduced to 0.5 times its original value. When the loss increases, the parameters are rolled back to the previous effective state, and the learning rate is reduced to 0.1 times its original value. The fine-tuning process stops when any of the following termination conditions are met: the number of iterations reaches the maximum value of 20, the loss function value is lower than the preset threshold of 0.01, or the loss change is less than 0.1% for five consecutive iterations. The technical effect of this adaptive strategy is to automatically balance convergence speed and optimization accuracy.
[0041] In one embodiment of the present invention, the entire few-sample fine-tuning process can be completed within 30 seconds on an industrial control computer equipped with an NVIDIA RTX 3060 graphics card. Combined with the specification identification in step S2 (approximately 2 seconds) and the parameter retrieval in step S3 (approximately 5 seconds), the overall production change parameter configuration time is controlled within 2 minutes, which is an order of magnitude improvement compared to the traditional solution of 20 to 30 minutes.
[0042] Step S5: Online Continuous Learning Module.
[0043] Step S5 is the core mechanism by which the detection system achieves continuous self-optimization in this invention. In actual production environments, even after fine-tuning with a small number of samples, the parameter configuration of the detection system may not be optimal. Furthermore, as production continues, product characteristics may slowly drift, requiring the detection system to have adaptive adjustment capabilities. This invention optimizes the classifier decision boundary unsupervised during normal detection through an online continuous learning module.
[0044] In one embodiment of the present invention, the core of the online continuous learning module is a boundary sample identification and collection mechanism. The system classifies each sample during the detection process into three categories based on its detection confidence: high-confidence normal samples, high-confidence abnormal samples, and boundary samples. Boundary samples refer to those samples whose detection confidence falls within the middle region; they are located near the normal-abnormal classification decision boundary and are of significant value for optimizing the classifier boundary.
[0045] Boundary sample identification is based on a threshold determination of detection confidence. Assume the detection model evaluates the input samples... The output normal class probability is Then the criteria for identifying boundary samples are: ,in To determine the sample for the detection model The probability of the normal class, with a value range of 1. This is generated by the softmax output layer of the detection network; The lower threshold for the boundary region is set to 0.3 in this embodiment, indicating that samples with a probability lower than this value are judged as high-confidence anomalous samples; The upper threshold for the boundary region is set to 0.7 in this embodiment, indicating that samples with a probability higher than this value are judged as high-confidence normal samples; samples falling within this value are considered normal samples. Samples within the specified interval are identified as boundary samples. The threshold is selected based on historical data statistics, and the boundary interval should cover approximately 10% to 20% of the samples to ensure sufficient learning data.
[0046] The system maintains a boundary sample buffer. This buffer is used to store boundary samples collected online. It employs a first-in, first-out (FIFO) strategy and has a maximum capacity of 100 samples. When the number of samples in the buffer accumulates to a certain threshold, a decision boundary optimization update is triggered; in this embodiment, this threshold is set to 50 samples.
[0047] The optimization of the decision boundary employs an unsupervised contrastive learning strategy. The core idea is to use high-confidence samples as anchor points, and through contrastive learning, to narrow the distance between boundary samples and anchor points of the same class, while widening the distance between them and anchor points of different classes, thereby refining the decision boundary. Specifically, the system randomly selects samples from a high-confidence normal sample pool. Positive anchor points Randomly selected from the high-confidence outlier sample pool Negative anchor points In this embodiment .
[0048] For each boundary sample The system calculates the feature distance between the target and the positive / negative anchor points, and generates pseudo-labels based on the distance relationship: , in: For boundary samples pseudo-tags This indicates that the sample is considered normal. This indicates that the sample is an anomalous. For boundary samples The average feature distance to all positive anchor points is calculated using the following formula: ,in For feature extraction networks, It is the Euclidean distance function; For boundary samples The calculation formula is similar to that for the average feature distance of all negative class anchor points. The technical effect of this pseudo-label generation strategy is to provide soft supervision signals for boundary samples by utilizing the clustering characteristics of high-confidence samples.
[0049] After obtaining pseudo-labels for the boundary samples, the system uses these pseudo-labeled boundary samples to fine-tune and update the decision boundary of the detection model. The update uses the cross-entropy loss function: , in: The loss function value is optimized for the boundary conditions, and its range is [value missing]. This loss function drives the model to output predictions consistent with the pseudo-labels; This represents the number of samples in the current boundary sample buffer, with a value ranging from 1 to 100. For boundary samples pseudo-tags; To determine boundary samples for the detection model The probability of being in the normal class.
[0050] Preferably, to prevent catastrophic forgetting during continuous online learning, this invention introduces an experience replay mechanism. The system additionally maintains a core sample database. It stores representative samples from each category, with a capacity of 200. During each boundary optimization update, samples from the core sample library are mixed with boundary samples for training, and the loss function is adjusted as follows: ,in In this embodiment, the replay loss weight is set to 0.5. This coefficient is chosen to balance the learning of new knowledge with the retention of old knowledge. The technical effect of the experience replay mechanism is to maintain the model's ability to recognize historical samples during continuous learning.
[0051] Step S6: Abnormal specification warning and new specification entry.
[0052] Step S6 is the key mechanism by which this invention achieves the system's self-expansion capability. In actual production environments, new specifications of playing cards that are not included in the specification feature library may appear. This invention, through an abnormal specification early warning mechanism, can automatically detect the occurrence of unknown specifications and support one-click entry of new specifications, thereby realizing the dynamic expansion of the specification feature library.
[0053] Abnormal specification detection is based on feature distance determination in the embedding space. When the minimum distance between the specification embedding vector of the input image and all known specification prototype vectors exceeds a preset threshold, the system determines that the image belongs to an unknown specification. The specific determination criteria are as follows: , in: The embedding vector of the current input sample With the Class specification prototype vector The Euclidean distance between them; This is an operator that retrieves the minimum distance among all known specifications. The total number of known specifications; The threshold for determining abnormal specifications needs to be balanced between the false negative rate and the false positive rate.
[0054] In one embodiment of the present invention, the abnormal specification determination threshold The settings are based on intra-class distance statistics of known specification embedding vectors. Specifically, the system first calculates the standard deviation of intra-class distance for each known specification. ,in For the first The standard deviation of the intra-class distance for each class specification characterizes the dispersion of samples of that class in the embedding space, typically ranging from 0.1 to 0.5. Then, the threshold for determining outlier specifications is set as the maximum value of the standard deviations of the intra-class distances for all classes multiplied by a safety factor. ,in For safety factor, it is set to 3.0 in this embodiment. The basis for this factor is that under the assumption of normal distribution, 3 times the standard deviation covers 99.7% of normal samples, thereby controlling the false alarm rate to below 0.3%.
[0055] When the system detects an abnormal specification, an early warning mechanism is triggered. Preferably, the early warning mechanism includes the following processing flow: First, the system pauses the current detection process and issues an audible and visual alarm; second, the current image and its embedded vector's position in the specification space are visualized on the human-machine interface; third, the operator is prompted to confirm, with confirmation options including three options: known specification misidentification, new specification entry, and ignoring the abnormality.
[0056] When the operator selects the new specification entry option, the system initiates a one-click entry process. In one embodiment of the present invention, the new specification entry only requires 5 sample images to complete. The entry process includes the following steps: First, acquire 5 sample images of the new specification playing cards. The second step is to calculate the embedding vectors of these five images using a specification classification network. The third step is to calculate the prototype vector of the new specification. The fourth step involves the operator inputting basic information about the new specification through the human-computer interaction interface. The fifth step involves the system automatically initializing the specification-related layer parameter templates for the new specification. The initialization strategy is to select the known specification parameter template that is closest to the prototype vector of the new specification in the embedding space as the basis, and to perform linear scaling adjustment based on the difference in geometric dimensions. The sixth step involves writing the prototype vector, parameter templates, and basic information of the new specification into the specification feature library, thus completing the input process.
[0057] Preferably, after the new specification is entered, the system will perform a rapid verification. Specifically, the system uses the remaining samples to recollect several samples for specification recognition testing to verify whether the new specification can be correctly identified. If the verification pass rate is less than 95%, the system will prompt the operator to supplement more samples or check the entered information. The technical effect of this verification mechanism is to ensure the reliability of the recognition of the newly entered specification.
[0058] like Figure 2 As shown, this embodiment of the invention also provides a multi-specification playing card image recognition and packaging parameter adaptive system, which corresponds to the above method embodiment and includes six functional modules.
[0059] The specification feature library construction module 1 is used to implement the function of step S1, which encodes and stores the geometric parameters, printing features, and material attributes of various specifications of playing cards in a structured manner to form a specification feature knowledge base. In one embodiment of the present invention, this module adopts a distributed storage architecture, with specification feature data stored in a relational database and prototype vectors and parameter templates stored in a high-speed cache system to support millisecond-level retrieval response. The database uses MySQL version 8.0, and the cache system uses Redis version 7.0, with both maintaining data consistency through a master-slave synchronization mechanism.
[0060] The specification recognition module 2 implements the function of step S2. When a playing card enters the inspection station, it performs specification recognition on the acquired image through a specification classification network, extracts the specification embedding vector of the current playing card, and determines its specification category in the specification embedding space based on metric learning. Preferably, this module is deployed on an edge computing device equipped with a GPU accelerator card. The specification classification network uses TensorRT for inference optimization, and the specification recognition time for a single image is controlled within 50ms, meeting the inspection speed requirement of 20 playing cards per second on the production line.
[0061] The parameter retrieval and fusion module 3 implements the function of step S3. Based on the identified specification category, it retrieves the corresponding parameter template from the specification feature library, decomposes the detected parameters into three levels: specification-independent layer parameters, specification-related layer parameters, and batch-related layer parameters, and performs parameter fusion through a multi-granularity parameter inheritance mechanism. This module is connected to the specification feature library construction module through a high-speed interface. Parameter retrieval is accelerated using hash indexing, and parameter fusion is optimized using vectorized operations. The total time for the retrieval and fusion process is controlled within 100ms.
[0062] The few-shot fine-tuning module 4 implements the function of step S4. It uses a few-shot fine-tuning strategy to perform batch-level optimization and adaptation of the fused parameters, and uses a small number of sample images from the current batch to update the gradient of the batch-related layer parameters. This module is implemented using an incremental training framework, which supports background parameter optimization without interrupting production. The optimization results are loaded into the detection execution engine via hot update, with the hot update latency controlled within 1 second.
[0063] The online continuous learning module 5 implements the function of step S5. During normal detection, it continuously collects boundary samples near the decision boundary to unsupervisedly optimize the classifier's decision boundary. This module consists of four parts: a boundary sample recognition submodule, a boundary sample buffer management submodule, a pseudo-label generation submodule, and a decision boundary update submodule. Each submodule communicates asynchronously through a message queue to ensure that the learning process does not affect the real-time performance of the main detection process.
[0064] The abnormal specification early warning module 6 implements the function of step S6, calculating the feature distance between the specification embedding vector of the current input image and all known specification prototype vectors. When all distances exceed a preset feature distance threshold, an abnormal specification early warning mechanism is triggered, and one-click input of new specifications is supported. This module is integrated with the human-computer interaction interface, providing intuitive specification space visualization. It uses the t-SNE dimensionality reduction algorithm to map the 256-dimensional embedding space to a 2D plane for display, and the convenient new specification input process can be completed within 3 minutes.
[0065] The various modules of this invention form a closed-loop collaborative relationship: the specification feature library construction module 1 provides prototype vector support for the specification recognition module; the output of the specification recognition module 2 drives the operation of the parameter retrieval and fusion module 3; the output of the parameter retrieval and fusion module 3 initializes the parameters of the few-sample fine-tuning module 4; the optimization results of the few-sample fine-tuning module 4 and the online continuous learning module 5 update the parameter templates in the specification feature library construction module 1 in reverse; and the new specification entry function of the abnormal specification early warning module 6 expands the specification library capacity of the specification feature library construction module 1. This closed-loop architecture enables the system to have the ability to self-improve and continuously evolve.
[0066] The system of this invention has achieved remarkable results in actual deployment tests: it supports automatic recognition of playing cards of any size within the range of 54mm×86mm to 89mm×127mm, covering more than 95% of playing card sizes on the market; the adaptive time for production change parameters has been shortened from 20 to 30 minutes in the traditional solution to less than 2 minutes, improving production efficiency by more than 10 times; only 5 sample images are needed to input new specifications, and the total input time is about 3 minutes; the specification recognition accuracy reaches 99.9% on a test set containing 15 common specifications and 99.7% on an extended test set containing 20 specifications.
[0067] The embodiments of the present invention are not limited to the specific embodiments described above. Those skilled in the art can make various equivalent changes or substitutions based on the technical solutions of the present invention, and all such changes or substitutions should be included within the protection scope of the present invention.
Claims
1. A method for image recognition and adaptive packaging parameters of multi-specification playing cards, characterized in that, Includes the following steps: Step S1: Construct a specification feature library by structurally encoding and storing the geometric parameters, printing features, and material properties of various playing cards. The geometric parameters include normalized values of the length, width, and thickness of the playing cards. The printing features include color space distribution features and edge sharpness index. The material properties include surface gloss and reflectivity parameters, forming a specification feature knowledge base. Step S2: When the playing card enters the detection station, the acquired image is identified by the specification classification network, the acquired image is mapped to a high-dimensional embedding space to generate a specification embedding vector, the Euclidean distance between the specification embedding vector and the specification prototype vectors in the specification feature library is calculated, and the specification category of the current playing card is determined by the softmax function based on the Euclidean distance. Step S3: Based on the specification category identified in step S2, retrieve the corresponding parameter template from the specification feature library, and decompose the detection parameters into three levels: specification-independent layer parameters, specification-related layer parameters, and batch-related layer parameters. The specification-independent layer parameters include light source intensity and camera gain, the specification-related layer parameters include region of interest segmentation scheme and edge detection threshold, and the batch-related layer parameters include template reference image and defect detection sensitivity coefficient. The parameters of the three levels are weighted and fused through a multi-granularity parameter inheritance mechanism. Step S4: The parameters fused in step S3 are optimized and adapted in batches using a few-sample fine-tuning strategy. Support set samples of the current batch are collected, and the parameters of the relevant layers of the batch are updated by gradient descent using the support set samples. During the update process, a regularization term is introduced to constrain the parameter offset. Step S5: During normal detection, the online continuous learning module is started to identify boundary samples whose detection confidence falls within a preset interval and store them in the boundary sample buffer. When the number of samples in the boundary sample buffer reaches a threshold, pseudo-labels of the boundary samples are generated based on high-confidence samples. The decision boundary of the classifier is optimized unsupervised using the boundary samples with pseudo-labels.
2. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S1, the color space distribution characteristics are represented by a hue histogram of the HSV color space. The hue histogram is quantized using 36 bins, with each bin covering a hue range of 10 degrees. The edge sharpness index is obtained by calculating the average gradient magnitude using the Sobel operator, with a value range of 50 to 200.
3. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S2, the specification classification network includes four convolutional blocks and two fully connected layers. The number of output channels of the four convolutional blocks are 64, 128, 256 and 512, respectively. The convolutional blocks are downsampled through a max pooling layer. The fully connected layer outputs a 256-dimensional embedding vector and applies L2 normalization.
4. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S2, the specification prototype vector is the mean center of the embedding vectors of all training samples of the specification, and the softmax function introduces a temperature coefficient τ, the value of which ranges from 0.1 to 1.
0.
5. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S2, the training of the specification classification network adopts the triplet loss function. The triplet loss function makes samples of the same specification cluster in the embedding space and samples of different specifications move away from each other. The value range of the margin boundary parameter in the triplet loss function is 0.3 to 0.
7.
6. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S3, the parameter fusion of the multi-granularity parameter inheritance mechanism adopts a layered superposition strategy. The parameter fusion weights of the three levels are α, β, and γ, respectively, satisfying the constraint condition α+β+γ=1. Among them, the weight β of the specification-related layer parameter is greater than the weights of the other two layers of parameters.
7. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S4, the number of support set samples is 3 to 10. The gradient descent uses a combined loss function, which includes a detection loss term and a regularization term. The regularization term uses the L2 norm to calculate the parameter offset, and the regularization coefficient ranges from 0.001 to 0.
1.
8. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, In step S5, the identification condition for the boundary sample is that the normal class probability output by the detection model falls within the interval formed by the lower threshold and the upper threshold. The value range of the lower threshold is 0.2 to 0.4, the value range of the upper threshold is 0.6 to 0.8, and the maximum capacity of the boundary sample buffer is 50 to 200 samples.
9. The method for multi-specification playing card image recognition and packaging parameter adaptation according to claim 1, characterized in that, The method also includes step S6, which calculates the feature distance between the specification embedding vector of the current input image and all known specification prototype vectors. When the minimum value of all distances exceeds a preset feature distance threshold, the current input image is determined to belong to an unknown specification and an abnormal specification warning mechanism is triggered. It supports one-click input of new specifications by collecting a small number of sample images to calculate the new specification prototype vector. The feature distance threshold is set based on the intra-class distance standard deviation of the known specification embedding vectors. The setting method is to multiply the maximum value of the intra-class distance standard deviation of all categories by a safety factor. The safety factor ranges from 2.5 to 3.
5. One-click input of new specifications requires the collection of 3 to 10 new specification sample images.
10. A multi-specification playing card image recognition and packaging parameter adaptive system, used to implement the method as described in any one of claims 1 to 9, characterized in that, include: The specification feature library construction module is used to structurally encode and store the geometric parameters, printing features and material properties of various sizes of playing cards, forming a specification feature knowledge base; The specification recognition module is used to identify the specifications of the captured image through a specification classification network when the playing card enters the inspection station, extract the specification embedding vector of the current playing card, and determine its specification category in the specification embedding space based on metric learning. The parameter retrieval and fusion module is used to retrieve the corresponding parameter template from the specification feature library based on the identified specification category, decompose the detection parameters into three levels: specification-independent layer parameters, specification-related layer parameters, and batch-related layer parameters, and perform parameter fusion through a multi-granularity parameter inheritance mechanism. The few-shot fine-tuning module is used to perform batch-level optimization and adaptation of the fused parameters using a few-shot fine-tuning strategy, and to perform gradient updates on the batch-related layer parameters using a small number of sample images of the current batch. The online continuous learning module is used to continuously collect boundary samples located near the decision boundary during normal detection, and to optimize the classifier decision boundary in an unsupervised manner. The abnormal specification warning module is used to calculate the feature distance between the specification embedding vector of the current input image and all known specification prototype vectors. When all distances exceed the preset feature distance threshold, the abnormal specification warning mechanism is triggered and one-click input of new specifications is supported.
Citation Information
Patent Citations
Machine vision detection method and system based on feature calibration
CN118762243A