Image reconstruction method, device and storage medium based on rotation CAPTCHA
By capturing the long-distance dependencies of rotated CAPTCHA images through the self-attention mechanism of the visual Transformer model, the problem of insufficient image feature alignment capability is solved, the perception accuracy of rotation alignment state is improved, and the reliability of CAPTCHA image reconstruction and the accuracy of security assessment are enhanced.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, the image feature alignment capability of rotation CAPTCHAs is insufficient, making it difficult to effectively model long-range dependencies between image blocks. This results in low accuracy of rotation alignment state perception, affecting security assessment and algorithm optimization.
The self-attention mechanism of the visual Transformer model is used to capture the long-distance dependency between the internal rotated image and the external background image, and the CAPTCHA image is reconstructed by predicting the rotation angle and the ring weight loss function.
It improves the accuracy of rotation angle prediction, thereby enhancing the reliability of CAPTCHA image reconstruction and the accuracy of security assessment.
Smart Images

Figure CN121366087B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to an image restoration method based on a rotating verification code, a device and a storage medium. BACKGROUND
[0002] The rotating verification code is a widely used human-computer interaction verification mechanism, which is often used to distinguish between human users and automated programs. This type of verification code is usually composed of a segmented picture, in which a circular inner region is randomly rotated, and the verification can be completed only when the inner region is rotated to the correct angle aligned with the outer background image.
[0003] In professional fields such as security audit and algorithm research and development, network security service providers often need to provide reliable security evaluation for customers' verification code systems, identify design vulnerabilities by simulating high-fidelity cracking attacks, and output reinforcement recommendations accordingly. At the same time, verification code research and development institutions also need to continuously test their algorithms internally, drive algorithm iteration through quantitative cracking success rate and other means, and thus improve the overall system's anti-attack ability.
[0004] However, due to the insufficient image feature alignment capability, it is difficult to effectively model the long-range dependency relationship between image blocks when judging the alignment state of the inner and outer image blocks at the semantic level, thus restricting the perception accuracy of the rotation alignment state, and thus it is difficult to support high-reliability security evaluation and algorithm optimization tasks.
[0005] The above content is only used to assist in understanding the technical solutions of the present application and does not represent the acknowledgement of the above content as prior art. SUMMARY
[0006] The main purpose of the present application is to provide an image restoration method based on a rotating verification code, a device and a storage medium, which aims to solve the technical problem of insufficient image feature alignment capability, difficulty in modeling long-range dependency relationship between image blocks, and low perception accuracy of rotation alignment state.
[0007] To achieve the above purpose, the present application provides an image restoration method based on a rotating verification code, which comprises:
[0008] Obtaining a verification code image, and parsing the verification code image to obtain an original rotation angle;
[0009] Splitting the verification code image into an inner rotating image and an outer background image, and inputting the inner rotating image and the outer background image into a visual Transformer model;
[0010] The self-attention mechanism of the visual Transformer model is used to capture the long-range dependency between the internal rotation image and the external background image, and the predicted rotation angle is output based on the long-range dependency.
[0011] The CAPTCHA image is reconstructed using the predicted rotation angle, the original rotation angle, and the preset ring weight loss function.
[0012] In one embodiment, the step of capturing the long-range dependency between the internal rotation image and the external background image using the self-attention mechanism of the visual Transformer model, and outputting a predicted rotation angle based on the long-range dependency, includes:
[0013] The internal rotated image and the external background image are each divided into multiple image blocks, and each image block is converted into a token sequence;
[0014] The token sequence is input into a visual Transformer network, and the global correlation between each image block is analyzed through a self-attention mechanism;
[0015] The token sequences of the internal rotation image and the external background image are integrated, and the predicted rotation angle is generated based on the integration result.
[0016] In one embodiment, the step of integrating token sequences of the inner rotated image and the outer background image, and generating the predicted rotation angle based on the integration result, includes:
[0017] The token sequence of the inner rotated image and the token sequence of the outer background image are concatenated to form a combined token sequence;
[0018] Calculate the association weights between each token in the combined token sequence, and obtain the long-distance dependency relationship based on the association weights;
[0019] The token sequences of the inner rotated image and the outer background image are weighted and fused according to the long-distance dependency to generate a unified feature representation as the integration result;
[0020] The predicted rotation angle is generated based on the integration results.
[0021] In one embodiment, the step of generating a predicted rotation angle based on the integrated results includes:
[0022] The unified feature representation is mapped to continuous rotation angle values, and the continuous rotation angles are weighted and calculated using a ring weight loss function;
[0023] The predicted rotation angle is obtained based on the weighted calculation results.
[0024] In one embodiment, the step of reconstructing the CAPTCHA image using the predicted rotation angle, the original rotation angle, and a preset circular weight loss function includes:
[0025] Calculate the minimum arc length distance between the predicted rotation angle and the original rotation angle in the ring structure;
[0026] The preset environmental weight loss function is used to generate a circular weight distribution for the minimum arc length distance. The angular distribution of the predicted rotation angle is aligned with the circular weight distribution. The weighted loss value is calculated based on the alignment state.
[0027] The predicted rotation angle is adjusted based on the weighted loss value, and the CAPTCHA image is restored using the adjusted predicted rotation angle.
[0028] In one embodiment, the step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure includes:
[0029] Calculate the absolute difference between the predicted rotation angle and the original rotation angle;
[0030] The absolute difference is compared with the complementary value of the data range to which the ring structure belongs, and the smaller value is taken as the minimum arc length distance.
[0031] In one embodiment, the step of generating a circular weight distribution for the minimum arc length distance using the preset environmental weight loss function, aligning the angular distribution of the predicted rotation angle with the circular weight distribution, and calculating the weighted loss value based on the alignment state includes:
[0032] The predicted rotation angle is converted into an angular probability distribution;
[0033] The angular probability distribution is weighted using the ring weight distribution of the preset environmental weight loss function, and the weighted cross-entropy loss is calculated to obtain the weighted loss value.
[0034] In one embodiment, the image restoration method based on the rotating CAPTCHA further includes:
[0035] Obtain training samples based on rotation CAPTCHAs and input the training samples into a pre-constructed initial visual feature network;
[0036] The difference measure of the training samples is calculated using the initial visual feature network;
[0037] The visual Transformer model is obtained by adjusting the parameter configuration of the initial visual feature network based on the difference metric.
[0038] In addition, to achieve the above objectives, this application also proposes an image restoration device based on a rotation CAPTCHA, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image restoration method based on a rotation CAPTCHA as described above.
[0039] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the image restoration method based on the rotation verification code described above.
[0040] One or more technical solutions proposed in this application have at least the following technical effects:
[0041] The technical solution of this application involves acquiring a CAPTCHA image, parsing the CAPTCHA image to obtain the original rotation angle, splitting the CAPTCHA image into an inner rotation image and an outer background image, and inputting the inner rotation image and the outer background image into a visual Transformer model; using the self-attention mechanism of the visual Transformer model to capture the long-distance dependency between the inner rotation image and the outer background image, and outputting a predicted rotation angle based on the long-distance dependency; and reconstructing the CAPTCHA image using the predicted rotation angle, the original rotation angle, and a preset circular weight loss function.
[0042] Therefore, this application effectively captures the long-distance dependency between the internal rotated image and the external background image through the self-attention mechanism of the visual Transformer model, improves the accuracy of rotation angle prediction, and thus enhances the reliability of CAPTCHA image reconstruction and the accuracy of security assessment. Attached Figure Description
[0043] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 This is a flowchart illustrating the first embodiment of the image restoration method based on a rotated CAPTCHA of this application;
[0046] Figure 2This is a flowchart illustrating the second embodiment of the image restoration method based on a rotated CAPTCHA of this application;
[0047] Figure 3 This is a schematic diagram of the device structure of the hardware operating environment involved in the image restoration method based on rotation verification code in the embodiments of this application.
[0048] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0049] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0050] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0051] The main solution of this application embodiment is as follows: acquire a verification code image, parse the verification code image to obtain the original rotation angle; split the verification code image into an inner rotation image and an outer background image, and input the inner rotation image and the outer background image into a visual Transformer model; use the self-attention mechanism of the visual Transformer model to capture the long-distance dependency between the inner rotation image and the outer background image, and output the predicted rotation angle based on the long-distance dependency; reconstruct the verification code image using the predicted rotation angle, the original rotation angle, and a preset circular weight loss function.
[0052] Due to insufficient existing image feature alignment capabilities, it is difficult to model long-range dependencies between image blocks, resulting in low accuracy of rotation alignment state perception.
[0053] This application provides a solution that effectively captures the long-distance dependency between the internal rotated image and the external background image through the self-attention mechanism of the visual Transformer model, thereby improving the accuracy of rotation angle prediction and enhancing the reliability of CAPTCHA image reconstruction and the accuracy of security assessment.
[0054] Based on this, embodiments of this application provide an image restoration method based on a rotated CAPTCHA, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the image restoration method based on a rotated CAPTCHA of this application. In this embodiment, the image restoration method based on a rotated CAPTCHA includes steps S10 to S40:
[0055] Step S10: Obtain the verification code image and parse the verification code image to obtain the original rotation angle;
[0056] In this embodiment, a CAPTCHA image is obtained from the target CAPTCHA server endpoint. The CAPTCHA image can be represented as a binary data stream, typically transmitted in Base64 encoding format or directly as an image file. After decoding and buffering, it is stored in memory as an image object to form the CAPTCHA image in image format. Metadata analysis of the CAPTCHA image allows for structural parsing to obtain the original rotation angle. When the CAPTCHA image is generated on the server side, its initial rotation angle parameter is often implicitly or explicitly embedded in the image data. Therefore, the original rotation angle parameter information of the CAPTCHA image can be extracted from the payload of the interaction communication protocol between the client and the CAPTCHA server to obtain the original rotated image; alternatively, structural feature analysis can be performed on the CAPTCHA image itself. By identifying preset direction markers or baselines in the CAPTCHA image, the initial offset of the internal rotated image relative to the standard coordinate system can be calculated, and this offset is recorded as the original rotation angle.
[0057] In another feasible implementation, a multi-frame image analysis strategy is used to parse the CAPTCHA image to obtain the original rotation angle. Specifically, when the CAPTCHA server adopts a dynamic CAPTCHA mechanism, it continuously acquires multiple frames of CAPTCHA images under the same CAPTCHA session, analyzes the relative displacement trajectory of the internal rotation image in the multiple frames of CAPTCHA images between different frames, and then uses a motion trajectory fitting algorithm to deduce the original rotation angle.
[0058] The original rotation angle is formatted as a floating-point value, and its range is normalized to the [0, 360) degree interval. It is then indexed and associated with the corresponding verification code image and stored in a temporary session database for subsequent restoration.
[0059] In addition, the acquisition and parsing process of the verification code image also needs to integrate an error handling mechanism. When the original rotation angle cannot be directly parsed from the communication protocol or image structure, a degradation processing strategy will be enabled. By calculating the overall grayscale distribution entropy value of the verification code image, or analyzing the matching degree of the edge contours of the inner rotated image and the outer background image, an approximate initial rotation angle will be estimated and defined as the original rotation angle.
[0060] Step S20: The verification code image is split into an inner rotated image and an outer background image, and the inner rotated image and the outer background image are input into the visual Transformer model;
[0061] The CAPTCHA image is split into an inner rotated region and an outer background region. This splitting process can be implemented based on a pre-trained semantic segmentation network. The semantic segmentation network adopts an encoder-decoder architecture. Its encoder part consists of a deep residual convolutional network used to extract multi-scale feature maps of the CAPTCHA image. The decoder part gradually restores the spatial resolution of the feature maps through upsampling and skip connection operations. Based on this, the encoder-decoder structure of the semantic segmentation network outputs the probability distribution of each pixel belonging to the inner rotated region or the outer background region. Adaptive threshold binarization is then applied to the probability distribution to generate an accurate mask image.
[0062] The splitting operation based on the CAPTCHA image includes two sub-steps: coordinate positioning and image cropping. First, the geometric parameters of the minimum bounding rectangle or minimum bounding circle of the internal rotation region are calculated based on the mask image, including the center coordinates and radius. Then, a cropping region is formed using the center coordinates as the center and the radius plus a preset boundary margin, extracting the internal rotation image from the CAPTCHA image. Correspondingly, the external background image is obtained by performing a logical NOT operation on the mask region corresponding to the internal rotation region, followed by a bitwise AND operation with the original CAPTCHA image. Furthermore, to ensure spatial alignment consistency between the internal rotation image and the external background image, the splitting process must maintain both images in the same spatial coordinate system.
[0063] In another feasible implementation, the segmentation operation based on the inner rotated image and the outer background image can employ a traditional image processing algorithm based on edge gradient detection. Specifically, Gaussian filtering is applied to the CAPTCHA image to suppress noise, followed by the extraction of salient edge contours from the CAPTCHA image using the Canny edge detection operator. Then, the Hough circle transform algorithm is used to detect circular boundaries from the salient edge contours; these circular boundaries serve as the boundary between the inner rotated image and the outer background image. Based on the detected circular boundary parameters, the same image cropping process as described in the aforementioned semantic segmentation method is performed.
[0064] After splitting, the inner rotated image and the outer background image undergo a unified preprocessing pipeline, including image size normalization, pixel value standardization, and data augmentation transformation to obtain standard outer rotated image and outer background image. Specifically, size normalization scales the two sets of images to the fixed input size required by the visual Transformer model, such as 224×224 pixels; pixel value standardization converts the image data from integer representation to floating-point representation and performs channel-level mean subtraction and standard deviation normalization; the data augmentation transformation optionally includes random horizontal flipping, random brightness adjustment, and random contrast adjustment to improve the generalization ability of the visual Transformer model. The two preprocessed images are concatenated into a multi-channel tensor, which serves as the formal input to the visual Transformer model.
[0065] Step S30: The self-attention mechanism of the visual Transformer model is used to capture the long-distance dependency between the internal rotation image and the external background image, and the predicted rotation angle is output based on the long-distance dependency.
[0066] In this embodiment, the self-attention mechanism of the visual Transformer model is the core component for capturing long-distance dependencies. Specifically, the internal rotated image and the external background image are divided into a sequence of image patches of fixed size. Each image patch is converted into an embedding vector through a linear projection layer, and positional encoding information is added to preserve its spatial relationship. The embedding vector sequence serves as the initial query vector, key vector, and value vector, and is input to the multi-head attention layer of the self-attention mechanism. In the multi-head attention layer, the query vector and the key vector are multiplied by a dot product to generate an attention score matrix. After being normalized by the Softmax function, the attention score matrix is weighted and summed with the value vector to establish the association weights between any two image patches globally.
[0067] Furthermore, by computing multiple attention heads in parallel, the visual Transformer model can simultaneously focus on feature information from different representation subspaces. Each attention head independently computes its corresponding attention distribution, and finally, the outputs of all attention heads are concatenated along the feature dimension and fused through a linear transformation layer to obtain the output result. This attention head configuration mechanism allows the visual Transformer model to explicitly model the semantic correspondence between the texture patterns in the internal rotated image and the corresponding regions in the external background image. Additionally, based on the output of the self-attention layer, a nonlinear transformation is performed using a multilayer perceptron and a feedforward neural network to gradually abstract high-level feature representations as long-distance dependencies.
[0068] Furthermore, a cross-attention mechanism can be integrated into the visual Transformer model as a supplement to the standard self-attention mechanism. In the architecture of the visual Transformer model, the embedding sequence of the inner rotated image serves as the source of the query vector, while the embedding sequence of the outer background image serves as the source of the key and value vectors. Through the cross-attention design, the visual Transformer model can proactively and specifically retrieve contextual information related to the content of the inner rotated image from the outer background image, accurately determining their alignment state. Specifically, this alignment state is represented as the long-distance dependency. Specifically, the cross-attention design can be combined with the standard self-attention mechanism in a cascaded or parallel manner to form a hybrid attention architecture that improves the efficiency of feature fusion.
[0069] The regression head is connected to the final output layer of the calculated visual Transformer model. The regression head consists of a fully connected layer and an activation function. It is used to map the global feature vector represented by the long-distance dependency into a continuous rotation angle prediction value, which is the predicted rotation angle. The regression head adopts an angle parameterization strategy, for example, decomposing the predicted rotation angle into sine and cosine components for joint prediction, and restoring it to a scalar angle value through inverse trigonometric function operation, which is the predicted rotation angle.
[0070] Step S40: Reconstruct the CAPTCHA image using the predicted rotation angle, the original rotation angle, and the preset ring weight loss function.
[0071] In this embodiment, based on the obtained original rotation angle, the calculated predicted rotation angle, and the preset ring weight loss function, where the preset ring weight loss function is an optimization objective designed to solve the periodicity problem of angle regression. Specifically, the core of the preset ring weight loss function lies in explicitly incorporating the ring-shaped characteristics of the angle difference into the loss calculation process. Its mathematical form is based on the Gaussian kernel function, assigning a weight that decays according to a Gaussian distribution to the shortest arc distance between the predicted rotation angle and the original rotation angle in the ring space. Specifically, firstly, the absolute difference between the predicted rotation angle and the original rotation angle is calculated. Then, by taking the minimum value between the absolute difference and 360 degrees minus the absolute difference, the angle error in the ring sense is obtained. The angle error is input into the Gaussian kernel function to generate the corresponding ring weight value.
[0072] Furthermore, the calculation process of the ring weight loss function involves discretizing the continuous angle space or probabilistically processing the predicted output. In one embodiment, the regression output of the visual Transformer model is converted into a probability distribution on a set of discrete angle values through a Softmax layer. Simultaneously, with the original rotation angle as the center, the ring weights corresponding to each discrete angle value are calculated using the Gaussian kernel function, forming a ring weight distribution of the target probability distribution. The ring weight loss function ultimately calculates the cross-entropy between the predicted probability distribution and the ring weight distribution.
[0073] In another feasible implementation, the ring-weighted loss function can be directly calculated in the continuous angle space without a discretization step. Specifically, using kernel-based density estimation theory, the predicted rotation angle is treated as a continuous random variable, and the probability density function based on this continuous random variable is represented by a hybrid density network parameterized by the visual Transformer model output. Furthermore, the loss function is defined as the negative log-likelihood between the predicted density function and the Gaussian ring kernel function centered at the original rotation angle.
[0074] In summary, the image restoration operation based on the CAPTCHA image is completed by applying geometric transformations after obtaining the optimized predicted rotation angle. Specifically, the inner rotated image is rotated in the opposite direction by the magnitude indicated by the predicted rotation angle, using the center of the inner rotated image as the rotation center. This reverse rotation operation compensates for the random rotation applied during CAPTCHA image generation, allowing the inner rotated image to be semantically realigned with the outer background image. In the specific implementation, the rotation operation based on the CAPTCHA image is performed using a bilinear interpolation algorithm to maintain the visual quality of the rotated CAPTCHA image. The restored CAPTCHA image is used for subsequent automated verification submissions or as test cases for security assessments, thus completing the entire image restoration process.
[0075] In this embodiment, by introducing a ring-weighted loss function, the directional ambiguity problem of traditional mean squared error loss in angle regression tasks is fundamentally solved, significantly improving the prediction stability and final reconstruction accuracy of the visual Transformer model in the critical angle region.
[0076] Specifically, based on the content of step S30 in the first embodiment above, step S30 can be further refined into steps S31~S33. The step of capturing the long-distance dependency between the internal rotation image and the external background image using the self-attention mechanism of the visual Transformer model, and outputting the predicted rotation angle based on the long-distance dependency, includes:
[0077] Step S31: Divide the internal rotated image and the external background image into multiple image blocks, and convert each image block into a token sequence;
[0078] Step S32: Input the token sequence into the visual Transformer network and analyze the global correlation between each image block through the self-attention mechanism;
[0079] Step S33: Integrate the token sequences of the internal rotation image and the external background image, and generate the predicted rotation angle based on the integration result.
[0080] In this embodiment, a fixed-size grid partitioning strategy is used to divide the internal rotated image and the external background image into multiple image blocks. The internal rotated image and the external background image are uniformly scaled to a preset resolution and then meshed along the height and width directions with a fixed step size, generating a series of square image blocks of the same size. Each image block is flattened into a pixel vector and then mapped to the latent space through a trainable linear projection layer, converting it into a corresponding token vector. To preserve the spatial position information of the image block in the original image, each token vector is superimposed with a learnable position encoding vector.
[0081] In another feasible implementation, an adaptive segmentation strategy based on semantic content can be used to divide the image blocks. This adaptive segmentation strategy uses a lightweight convolutional neural network to perform preliminary feature extraction on the inner rotated image and the outer background image, identifying key semantic boundaries and texture-dense regions in both images. Subsequently, the density of the image block divisions is dynamically adjusted based on the feature map gradient information obtained from the preliminary feature extraction. Smaller image block sizes are used in textured regions to preserve detailed features, while larger image blocks are used in smooth regions to improve computational efficiency. This adaptive segmentation method allocates computational resources more effectively, focusing on key image regions relevant to semantic alignment.
[0082] Furthermore, the token sequence based on image blocks is input into a visual Transformer network for stacked computation of multiple Transformer encoders. Each Transformer encoder layer consists of two core modules: a multi-head self-attention mechanism and a feedforward neural network. The gradient flow stability between layers is maintained through residual connections and layer normalization operations. In the multi-head self-attention mechanism, each token vector is projected in parallel into three different representations: a query vector, a key vector, and a value vector. By calculating the dot product similarity between the query vector and all key vectors, an attention weight distribution is generated, and then the value vectors are weighted and summed. This allows each image block to establish a direct association with all other blocks in the sequence, thereby modeling the long-distance visual dependency between the internally rotated image and the external background image.
[0083] Specifically, to enhance the interactive perception between the internal rotating image and the external background image, a cross-image attention mechanism is introduced on top of standard self-attention. This cross-image attention mechanism uses the token sequence of the internal rotating image as the source of the query vector, while using the token sequence of the external background image as the source of both the key and value vectors, thus constructing a cross-image attention layer. Through this directed attention flow, the visual Transformer model can proactively retrieve contextual features from the external background image that match the internal rotating pattern, thereby more accurately perceiving the relative rotation state between the two. Furthermore, the cross-image attention layer can be combined with the standard self-attention layer in an alternating or parallel manner to form a hybrid attention architecture.
[0084] In this embodiment, a global feature aggregation and regression output processing flow is used to integrate the token sequences of the inner rotated image and the outer background image to generate a predicted rotation angle. After processing by a multi-layer Transformer encoder, the global context information of the entire token sequence is condensed into a pre-inserted special classification token. This special classification token, through interaction with all image block tokens, ultimately carries a comprehensive representation of the alignment state between the inner rotated image and the outer background image. After the final hidden state of the special classification token is extracted, it is mapped to the predicted rotation angle value through a regression head composed of a multi-layer perceptron.
[0085] In another feasible implementation, an attention-pooling-based feature aggregation strategy can be used for the integration process. This strategy dynamically calculates the importance weight of each token in the angle prediction task by applying self-attention pooling to all final layer tokens, and then weights and sums the features of all tokens based on the importance weight to generate a global image representation. The global image representation retains fine-grained feature information from the original image blocks, thereby effectively processing CAPTCHA images with complex texture patterns. The specific implementation of the regression head can adopt an angle parameterization representation, that is, decomposing the calculated predicted rotation angle prediction into a joint prediction of sine and cosine values, and then parsing the continuous angle values through inverse trigonometric functions to alleviate the problem of discontinuity at the boundary of the angle period.
[0086] Furthermore, the network structure based on the regression head includes two fully connected layers, with a nonlinear transformation introduced through a Gaussian error linear unit activation function in between. One fully connected layer projects the high-dimensional feature vector to a lower-dimensional latent space, while the other fully connected layer outputs the final predicted value. Additionally, spectral normalization is introduced into the regression head to constrain the Lipshitz constant of the weight matrix, thereby improving model training stability. The data stream, integrated with the token sequence to generate the angle, constitutes the end-to-end prediction pipeline of the visual Transformer model, achieving a precise mapping from local features at the image block level to global rotation angles.
[0087] Further refining the content described in step S33 above, specifically, the step of integrating the token sequences of the internal rotation image and the external background image, and generating the predicted rotation angle based on the integration result, includes:
[0088] The token sequence of the inner rotated image and the token sequence of the outer background image are concatenated to form a combined token sequence;
[0089] Calculate the association weights between each token in the combined token sequence, and obtain the long-distance dependency relationship based on the association weights;
[0090] The token sequences of the inner rotated image and the outer background image are weighted and fused according to the long-distance dependency to generate a unified feature representation as the integration result;
[0091] The predicted rotation angle is generated based on the integration results.
[0092] In this embodiment, the operation of concatenating the token sequence of the inner rotated image and the token sequence of the outer background image into a combined token sequence is essentially a channel merging process based on the embedding dimensions of each token in the token sequence. The token sequence of the inner rotated image contains N token vectors of dimension D, and the token sequence of the outer background image contains M token vectors of the same dimension. By concatenating along the sequence dimensions, a combined token sequence containing N+M token vectors is generated. To distinguish between tokens from two different sources, each token vector is superimposed with a type encoding vector. This type encoding is generated through a trainable parameter matrix and is used to identify the image type to which the token belongs. Simultaneously, a special classification token is inserted at the beginning of the combined token sequence. This token gradually learns the global context information of the entire sequence during training.
[0093] A multi-head self-attention mechanism is used to calculate the association weights between tokens in the combined token sequence. Each attention head of the multi-head self-attention mechanism independently calculates the query-key-value triple, where the query vector, key vector, and value vector all come from the linear projection of the same combined token sequence. The attention weights are calculated using the scaled dot product attention formula. The attention distribution matrix is generated by performing a dot product operation between the query vector and all key vectors, followed by normalization using the Softmax function. Each element of this attention distribution matrix represents the association strength between two tokens in the sequence, thereby capturing the long-distance dependency between the inner rotated image block and the outer background image block.
[0094] In another feasible implementation, a hierarchical attention architecture is used to calculate the association weights. This architecture first performs self-attention computation within each image, establishing local associations between internal rotated image tokens and between external background image tokens. Subsequently, cross-image attention computation is performed to model the interaction relationship between the two types of image tokens. This hierarchical design effectively reduces computational complexity while maintaining the ability to model long-distance dependencies. Specifically, the cross-image attention layer can employ an asymmetric computation mode, allowing only internal rotated image tokens as query sources and external background image tokens as key sources, forming a targeted feature retrieval mechanism.
[0095] The weighted fusion of the token sequences based on their association weights is achieved through weighted summation of value vectors from the attention mechanism. The set of weighted value vectors output by each attention head is concatenated along the feature dimension and then fused through a linear transformation layer to generate a unified feature representation. This unified feature representation retains both the local feature information of the original image blocks and incorporates the global context information captured by the attention mechanism. To further enhance the feature representation capability, the unified feature representation can be processed through a multi-layer feedforward neural network. Each layer contains two fully connected layers and a Gaussian error linear unit activation function, with residual connections and layer normalization maintaining training stability.
[0096] The steps for generating the predicted rotation angle based on the integrated results described above include:
[0097] The unified feature representation is mapped to continuous rotation angle values, and the continuous rotation angles are weighted and calculated using a ring weight loss function;
[0098] The predicted rotation angle is obtained based on the weighted calculation results.
[0099] In this embodiment, a regression head network module maps the unified feature representation to continuous rotation angle values. The regression head consists of two fully connected layers: one fully connected layer projects the high-dimensional unified feature representation to the hidden space, and the other fully connected layer maps the hidden features to angle prediction values. To handle the special properties of the angle period, the output of the regression head can adopt a dual-channel design, predicting the sine and cosine components of the rotation angle separately. Then, the final continuous rotation angle value is synthesized through inverse trigonometric function operations, solving the discontinuity problem of angle regression at the period boundary and improving the stability of model training.
[0100] When calculating the weighted rotation angles using the ring-weighted loss function, a Gaussian kernel transformation based on angle differences is employed. During this transformation, the shortest arc length distance between the predicted and original rotation angles in the ring space is first calculated. This shortest arc length distance is obtained by taking the minimum of the absolute difference and 360 degrees minus the absolute difference. This shortest arc length distance is then input into the Gaussian kernel function to generate the corresponding ring-weighted values. Furthermore, the calculation based on the ring-weighted loss function uses a negative log-likelihood form, guiding the predicted rotation angle distribution output by the visual Transformer model to be as close as possible to a Gaussian ring distribution centered on the original rotation angle. The bandwidth parameter σ of the Gaussian kernel serves as an adjustable hyperparameter, controlling the sensitivity of the loss function to angle errors.
[0101] In another feasible implementation, a hybrid density network architecture is used to generate the continuous rotation angles. The hybrid density network architecture predicts parameters of an angle distribution function, such as the weights, mean, and variance of a mixture of Gaussian distributions. Based on this, the ring weight loss function is adjusted accordingly to a measure of the difference between the distribution of this predicted angle distribution function and the target distribution, such as using Wasserstein distance or KL divergence.
[0102] When obtaining the predicted rotation angle based on the weighted calculation results, backpropagation optimization of the model parameters is involved. Specifically, the gradient information of the predicted rotation angle, obtained through the circular weight loss function, is backpropagated to the parameters of each layer of the regression head and the visual Transformer backbone network using a chain rule, driving the visual Transformer model to adjust the weights to minimize the loss value. Furthermore, to improve optimization efficiency, an adaptive moment estimation algorithm can be used as the optimizer, combined with learning rate warm-up and cosine annealing strategies to dynamically adjust the learning rate. The entire training process is conducted end-to-end, with the visual Transformer model and the regression head network jointly optimizing, ultimately achieving a stable mapping from a unified feature representation to the precise rotation angle.
[0103] Specifically, based on the content of step S40 in the first embodiment above, step S40 can be further refined into steps S41~S43. The step of restoring the verification code image using the predicted rotation angle, the original rotation angle, and the preset ring weight loss function includes:
[0104] Step S41: Calculate the minimum arc length distance between the predicted rotation angle and the original rotation angle in the ring structure;
[0105] Step S42: Use the preset environmental weight loss function to generate a ring weight distribution for the minimum arc length distance, align the angle distribution of the predicted rotation angle with the ring weight distribution, and calculate the weighted loss value based on the alignment state;
[0106] Step S43: Adjust the predicted rotation angle according to the weighted loss value, and restore the CAPTCHA image using the adjusted predicted rotation angle.
[0107] In this embodiment, the minimum arc length distance between the predicted rotation angle and the original rotation angle in the ring structure is calculated using an angle difference metric method in periodic geometric space. In this calculation process, the predicted rotation angle and the original rotation angle are first normalized to a continuous interval of [0, 360) degrees, and the absolute difference Δθ between them is calculated. Since the angle quantity has periodic symmetry, the minimum arc length distance is determined by the formula min(Δθ, 360 - Δθ), ensuring that the angle difference always remains within the effective range of [0, 180] degrees. In the specific implementation, this calculation process is completed through tensor operations, where the angle difference for each sample is calculated independently and forms a difference vector.
[0108] Furthermore, the calculation based on the minimum arc length distance needs to consider the boundary conditions of the angle period. When the predicted rotation angle is close to 0 degrees and the original rotation angle is close to 360 degrees, the standard deviation calculation will produce a large error. Therefore, the actual adjacency of the two can be correctly identified through the ring distance calculation. To improve the calculation accuracy, the angle values are uniformly converted to radians before calculation, and the discontinuity problem of the period boundary is avoided by utilizing the properties of trigonometric functions. During the training process of the visual Transformer model, the minimum arc length distance serves as a basic error metric, directly reflecting the degree of deviation between the predicted result and the true value in the ring geometric space.
[0109] In another feasible implementation, the minimum arc length distance can be calculated using vector geometry methods. Each angle value is converted into a two-dimensional coordinate vector on a unit circle, and the arc length difference is derived by calculating the Euclidean distance between the two two-dimensional coordinate vectors. Specifically, the angle θ is mapped to (cosθ, sinθ), and then the dot product of the predicted angle vector and the true angle vector is calculated. The arc length distance is then obtained using the inverse cosine function.
[0110] Furthermore, based on Gaussian kernel density estimation theory, a preset circular weight loss function is constructed to generate a circular weight distribution using the minimum arc length distance. This circular weight distribution, centered on the original rotation angle, constructs a continuous probability density function in a circular space. Specifically, for any candidate angle θ_i, its circular weight is calculated using the Gaussian kernel function W(θ_i) = exp(-d(θ_i, θ_gt)² / (2σ²)), where d(θ_i, θ_gt) represents the minimum arc length distance between the candidate angle and the true angle, W(θ) is the circular weight distribution, P(θ) is the discrete angle distribution, and σ is the bandwidth parameter controlling the distribution width. This weight distribution reflects the penalty intensity for alignment errors in the circular space; regions closer to the true angle have higher weights.
[0111] Furthermore, the process of aligning the angular distribution of the predicted rotation angle with the circular weight distribution involves a similarity measurement of the probability distributions. Specifically, the regression output of the visual Transformer model is converted into a discrete angular distribution P(θ) using the Softmax function. This distribution represents the probability that the model correctly predicts each angular value. Subsequently, the cross-entropy loss between P(θ) and the circular weight distribution W(θ) is calculated as the weighted loss value.
[0112] In another feasible implementation, an adaptive bandwidth mechanism is used to generate the ring weight distribution. The bandwidth parameter σ of the Gaussian kernel is dynamically adjusted according to the training phase. A larger bandwidth is used in the early stages of training to provide a smooth gradient signal, and the bandwidth is gradually reduced as training progresses to improve accuracy. Furthermore, the ring weight function can be extended to a Gaussian mixture model, using a linear combination of multiple Gaussian kernels to model complex error distribution patterns, better adapting to the characteristics of different CAPTCHA styles.
[0113] Furthermore, the process of adjusting the predicted rotation angle based on the weighted loss value is implemented using the gradient backpropagation algorithm. The partial derivative of the weighted loss value with respect to the model parameters is used to calculate the gradient direction of the loss function relative to the predicted angle. The weight matrix and bias terms in the visual Transformer model are updated using stochastic gradient descent or a variant thereof, gradually reducing the difference between the predicted and true angles in the annular space. A cosine annealing strategy is used for learning rate scheduling, automatically adjusting the learning rate during training to balance convergence speed and stability.
[0114] Furthermore, the process of reconstructing the CAPTCHA image using the adjusted predicted rotation angle involves geometric transformation operations. Using the predicted angle value as a parameter, an inverse rotation transformation is performed on the internally rotated image. Specifically, this includes: establishing an affine transformation matrix with the image center as the rotation base point, and calculating the color value of each pixel after rotation using a bilinear interpolation algorithm. The rotated internal image is then recombined with the external background image to generate the reconstructed CAPTCHA image. The entire reconstruction process maintains image quality, ensuring that the rotation operation does not introduce noticeable jagged edges or blurring distortion.
[0115] In the final stage of image reconstruction, a result verification process is executed. The reconstructed CAPTCHA image is input into a pre-trained verification module to detect whether the internal rotated image and the external background image are correctly aligned semantically and visually. The verification result is compared with the original rotation angle, forming a closed-loop feedback mechanism. For samples that fail to be reconstructed, their angle prediction error distribution characteristics are recorded for subsequent model optimization and data augmentation strategy adjustments. This self-verification mechanism ensures the reliability and robustness of the image reconstruction method in practical applications.
[0116] Furthermore, the step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure includes:
[0117] Calculate the absolute difference between the predicted rotation angle and the original rotation angle;
[0118] The absolute difference is compared with the complementary value of the data range to which the ring structure belongs, and the smaller value is taken as the minimum arc length distance.
[0119] In this embodiment, the process of calculating the absolute difference between the predicted rotation angle and the original rotation angle first requires standardization preprocessing. This preprocessing normalizes the predicted and original rotation angles to floating-point values within the range of 0 to 360 degrees, ensuring that their angle values are within a unified measurement system. The calculation of the absolute difference is implemented using a mathematical absolute value function, i.e., the absolute difference is: Δθ = |θ_pred - θ_gt|, where θ_pred represents the predicted rotation angle and θ_gt represents the original rotation angle. This calculation process is performed element-wise within a tensor operation framework, supporting batch processing of angle comparisons for multiple CAPTCHA samples.
[0120] The determination of the complementary value within the data range of the ring structure is based on the periodicity of the angle data. In the ring angle space from 0 to 360 degrees, for any absolute difference Δθ, its complementary value is defined as 360 - Δθ. This complementary value reflects the distance measured from the other direction of the ring space for the angle difference. In the specific implementation, the calculation of the complementary value is performed through a scalar subtraction operation, ensuring that the result always remains within the valid range of 0 to 360 degrees, thus maintaining the integrity of the ring geometry.
[0121] When comparing the absolute difference with the complementary value of the data range to which the ring structure belongs, an element-wise minimum value selection algorithm is employed. This algorithm computes the absolute difference and its complementary value for each pair of angle samples in parallel, and then applies the minimum value function min(Δθ, 360 - Δθ) to determine the final minimum arc length distance. This comparison operation ensures that the shortest arc length path in the ring space is obtained regardless of the direction from which the angle difference is measured, conforming to the physical nature of angle alignment in rotating CAPTCHAs.
[0122] In another feasible implementation, the minimum arc length distance is calculated using a modular arithmetic optimization method. The minimum ring distance is directly obtained using the formula min(Δθ mod 360, (-Δθ) mod 360), where mod represents the modular arithmetic operation. This mathematical transformation avoids the explicit calculation of complementary values, thus improving computational efficiency.
[0123] Furthermore, the final determination of the minimum arc length distance also needs to consider the accuracy of numerical calculations. Due to rounding errors in floating-point calculations, a fault-tolerance mechanism needs to be introduced when the angle difference approaches 180 degrees. This is achieved by setting a very small threshold ε to avoid numerical instability. When |Δθ - 180| < ε, the minimum arc length distance is forcibly set to 180 degrees to ensure the determinism of the calculation result.
[0124] The calculated minimum arc length distance will serve as a key input to the ring-shaped weighted loss function, and its accuracy directly affects the direction and quality of model optimization. This rigorous minimum arc length distance calculation process ensures that the angular difference metric perfectly matches the geometric characteristics of the ring space, providing a solid mathematical foundation for the task of restoring rotated CAPTCHA images.
[0125] The step of generating a circular weight distribution for the minimum arc length distance using the preset environmental weight loss function, aligning the angular distribution of the predicted rotation angle with the circular weight distribution, and calculating the weighted loss value based on the alignment state includes:
[0126] The predicted rotation angle is converted into an angular probability distribution;
[0127] The angular probability distribution is weighted using the ring weight distribution of the preset environmental weight loss function, and the weighted cross-entropy loss is calculated to obtain the weighted loss value.
[0128] In this embodiment, a discretization probability modeling method based on the Softmax function is used to convert the predicted rotation angle into an angle probability distribution. Specifically, the continuous angle space is uniformly discretized into K equally spaced angle intervals, with the center of each interval representing a candidate angle value. The predicted rotation angle is mapped to a K-dimensional logistic vector through a fully connected layer, and then normalized using the Softmax function to generate an angle probability distribution that conforms to probability axioms. Each element in the angle probability distribution represents the confidence level that the predicted angle falls within the corresponding angle interval, thereby transforming the regression problem into a probability distribution estimation problem.
[0129] In another feasible implementation, the angle probability distribution is generated by a Gaussian mixture model parameterization method. The visual Transformer model outputs multiple sets of parameters such as mixture weights, mean, and variance. A continuous probability density function is constructed through a Gaussian kernel function, and then the continuous probability density function is discretely sampled to obtain the angle probability distribution. This method can more accurately model the uncertainty of angle prediction and is particularly suitable for handling complex CAPTCHA scenarios with multi-peak distribution characteristics.
[0130] In this embodiment, a ring weight distribution with a preset ring weight loss function is used to weight the angle probability distribution, and a target distribution is constructed based on a Gaussian kernel function. Using the original rotation angle as the center, the minimum arc length distance between each discrete angle value and the true angle is calculated, and this minimum arc length distance is input into the Gaussian kernel function to generate a ring weight distribution. When calculating the weighted cross-entropy loss, the difference between the angle probability distribution and the ring weight distribution is quantified as the loss value. Specifically, the weighted cross-entropy formula is used: L = -Σ[W(θ_i) * log(P(θ_i))], where W(θ_i) represents the ring weight distribution and P(θ_i) represents the predicted angle probability distribution.
[0131] In another feasible implementation, a temperature parameter is introduced to adjust the smoothness of the probability distribution in calculating the weighted loss value. By introducing an adjustable temperature parameter before calculating the logarithmic probability, the concentration of the probability distribution is controlled. Higher temperature values are used in the early stages of training to make the distribution smoother, facilitating the model's exploration of the global optimum. As training progresses, the temperature value is gradually decreased to make the distribution more concentrated, thereby improving prediction accuracy. This annealing training strategy effectively balances the contradiction between exploration and exploitation.
[0132] In this embodiment, the calculation of the weighted cross-entropy loss also needs to consider numerical stability. In practical implementation, a very small positive value ε is added during the logarithmic probability calculation to avoid the logarithmic operation from reaching infinity, while ensuring that the sum of all elements in the probability distribution is strictly 1. The weighted loss value is finally obtained by averaging the batch of samples to obtain the overall loss, which serves as the objective function for optimizing the model parameters. The entire process of converting angle values to probability distributions and calculating losses forms a complete circular angle regression optimization framework, providing a reliable training mechanism for the accurate reconstruction of rotating CAPTCHAs.
[0133] Furthermore, you can also view Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the image restoration method based on a rotated CAPTCHA of the present invention. Figure 2 After the step of scheduling the task object to execute the task chain through the task flow orchestration template, the method further includes steps S50-70:
[0134] Step S50: Obtain training samples based on the rotation CAPTCHA and input the training samples into the pre-constructed initial visual feature network;
[0135] Step S60: Calculate the difference measure of the training samples through the initial visual feature network;
[0136] Step S70: Adjust the parameter configuration of the initial visual feature network according to the difference metric to obtain the visual Transformer model.
[0137] In this embodiment, obtaining training samples based on rotated CAPTCHAs involves a multi-source data acquisition and preprocessing process. Specifically, the training samples consist of CAPTCHA image samples and their corresponding actual rotation angle annotations, constructed through a combination of programmed generation and manual annotation. The CAPTCHA image samples cover variations of rotated CAPTCHAs with different design styles, including but not limited to key feature dimensions such as dividing line style, texture complexity, and color mode. Each training sample contains a complete CAPTCHA image, a separated internal rotated image and an external background image, and a precisely measured actual rotation angle value. The actual rotation angle value is obtained through calibration using professional image processing tools to ensure that the annotation accuracy reaches the sub-pixel level.
[0138] In another feasible implementation, data augmentation strategies are employed to expand sample diversity when acquiring the training samples. By applying data augmentation operations such as random rotation transformations, brightness adjustments, Gaussian noise injection, and elastic deformation to the base CAPTCHA image, derived samples with different visual characteristics are generated. Simultaneously, style transfer techniques are used to adapt the CAPTCHA content to backgrounds with different visual styles, enhancing the visual Transformer model's adaptability to various design variations.
[0139] Furthermore, in this embodiment, when inputting training samples into the pre-constructed initial visual feature network, an end-to-end deep learning training paradigm must be followed. The initial visual feature network adopts a ViT-based encoder architecture, containing a backbone network composed of multiple Transformer modules. The input training samples, after image segmentation, linear projection, and positional encoding, are converted into token sequences for input into the network. During training, a batch gradient descent algorithm is used, dynamically adjusting the batch size to balance training efficiency and memory consumption.
[0140] The core of calculating the difference metric for training samples through the initial visual feature network lies in constructing an effective loss function system. The difference metric is calculated based on the error between the predicted rotation angle and the actual rotation angle, using a ring-weighted loss function as the primary optimization objective. This ring-weighted loss function fully considers the periodicity of the angle data, using a Gaussian kernel function to weight the angle error in the ring space, enabling the visual Transformer model to accurately perceive the ring-like characteristics of the angle deviation. In the early stages of training, an auxiliary loss function is introduced to supervise the intermediate layer feature learning, ensuring that the network maintains stable gradient flow during training.
[0141] In another feasible implementation, the difference metric can be calculated using a contrastive learning strategy. By constructing positive and negative sample pairs, the visual Transformer backbone network is required not only to accurately predict the rotation angle, but also to ensure that semantically aligned CAPTCHA samples are close to each other in the feature space, while misaligned samples are far apart. Furthermore, when adjusting the parameter configuration of the initial visual feature network based on the difference metric, an optimization algorithm based on gradient backpropagation is employed. The direction and magnitude of parameter updates for the initial visual feature network are determined by calculating the partial derivatives of the loss function with respect to the parameters of each network layer. An adaptive moment estimation algorithm is selected as the optimizer, and a hierarchical learning rate strategy is configured, setting different learning rates for the backbone network and the regression head network to balance the training progress of the two subtasks: feature extraction and angle regression. During training, regularization techniques such as gradient clipping and weight decay are implemented to prevent model overfitting and improve generalization ability.
[0142] Finally, after a complete training cycle and model selection process, the visual Transformer model is obtained. After a specified number of iterations of training on the training set, the model performance is evaluated on an independent validation set, and the model parameters with the minimum validation loss are selected as the final visual Transformer model. The performance evaluation of this visual Transformer model considers not only the average error of angle prediction but also key metrics such as success rate and robustness. The final visual Transformer model possesses powerful feature extraction and angle regression capabilities, accurately understanding the image content of rotated CAPTCHAs and predicting their rotation state, thus improving reconstruction accuracy.
[0143] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the image restoration method based on rotating CAPTCHA in this application. Any simple transformations based on this technical concept are within the protection scope of this application.
[0144] This application provides an image restoration device based on a rotation CAPTCHA. The image restoration device based on a rotation CAPTCHA includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the image restoration method based on a rotation CAPTCHA in the above embodiment 1.
[0145] The following is for reference. Figure 3The diagram illustrates a structural schematic of an image reconstruction device based on a rotation verification code suitable for implementing embodiments of this application. The image reconstruction device based on a rotation verification code in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The image restoration device based on rotating CAPTCHA shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0146] like Figure 3 As shown, the image reconstruction device based on rotation CAPTCHA may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the image reconstruction device based on rotation CAPTCHA. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the image reconstruction device based on rotation CAPTCHAs to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows an image reconstruction device based on rotation CAPTCHAs with various systems, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems can be implemented alternatively.
[0147] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0148] The image reconstruction device based on rotation CAPTCHA provided in this application, employing the image reconstruction method based on rotation CAPTCHA in the above embodiments, can solve the technical problem of insufficient image feature alignment capability and difficulty in modeling long-range dependencies between image blocks, resulting in low accuracy of rotation alignment state perception. Compared with the prior art, the beneficial effects of the image reconstruction device based on rotation CAPTCHA provided in this application are the same as those of the image reconstruction method based on rotation CAPTCHA provided in the above embodiments, and other technical features in this image reconstruction device based on rotation CAPTCHA are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0149] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0150] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0151] This application provides a storage medium, which is a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the image restoration method based on rotation verification code in the above embodiments.
[0152] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), or any suitable combination thereof.
[0153] The aforementioned computer-readable storage medium may be included in an image reconstruction device based on a rotation CAPTCHA; or it may exist independently and not be assembled into an image reconstruction device based on a rotation CAPTCHA.
[0154] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the image restoration device based on the rotation CAPTCHA, enable the image restoration device based on the rotation CAPTCHA to implement the technical content of the above-described embodiment of the image restoration method based on the rotation CAPTCHA.
[0155] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0156] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0157] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0158] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described image reconstruction method based on rotational CAPTCHA. This solves the technical problem of insufficient image feature alignment capabilities, difficulty in modeling long-range dependencies between image blocks, and resulting in low accuracy in rotational alignment state perception. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the image reconstruction method based on rotational CAPTCHA provided in the above embodiments, and will not be repeated here.
Claims
1. An image reconstruction method based on a rotated CAPTCHA, characterized in that, The image restoration method based on rotation CAPTCHA includes the following steps: Obtain the verification code image and parse the verification code image to obtain the original rotation angle; The verification code image is split into an inner rotated image and an outer background image, and the inner rotated image and the outer background image are input into the visual Transformer model; The self-attention mechanism of the visual Transformer model is used to capture the long-range dependency between the inner rotated image and the outer background image, and the predicted rotation angle is output based on the long-range dependency. Specifically, the inner rotated image and the outer background image are each divided into multiple image blocks, and each image block is converted into a token sequence. The token sequences are input into the visual Transformer network, and the global correlation between the various image blocks is analyzed through the self-attention mechanism. The token sequences of the inner rotated image and the outer background image are integrated, and the predicted rotation angle is generated based on the integration result. The CAPTCHA image is reconstructed using the predicted rotation angle, the original rotation angle, and a preset ring weight loss function. The step of reconstructing the CAPTCHA image using the predicted rotation angle, the original rotation angle, and the preset ring weight loss function includes: calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle within a ring structure; generating a ring weight distribution for the minimum arc length distance using the preset ring weight loss function; aligning the angle distribution of the predicted rotation angle with the ring weight distribution; calculating a weighted loss value based on the alignment state; adjusting the predicted rotation angle based on the weighted loss value; and reconstructing the CAPTCHA image using the adjusted predicted rotation angle. Furthermore, the absolute difference between the predicted rotation angle and the original rotation angle is first calculated, and then the minimum value between the absolute difference and 360 degrees minus the absolute difference is taken to obtain the angle error in a ring-like sense. The angle error is input into a Gaussian kernel function to generate the corresponding ring weight value. The step of integrating the token sequences of the internal rotated image and the external background image, and generating the predicted rotation angle based on the integration result, includes: The token sequence of the inner rotated image and the token sequence of the outer background image are concatenated to form a combined token sequence; Calculate the association weights between each token in the combined token sequence, and obtain the long-distance dependency relationship based on the association weights; The token sequences of the inner rotated image and the outer background image are weighted and fused according to the long-distance dependency to generate a unified feature representation as the integration result; The predicted rotation angle is generated based on the integration results.
2. The image restoration method based on rotating CAPTCHA as described in claim 1, characterized in that, The step of generating the predicted rotation angle based on the integrated results includes: The unified feature representation is mapped to continuous rotation angle values, and the continuous rotation angles are weighted and calculated using a ring weight loss function; The predicted rotation angle is obtained based on the weighted calculation results.
3. The image restoration method based on rotating CAPTCHA as described in claim 1, characterized in that, The step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the ring structure includes: Calculate the absolute difference between the predicted rotation angle and the original rotation angle; The absolute difference is compared with the complementary value of the data range to which the ring structure belongs, and the smaller value is taken as the minimum arc length distance.
4. The image restoration method based on rotating CAPTCHA as described in claim 1, characterized in that, The steps of generating a ring weight distribution for the minimum arc length distance using the preset ring weight loss function, aligning the angular distribution of the predicted rotation angle with the ring weight distribution, and calculating the weighted loss value based on the alignment state include: The predicted rotation angle is converted into an angular probability distribution; The angular probability distribution is weighted using the ring weight distribution of the preset ring weight loss function, and the weighted cross-entropy loss is calculated to obtain the weighted loss value.
5. The image restoration method based on a rotation CAPTCHA as described in any one of claims 1 to 4, characterized in that, The image restoration method based on rotation CAPTCHA also includes: Obtain training samples based on rotation CAPTCHAs and input the training samples into a pre-constructed initial visual feature network; The difference measure of the training samples is calculated using the initial visual feature network; The visual Transformer model is obtained by adjusting the parameter configuration of the initial visual feature network based on the difference metric.
6. An image reconstruction device based on a rotating CAPTCHA, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image restoration method based on a rotation CAPTCHA as described in any one of claims 1 to 5.
7. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the image restoration method based on the rotation verification code as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Recognition algorithm of rotary verification code
CN117556844A
Intelligent verification code generation and anti-refreshing method and system and computer equipment
CN119397477A