Image restoration method and device based on rotating verification code and storage medium

By employing the self-attention mechanism and circular weight loss function of the visual Transformer model, the problem of insufficient image feature alignment capability in rotated CAPTCHAs is solved, improving the perceptual accuracy of rotation alignment state and enhancing the reliability of image reconstruction and security assessment.

CN121366087AActive Publication Date: 2026-01-20VIPSHOP (GUANGZHOU) SOFTWARE CO LTD

Patent Information

Application Number
CN202511950986.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-23
Publication Date
2026-01-20
Estimated Expiration
2045-12-23

Smart Images

  • Figure CN121366087A_ABST
    Figure CN121366087A_ABST
Patent Text Reader

Abstract

The invention discloses an image restoration method and device based on a rotation verification code and a storage medium, and the method comprises the steps: obtaining a verification code image, and analyzing the verification code image to obtain an original rotation angle; splitting the verification code image into an internal rotation image and an external background image, and inputting the internal rotation image and the external background image into a visual Transform model; capturing a long-distance dependency relationship between the internal rotation image and the external background image by adopting a self-attention mechanism of the visual Transform model, and outputting a predicted rotation angle based on the long-distance dependency relationship; and restoring the verification code image through the predicted rotation angle and a preset annular weight loss function. Through the self-attention mechanism of the visual Transform model, the long-distance dependency relationship between the internal rotation image and the external background image is effectively captured, and the rotation angle prediction precision is improved, so that the reliability of verification code image restoration and the accuracy of safety evaluation are enhanced.
Need to check novelty before this filing date? Find Prior Art

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 correct angle of rotation to align with the outer background image is required to complete the verification.

[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 current lack of image feature alignment capability, it is difficult to effectively model the long-range dependency relationship between image blocks when judging the semantic alignment state of the inner and outer image blocks, thus restricting the perception accuracy of the rotation alignment state, and thus making it 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 the current lack of image feature alignment capability, the difficulty in modeling the long-range dependency relationship between image blocks, and the low perception accuracy of the 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: Obtaining a verification code image and parsing the verification code image to obtain an original rotation angle; 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; Capturing the long-distance dependency relationship of the inner rotating image and the outer background image by using the self-attention mechanism of the visual Transformer model, and outputting a predicted rotation angle based on the long-distance dependency relationship; restore the verification code image through the predicted rotation angle, the original rotation angle, and a preset annular weight loss function.

[0008] In an embodiment, the step of capturing long-distance dependencies of the inner rotation image and the outer background image based on the self-attention mechanism of the visual Transformer model and outputting a predicted rotation angle comprises: dividing the inner rotation image and the outer background image into a plurality of image blocks respectively, and converting each image block into a token sequence; inputting the token sequence into a visual Transformer network to analyze the global correlation between each image block through a self-attention mechanism; integrating the token sequences of the inner rotation image and the outer background image, and generating the predicted rotation angle based on the integration result.

[0009] In an embodiment, the step of integrating the token sequences of the inner rotation image and the outer background image and generating the predicted rotation angle based on the integration result comprises: splicing the token sequence of the inner rotation image and the token sequence of the outer background image to obtain a combined token sequence; calculating the correlation weight between each token in the combined token sequence, and obtaining the long-distance dependencies according to the correlation weight; weighting and fusing the token sequences of the inner rotation image and the outer background image according to the long-distance dependencies to generate a unified feature representation as the integration result; generating the predicted rotation angle based on the integration result.

[0010] In an embodiment, the step of generating the predicted rotation angle based on the integration result comprises: mapping the unified feature representation to a continuous rotation angle value, and calculating the continuous rotation angle through an annular weight loss function; obtaining the predicted rotation angle based on the calculation result.

[0011] In an embodiment, the step of restoring the verification code image through the predicted rotation angle, the original rotation angle, and a preset annular weight loss function comprises: calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in an annular structure; generating an annular weight distribution for the minimum arc length distance using the preset environmental weight loss function, aligning the angle distribution of the predicted rotation angle with the annular weight distribution, and calculating a weighted loss value according to the alignment state; adjust the predicted rotation angle according to the weighted loss value, and restore the verification code image according to the adjusted predicted rotation angle.

[0012] In an embodiment, the step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle comprises: calculating an absolute difference value between the predicted rotation angle and the original rotation angle; comparing the absolute difference value with a complementary value of a data range to which the annular structure belongs, and taking a smaller value as the minimum arc length distance.

[0013] In an embodiment, the step of generating an annular weight distribution for the minimum arc length distance using the preset environmental weight loss function, aligning the angle distribution of the predicted rotation angle with the annular weight distribution, and calculating a weighted loss value according to the alignment state comprises: converting the predicted rotation angle into an angle probability distribution; performing weighted processing on the angle probability distribution using the annular weight distribution of the preset environmental weight loss function, and calculating a weighted cross-entropy loss to obtain the weighted loss value.

[0014] In an embodiment, the image restoration method based on the rotation verification code further comprises: obtaining a training sample based on the rotation verification code, and inputting the training sample into an initial visual feature network constructed in advance; calculating a difference measure of the training sample through the initial visual feature network; adjusting a parameter configuration of the initial visual feature network according to the difference measure to obtain the visual Transformer model.

[0015] In addition, to achieve the above-mentioned purposes, the present application further provides an image restoration device based on a rotation verification code, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the image restoration method based on the rotation verification code as described above.

[0016] In addition, to achieve the above-mentioned purposes, the present application further provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, wherein the computer program is executed by a processor to implement the steps of the image restoration method based on the rotation verification code as described above.

[0017] The one or more technical solutions provided by the present application have at least the following technical effects: The technical scheme of the present application obtains a verification code image, analyzes the verification code image to obtain an original rotation angle, splits the verification code image into an internal rotation image and an external background image, inputs the internal rotation image and the external background image into a visual Transformer model, captures long-distance dependency relationships of the internal rotation image and the external background image by using a self-attention mechanism of the visual Transformer model, and outputs a predicted rotation angle based on the long-distance dependency relationships, and restores the verification code image through the predicted rotation angle, the original rotation angle, and a preset annular weight loss function.

[0018] Therefore, by using the self-attention mechanism of the visual Transformer model, the present application effectively captures the long-distance dependency relationships of the internal rotation image and the external background image, improves the rotation angle prediction accuracy, and thus enhances the reliability of the verification code image restoration and the accuracy of the security evaluation. BRIEF DESCRIPTION OF DRAWINGS

[0019] The accompanying drawings, which are incorporated into and form a part of the specification, illustrate preferred embodiments of the present application and, together with the description, serve to explain the principles of the present application.

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without any creative effort.

[0021] Figure 1 A flowchart of a first embodiment of the image restoration method based on the rotating verification code of the present application; Figure 2 A flowchart of a second embodiment of the image restoration method based on the rotating verification code of the present application; Figure 3 A device structure diagram of a hardware running environment related to the image restoration method based on the rotating verification code in the embodiments of the present application.

[0022] The object implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0023] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application, and are not used to limit the present application.

[0024] In order to better understand the technical solutions of the present application, the following will be described in detail with reference to the accompanying drawings and specific embodiments.

[0025] The main solution of the embodiment of the application is: obtaining a verification code image, analyzing the verification code image to obtain an original rotation angle; splitting the verification code image into an internal rotation image and an external background image, and inputting the internal rotation image and the external background image into a visual Transformer model; using a self-attention mechanism of the visual Transformer model to capture long-distance dependency relationships of the internal rotation image and the external background image, and outputting a predicted rotation angle based on the long-distance dependency relationships; and restoring the verification code image through the predicted rotation angle, the original rotation angle, and a preset annular weight loss function.

[0026] Due to insufficient image feature alignment capability, it is difficult to model long-range dependency relationships between image blocks, resulting in the technical problem of low rotation alignment state perception accuracy.

[0027] The application provides a solution, which effectively captures long-distance dependency relationships of internal rotation images and external background images through a self-attention mechanism of a visual Transformer model, improves rotation angle prediction accuracy, and thus enhances the reliability of verification code image restoration and the accuracy of security evaluation.

[0028] Based on this, the embodiment of the application provides a verification code-based image restoration method, referring to Figure 1 , Figure 1 is a flowchart of a first embodiment of the verification code-based image restoration method of the application. In this embodiment, the verification code-based image restoration method comprises steps S10-S40: Step S10, obtaining a verification code image and analyzing the verification code image to obtain an original rotation angle; In this embodiment, the verification code image is obtained from a target verification code server point. The verification code image can be represented as a binary data stream, which is usually transmitted in Base64 encoding format or directly as an image file. After decoding and buffering, the binary data stream is stored in a memory image object to form the verification code image in image format. Metadata analysis of the verification code image can be structurally analyzed to obtain the original rotation angle. When the verification code image is generated on the server side, the initial rotation angle parameter is usually embedded in the image data in an implicit or explicit manner. Therefore, the original rotation angle parameter information of the verification code image can be extracted from the payload of the interactive communication protocol between the client and the verification code server to obtain the original rotation image; or the structure feature of the verification code image itself is analyzed, the initial offset of the internal rotation image relative to the standard coordinate system is calculated by identifying the preset direction mark or reference line in the verification code image, and the offset is recorded as the original rotation angle.

[0029] In another possible implementation, a multi-frame image analysis strategy is adopted to analyze the verification code image to obtain the original rotation angle. Specifically, when a dynamic verification code mechanism is adopted by the verification code server, a plurality of frames of verification code images under the same verification code session are continuously acquired, the relative displacement trajectories of the internal rotation images in the plurality of frames of verification code images between different frames are analyzed, and then the original rotation angle is inversely deduced through a motion trajectory fitting algorithm.

[0030] The obtained original rotation angle is formatted as a floating point number, the value range of which is normalized to the interval [0, 360) degrees, and is indexed and associated with the corresponding verification code image, and is stored in a temporary session database for subsequent restoration and calling.

[0031] In addition, the verification code image acquisition and analysis process also needs to integrate an error handling mechanism. When the original rotation angle cannot be directly analyzed from the communication protocol or the image structure, a degradation processing strategy is enabled, the overall gray scale distribution entropy value of the verification code image is calculated, or the matching degree of the internal rotation image and the edge contour of the external background image is analyzed, to estimate an approximate initial rotation angle as the original rotation angle.

[0032] In step S20, the verification code image is split into an internal rotation image and an external background image, and the internal rotation image and the external background image are input into a visual Transformer model. The verification code image is split into an internal rotation image and an external background image, and this splitting process can be implemented based on a pre-trained semantic segmentation network. The semantic segmentation network adopts an encoder-decoder architecture, the encoder part of which is composed of a deep residual convolutional network, which is used to extract multi-scale feature maps of the verification code image. The decoder part gradually restores the spatial resolution of the feature map through upsampling and jump connection operations. Based on this, the probability distribution of each pixel point belonging to the internal rotation region or the external background region is output through the encoder-decoder structure of the semantic segmentation network. Adaptive threshold binarization processing is applied to the probability distribution to generate an accurate mask image.

[0033] Based on the splitting operation of the verification code image, two sub-steps of coordinate positioning and image cropping are implemented, wherein the geometric parameters of the minimum circumscribed rectangle or the minimum circumscribed circle based on the internal rotation region are calculated based on the mask image, including the center coordinates and the radius length; then, the center coordinates are taken as the center, and the radius plus a preset boundary margin forms a cropping region, and the internal rotation image is extracted from the verification code image. Correspondingly, the external background image is obtained by performing logical NOT operation on the mask region corresponding to the internal rotation region, and then performing bitwise AND operation with the original verification code image. In addition, in order to ensure the spatial alignment consistency of the internal rotation image and the external background image, the splitting process needs to keep the same spatial coordinate system for the two groups of images.

[0034] In another possible implementation, the splitting operation based on the internal rotation image and the external background image can use a traditional image processing algorithm based on edge gradient detection as another implementable scheme. Specifically, Gaussian filtering is applied to the verification code image to suppress noise, and then the Canny edge detection operator is used to extract the significant edge profile in the verification code image. Then, the Hough circle transformation algorithm is used to detect the circular boundary from the significant edge profile, which is the boundary between the internal rotation image and the external background image. Based on the detected circular boundary parameters, the same image cropping process as the aforementioned semantic segmentation method is performed.

[0035] After splitting, the internal rotation image and the external background image undergo a unified preprocessing pipeline, including image size normalization, pixel value standardization and data enhancement transformation to obtain standard external rotation images and external background images. Specifically, the size normalization can scale the two groups of images to a fixed input size required by the visual Transformer model, for example, 224x224 pixels; the 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 enhancement transformation can optionally include random horizontal flipping, random brightness adjustment and random contrast adjustment to improve the generalization ability of the visual Transformer model. The two groups of preprocessed images are spliced into a multi-channel tensor as the formal input of the visual Transformer model.

[0036] In step S30, the self-attention mechanism of the visual Transformer model is used to capture the long-distance dependency relationship of the internal rotation image and the external background image, and a predicted rotation angle is output based on the long-distance dependency relationship. In this embodiment, the self-attention mechanism of the visual Transformer model is the core component for capturing long-range dependencies. Specifically, the internal rotation image and the external background image are divided into fixed-size image block sequences. Each image block is converted into an embedding vector through a linear projection layer and is appended with position encoding information to preserve its spatial relationship. The embedding vector sequence is input into the multi-head attention layer of the self-attention mechanism as the initial query vector, key vector, and value vector. In the multi-head attention layer, the query vector and the key vector are subjected to point multiplication operation to generate an attention score matrix. After normalization by the Softmax function, the attention score matrix is weighted and summed with the value vector to establish the association weight between any two image blocks in the global range.

[0037] In addition, by parallel computing multiple attention heads, the visual Transformer model can simultaneously focus on feature information from different representation subspaces. Each attention head independently calculates its corresponding attention distribution, and finally the outputs of all attention heads are spliced in the feature dimension and fused through a linear transformation layer to obtain the output result. Through the setting mechanism of the attention head, the visual Transformer model can explicitly model the semantic correspondence between the texture pattern in the internal rotation image and the corresponding region in the external background image. Furthermore, based on the nonlinear transformation of the output of the self-attention layer by the multi-layer perceptron and the feedforward neural network, high-level feature representations are gradually abstracted as long-range dependencies.

[0038] In addition, based on the visual Transformer model, a cross-attention mechanism can be integrated as a supplement to the standard self-attention mechanism. In the architecture of the visual Transformer model, the embedding sequence of the internal rotation image serves as the source of the query vector, while the embedding sequence of the external background image serves as the source of the key vector and the value vector. Through the cross-attention design, the visual Transformer model can actively and specifically retrieve context information related to the internal rotation image content from the external background image, which is used to accurately judge the alignment state of the two, specifically, based on the alignment state representation as the long-range 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 to improve the efficiency of feature fusion.

[0039] According to the final output layer of the visual Transformer model, a regression head is connected, which is composed of a fully connected layer and an activation function, and is used to map the global feature vector represented based on the long-distance dependency relationship into a continuous rotation angle prediction value, i.e., a predicted rotation angle. The regression head adopts an angle parameterization representation strategy, for example, decomposes the predicted rotation angle into a sine component and a cosine component for joint prediction, and restores it to a scalar angle value, i.e., the predicted rotation angle, through an inverse trigonometric function operation.

[0040] In step S40, the verification code image is restored by the predicted rotation angle, the original rotation angle and a preset annular weight loss function.

[0041] In this embodiment, based on the obtained original rotation angle, the calculated predicted rotation angle and the preset annular weight loss function, wherein the preset annular weight loss function is an optimization objective designed to solve the periodicity problem of angle regression. Specifically, the core of the preset annular weight loss function is to explicitly incorporate the annular characteristics of the angle difference into the loss calculation process, and its mathematical form is based on a Gaussian kernel function, which assigns a weight that decays according to a Gaussian distribution to the shortest arc length distance of the predicted rotation angle and the original rotation angle in the annular space. Specifically, first, the absolute difference between the predicted rotation angle and the original rotation angle is calculated, and then the angle error in the annular sense is obtained by taking the minimum value between the absolute difference and 360 degrees minus the absolute difference. The angle error is input into the Gaussian kernel function to generate the corresponding annular weight value.

[0042] In addition, the calculation process of the annular weight loss function involves discretization sampling of continuous angle space or probabilistic processing of prediction output. In one embodiment, the regression output of the visual Transformer model is converted into a probability distribution over a set of discrete angle values through a Softmax layer. At the same time, taking the original rotation angle as the center, the annular weight corresponding to each discrete angle value is calculated by the Gaussian kernel function to form an annular weight distribution of the target probability distribution, and the annular weight loss function finally calculates the cross entropy between the predicted probability distribution and the annular weight distribution.

[0043] In another possible implementation, the annular weight loss function can be calculated directly in the continuous angle space without the discretization step. Specifically, based on the kernel function-based density estimation theory, the predicted rotation angle is regarded as a continuous random variable, and the probability density function of the continuous random variable is represented by a mixed density network parameterized by the output of the visual Transformer model. And the loss function is defined as the negative log-likelihood between the predicted density function and the Gaussian annular kernel function centered on the original rotation angle.

[0044] In summary, based on the restoration operation of the verification code image, after obtaining the optimized predicted rotation angle, the geometric transformation is applied to complete the operation. Specifically, taking the center of the internal rotation image as the rotation center, the internal rotation image is reversely rotated by the amplitude indicated by the predicted rotation angle. This reverse rotation operation compensates for the random rotation applied during the generation of the verification code image, so that the internal rotation image and the external background image are re-aligned in terms of semantic content. In the specific implementation process, the rotation operation of the image verification code is performed by a bilinear interpolation algorithm to maintain the visual quality of the rotated verification code image. The restored verification code image is used for subsequent automated verification submission or as a test case for security evaluation, thereby completing the entire image restoration process.

[0045] In this embodiment, by introducing the annular weight loss function, the direction ambiguity problem of the traditional mean square error loss in the angle regression task is fundamentally solved, and the prediction stability and final restoration accuracy of the visual Transformer model in the critical angle region are significantly improved.

[0046] Specifically, based on the content of step S30 in the first embodiment, step S30 can be further refined into steps S31-S33. The step of capturing 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 a predicted rotation angle based on the long-distance dependency includes: Step S31, dividing the internal rotation image and the external background image into a plurality of image blocks respectively, and converting each image block into a token sequence; Step S32, inputting the token sequence into the visual Transformer network, and analyzing the global correlation between each image block through the self-attention mechanism; Step S33, 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.

[0047] In this embodiment, a fixed-size grid division strategy is used to divide the internal rotation image and the external background image into a plurality of image blocks. The internal rotation image and the external background image are uniformly scaled to a preset resolution and are grid cut along the height and width directions according to a fixed step, generating a series of square image blocks with the same size. After each image block is flattened into a pixel vector, it is mapped to a latent space through a trainable linear projection layer and converted 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.

[0048] In another possible implementation, the image patches can also be divided by a semantic content based adaptive division strategy, which extracts preliminary features of the inner rotating image and the outer background image by a lightweight convolutional neural network, and identifies key semantic boundaries and texture dense regions in the inner rotating image and the outer background image. Then, the density of the image patch division is dynamically adjusted based on the gradient information of the feature maps obtained by the preliminary feature extraction, and smaller size image patches are used in texture complex regions to retain detailed features, and larger size image patches are used in smooth regions to improve computational efficiency. Through this adaptive division method, the computing resources are more effectively allocated, and the key image regions related to semantic alignment are focused on.

[0049] Further, the token sequence based on the image patches is input into a visual Transformer network for stacking calculation of multiple Transformer encoder layers. Each of the Transformer encoder layers is composed of two core modules of multi-head self-attention mechanism and feedforward neural network, and the gradient flow stability is maintained by residual connection and layer normalization operation between the Transformer encoder layers. In the multi-head self-attention mechanism, each token vector is projected into three different representations of query vector, key vector and value vector in parallel, the attention weight distribution is generated by calculating the dot product similarity of the query vector and all key vectors, and then the value vector is weighted and summed, so that each image patch can establish a direct association with all other patches in the sequence, thereby modeling the long distance visual dependency between the inner rotating image and the outer background image.

[0050] In particular, to enhance the interactive perception between the inner rotating image and the outer background image, a cross-image attention mechanism is introduced on the basis of the standard self-attention, which takes the token sequence of the inner rotating image as the source of the query vector, and takes the token sequence of the outer background image as the source of the key vector and the value vector, to construct a cross-image attention layer. Through this directional attention flow, the visual Transformer model can actively retrieve the context features matching the inner rotating pattern from the outer background image, to more accurately perceive the relative rotation state of the two, and 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.

[0051] In this embodiment, the token sequences of the internal rotation image and the external background image are integrated and the predicted rotation angle is generated by using the processing flow of global feature aggregation and regression output. After being processed by multiple Transformer encoder layers, the global context information of the entire token sequence is condensed into a special classification token inserted in advance. The special classification token carries the comprehensive representation of the alignment state of the internal rotation image and the external background image through interaction with all image block tokens. The final hidden state of the special classification token is extracted and mapped to the predicted rotation angle value by a regression head composed of multiple perception mechanisms.

[0052] In another possible implementation, an attention-based pooling feature aggregation strategy can be used for the integration process. The strategy dynamically calculates the importance weight of each token in the angle prediction task by applying self-attention pooling operation on all final layer tokens, and generates a global image representation by weighted sum of all token features based on the importance weight. The global image representation retains fine-grained feature information from the original image block, thereby effectively processing CAPTCHA images with complex texture patterns. The specific implementation of the regression head can use angle parameterization representation method, i.e., decomposing the calculated predicted rotation angle into joint prediction of sine value and cosine value, and then analyzing the continuous angle value by inverse trigonometric function to alleviate the boundary discontinuity problem of angle period.

[0053] In addition, the network structure based on the regression head includes two fully connected layers, and a non-linear transformation is introduced by a Gaussian error linear unit activation function in between. One of the fully connected layers projects the high-dimensional feature vector to a lower-dimensional hidden space, and the other fully connected layer outputs the final prediction value. Furthermore, a spectral normalization technique is introduced in the regression head to constrain the Lipschitz constant of the weight matrix, thereby improving the stability of model training. Based on the data flow of token sequence integration to angle generation, an end-to-end prediction pipeline of the visual Transformer model is formed, realizing accurate mapping from image block level local features to global rotation angle.

[0054] Further refinement based on the content described in step S33, 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: splicing the token sequence of the internal rotation image and the token sequence of the external background image to obtain a combined token sequence; calculating the correlation weight between each token in the combined token sequence, and obtaining the long-distance dependency relationship captured according to the correlation weight; fusing the token sequences of the inner rotation image and the outer background image according to the long-distance dependency relationship, to generate a unified feature representation as the integration result; generating the predicted rotation angle based on the integration result.

[0055] In this embodiment, the operation of splicing the token sequence of the inner rotation image and the token sequence of the outer background image into a combined token sequence is essentially a process of channel merging based on each token embedding dimension in the token sequence, wherein the token sequence of the inner rotation image contains N token vectors with a dimension of D, and the token sequence of the outer background image contains M token vectors with the same dimension. By splicing operation along the sequence dimension, a combined token sequence containing N+M token vectors is generated. In order to distinguish tokens of two different sources, each token vector is superimposed with a type encoding vector, and the type encoding is generated by a trainable parameter matrix, which is used to identify the image type to which the token belongs. At the same time, a special classification token is inserted at the beginning of the combined token sequence, which gradually learns the global context information of the entire sequence during the training process.

[0056] The correlation weight between each token in the combined token sequence is calculated by a multi-head self-attention mechanism, wherein each attention head of the multi-head self-attention mechanism independently calculates a query-key-value triple, wherein the query vector, the key vector and the value vector are linearly projected from the same combined token sequence, and the attention weight is calculated by using the scaled dot-product attention formula. The attention distribution matrix is generated by the dot product operation of the query vector and all key vectors, and is normalized by the Softmax function; each element of this attention distribution matrix represents the correlation strength between two tokens in the sequence, thereby capturing the long-distance dependency relationship between the inner rotation image blocks and the outer background image blocks.

[0057] In another feasible implementation, the correlation weight is calculated by using a hierarchical attention architecture, which first performs self-attention calculation within each image to establish local correlations between tokens of the inner rotation image and local correlations between tokens of the outer background image; then cross-image attention calculation is performed to model the interaction between tokens of the two images. Through this hierarchical design, the computational complexity can be effectively reduced while maintaining the modeling ability of long-distance dependency relationship. In particular, the cross-image attention layer can adopt an asymmetric calculation mode, allowing only the inner rotation image tokens as the query source and the outer background image tokens as the key-value source, forming a directional feature retrieval mechanism.

[0058] The process of weighting and fusing the token sequence according to the correlation weight is realized by weighted summation of the value vector of the attention mechanism. The weighted value vector set output by each attention head is spliced along the feature dimension and then fused through a linear transformation layer to generate a unified feature representation that not only retains the local feature information of the original image block but also incorporates the global context information captured through the attention mechanism. To further enhance the feature representation capability, the unified feature representation can be processed by a multi-layer feedforward neural network, each layer of which contains two fully connected layers and a Gaussian error linear unit activation function, and the training stability is maintained through residual connection and layer normalization in between.

[0059] The step of generating a predicted rotation angle based on the integration result includes: mapping the unified feature representation to a continuous rotation angle value, and performing weighted calculation on the continuous rotation angle through a ring weight loss function; obtaining the predicted rotation angle based on the weighted calculation result.

[0060] In this embodiment, the unified feature representation is mapped to a continuous rotation angle value through a regression head network module. The regression head is composed of two fully connected layers. One fully connected layer projects the high-dimensional unified feature representation to a hidden space, and the other fully connected layer maps the hidden features to an angle prediction value. To handle the special properties of the angle period, the output of the regression head can adopt a dual-channel design to predict the sine component and the cosine component of the rotation angle respectively, and then combine the final continuous rotation angle value through the inverse trigonometric function operation, solving the discontinuity problem of angle regression at the cycle boundary and improving the stability of model training.

[0061] When performing weighted calculation on the continuous rotation angle through the ring weight loss function, the Gaussian kernel transformation based on the angle difference is realized. In the transformation process based on the Gaussian kernel, the shortest arc length distance between the predicted rotation angle and the original rotation angle in the ring space is first calculated. The shortest arc length distance is obtained by taking the minimum value of the absolute difference and 360 degrees minus the absolute difference. Then, the shortest arc length distance is input into the Gaussian kernel function to generate the corresponding ring weight value. Further, the calculation based on the ring weight loss function adopts a negative log-likelihood form, guiding the predicted rotation angle distribution output by the visual Transformer model to be as close as possible to the 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 the angle error.

[0062] In another possible implementation, the continuous rotation angle is generated using a hybrid density network architecture that predicts parameters of a distribution function, such as weights, means, and variances of a mixture Gaussian distribution, based on which the annular weight loss function is adjusted to measure the difference between the predicted distribution function and the target distribution, for example, using the Wasserstein distance or the KL divergence.

[0063] In the prediction of the rotation angle based on the weighted calculation result, the back propagation optimization of the model parameters is involved. In this process, the gradient information of the predicted rotation angle is back propagated to the parameters of each layer of the regression head and the visual Transformer backbone network through the annular weight loss function, to drive the visual Transformer model to adjust the weights to minimize the loss value. In addition, to improve the optimization efficiency, the adaptive moment estimation algorithm can be used as the optimizer, and the learning rate can be dynamically adjusted by combining the learning rate warm-up and the cosine annealing strategy. The entire training process is performed in an end-to-end manner, and the visual Transformer model and the regression head network are optimized together to finally realize the stable mapping from the unified feature representation to the accurate rotation angle.

[0064] Specifically, based on the content of step S40 in the first embodiment, step S40 can be further refined into steps S41-S43. The step of restoring the verification code image based on the predicted rotation angle, the original rotation angle, and the preset annular weight loss function includes: Step S41, calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure; Step S42, generating an annular weight distribution for the minimum arc length distance using the preset environmental weight loss function, aligning the angle distribution of the predicted rotation angle with the annular weight distribution, and calculating a weighted loss value based on the alignment state; Step S43, adjusting the predicted rotation angle based on the weighted loss value, and restoring the verification code image based on the adjusted predicted rotation angle.

[0065] In this embodiment, the angle difference measurement method in the periodic geometric space is used to calculate the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure. In this calculation process, the predicted rotation angle and the original rotation angle are first normalized to the continuous interval of [0, 360) degrees, and the absolute difference Δθ between the two angles is calculated. Since the angle has periodic symmetry, the minimum arc length distance is determined by the formula min(Δθ, 360-Δθ), which ensures that the angle difference is always within the effective range of [0, 180] degrees. In specific implementation, this calculation process is completed through tensor operation, in which the angle difference of each sample is calculated independently and forms a difference vector.

[0066] And, the calculation of the minimum arc length distance needs to consider the boundary condition of the angle period, and when the predicted rotation angle approaches 0 degrees and the original rotation angle approaches 360 degrees, the standard deviation value calculation will produce a larger error, so the ring distance calculation can correctly identify the actual adjacent nature of the two. In order to improve the calculation accuracy, the angle value is uniformly converted to radian representation before calculation, and the discontinuity problem of the period boundary is avoided by using the characteristics of trigonometric functions. In the training process of the visual Transformer model, the minimum arc length distance is used as the basic error measurement, which directly reflects the deviation of the prediction result and the true value in the ring geometric space.

[0067] In another possible implementation, the calculation of the minimum arc length distance can use a vector geometry method, which converts each angle value into a two-dimensional coordinate vector on a unit circle, and derives the arc length difference 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, and the arc length distance is obtained by the inverse cosine function.

[0068] Further, based on the Gaussian kernel density estimation theory, a preset ring weight loss function is constructed to generate a ring weight distribution for the minimum arc length distance, and the ring weight distribution is centered on the original rotation angle and constructs a continuous probability density function in the ring space. Specifically, for any candidate angle θ_i, its ring weight is calculated by 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 ring weight distribution, P(θ) is the discrete angle distribution, and σ is the bandwidth parameter controlling the width of the distribution. This weight distribution reflects the punishment strength of the alignment error in the ring space, and the higher the weight of the region closer to the true angle.

[0069] And, the process of aligning the angle distribution of the predicted rotation angle with the ring weight distribution involves the similarity measurement of the probability distribution, specifically, the regression output of the visual Transformer model is converted to a discrete angle distribution P(θ) by the Softmax function, which represents the possibility of the model predicting each angle value as the correct result. Then the cross-entropy loss between P(θ) and the ring weight distribution W(θ) is calculated as the weighted loss value.

[0070] In another possible implementation, the adaptive bandwidth mechanism is adopted to generate the annular weight distribution. The bandwidth parameter σ of the Gaussian kernel is dynamically adjusted according to the training phase. A larger bandwidth is used at the beginning of training to provide a smooth gradient signal, and the bandwidth is gradually reduced as the training proceeds to improve the accuracy requirement. In addition, the annular weight function can be extended to a mixture Gaussian model, using a linear combination of multiple Gaussian kernels to model complex error distribution patterns, and better adapt to the characteristics of different verification code styles.

[0071] Further, the process of adjusting the predicted rotation angle according to the weighted loss value is implemented by a gradient back propagation algorithm, which takes the partial derivative of the model parameters and calculates the gradient direction of the loss function with respect to the predicted angle. The random gradient descent algorithm or its variants are used to update the weight matrix and bias term in the visual Transformer model, so that the visual Transformer model gradually reduces the difference between the predicted angle and the real angle in the annular space. The learning rate scheduling adopts a cosine annealing strategy to automatically adjust the learning rate during the training process, balancing the convergence speed and stability.

[0072] In addition, the process of restoring the verification code image by the adjusted predicted rotation angle involves a geometric transformation operation. The obtained angle prediction value is used as a parameter to perform an inverse rotation transformation on the internal rotation image. The specific operation includes: taking the image center as the rotation base point, establishing an affine transformation matrix, and calculating the color value of each pixel point after rotation by a bilinear interpolation algorithm. The internal rotation image after rotation and the external background image are recombined to generate the restored verification code image. The entire restoration process maintains the image quality and ensures that the rotation operation does not introduce obvious jagged or blurred distortion.

[0073] In the final stage of image restoration, a result verification process is performed. The restored verification code image is input into a pre-trained verification module to detect whether the internal rotation image and the external background image are correctly aligned in terms of semantics and vision. The verification result is compared with the original rotation angle to form a closed-loop feedback mechanism. For samples that fail to restore, the angle prediction error distribution characteristics are recorded for subsequent model optimization and data enhancement strategy adjustment. This self-verification mechanism ensures the reliability and robustness of the image restoration method in practical applications.

[0074] Further, the step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure includes: calculating the absolute difference between the predicted rotation angle and the original rotation angle; comparing the absolute difference with the complementary value of the data range to which the annular structure belongs, and taking the smaller value as the minimum arc length distance.

[0075] In the process of calculating the absolute difference between the predicted rotation angle and the original rotation angle, first of all, the predicted rotation angle and the original rotation angle need to be standardized. Through preprocessing, the predicted rotation angle and the original rotation angle are normalized to floating-point values within the range of 0 to 360 degrees, ensuring that the angle values of the two are in a unified measurement system. The calculation of the absolute difference is realized through the mathematical absolute value function, that is, 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 at the element level under the tensor operation framework, supporting batch processing of multiple verification code samples for angle comparison.

[0076] The determination of the complementary value of the data range of the annular structure is based on the periodicity of the angle data. In the annular angle space of 0 to 360 degrees, for any absolute difference Δθ, the complementary value is defined as 360 - Δθ. The complementary value reflects the distance measured from the other direction in the annular space. In specific implementation, the calculation of the complementary value is completed through scalar subtraction operation, and the result is always within the effective range of 0 to 360 degrees, maintaining the integrity of the annular geometry.

[0077] When comparing the absolute difference with the complementary value of the data range of the annular structure, the element-wise minimum selection algorithm is used. Through the parallel calculation of the absolute difference and its complementary value of each angle sample pair by the element-wise minimum selection algorithm, and then applying the minimum value function min(Δθ, 360 - Δθ) to determine the final minimum arc length distance. This comparison operation ensures that no matter which direction the angle difference is measured from, the shortest arc length path in the annular space is obtained, which conforms to the physical nature of the rotation verification code angle alignment.

[0078] In another possible implementation, the modulus operation optimization method is used to calculate the minimum arc length distance. The annular minimum distance is directly obtained through the formula min(Δθ mod 360, (-Δθ) mod 360), where mod represents modulus operation. Through mathematical transformation, the explicit complementary value calculation link is avoided, improving the calculation efficiency.

[0079] In addition, the final determination of the minimum arc length distance also needs to consider the numerical calculation accuracy problem. Due to the rounding error of floating-point calculation, when the angle difference is close to 180 degrees, a fault tolerance mechanism needs to be introduced to avoid numerical instability. When |Δθ - 180| < ε, the minimum arc length distance is forcibly set to 180 degrees, ensuring the certainty of the calculation result.

[0080] The calculation result of the minimum arc length distance will be used as a key input of the annular weight loss function, and its accuracy directly affects the direction and quality of model optimization. Through this rigorous minimum arc length distance calculation process, the angle difference measurement is fully consistent with the geometric characteristics of the annular space, providing a solid mathematical foundation for the image restoration task of the rotation verification.

[0081] In addition, the annular weight distribution of the preset environmental weight loss function is used to generate the minimum arc length distance, the angle distribution of the predicted rotation angle is aligned with the annular weight distribution, and the weighted loss value is calculated according to the alignment state. The step includes: The predicted rotation angle is converted into an angle probability distribution. The annular weight distribution of the preset environmental weight loss function is used to weight the angle probability distribution, and the weighted cross-entropy loss is calculated to obtain the weighted loss value.

[0082] In this embodiment, a discrete 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, and the center of each angle interval represents a candidate angle value. The predicted rotation angle is mapped to a K-dimensional logical vector through a fully connected layer, and then normalized through a Softmax function to generate an angle probability distribution that meets the probability axioms. Each element in the angle probability distribution represents the confidence of the predicted angle falling within the corresponding angle interval, thereby converting the regression problem into a probability distribution estimation problem.

[0083] In another possible implementation, a Gaussian mixture model parameterization method is used to generate the angle probability distribution. The visual Transformer model outputs multiple groups of parameters such as mixture weights, means, and variances. A continuous probability density function is constructed through a Gaussian kernel function, and then the continuous probability density function is discretely sampled to obtain an angle probability distribution, thereby more accurately modeling the uncertainty of angle prediction, and particularly suitable for processing complex verification code scenarios with multi-peak distribution characteristics.

[0084] In this embodiment, the annular weight distribution of the preset annular weight loss function is used to weight the angle probability distribution, and a target distribution is constructed based on a Gaussian kernel function. The minimum arc length distance between each discrete angle value and the true angle is calculated with the original rotation angle as the center, and the minimum arc length distance is input into the Gaussian kernel function to generate the annular weight distribution. When calculating the weighted cross-entropy loss, the difference between the angle probability distribution and the annular weight distribution is quantified as a loss value. Specifically, the weighted cross-entropy formula L = -Σ[W(θ_i) * log(P(θ_i))] is used, where W(θ_i) represents the annular weight distribution, and P(θ_i) represents the predicted angle probability distribution.

[0085] In another possible implementation, a temperature parameter is introduced to adjust the smoothness of the probability distribution to calculate the weighted loss value. By introducing an adjustable temperature parameter before calculating the logarithmic probability, the concentration of the probability distribution is controlled. A higher temperature value is used at the beginning of training to make the distribution smoother, facilitating the model to explore the global optimal solution. As the training progresses, the temperature value is gradually reduced to make the distribution more concentrated to improve the prediction accuracy. This annealing training strategy effectively balances the contradiction between exploration and utilization.

[0086] In this embodiment, the calculation of the weighted cross-entropy loss also needs to consider the numerical stability problem. In actual implementation, a small positive value ε is added when calculating the logarithmic probability to avoid the occurrence of infinity in the logarithmic operation, while ensuring that the sum of each element in the probability distribution is strictly 1. The weighted loss value is finally obtained by averaging the batch samples to obtain the overall loss, which is used as the objective function of the model parameter optimization. The entire conversion from the angle value to the probability distribution and the loss calculation process form a complete circular angle regression optimization framework, providing a reliable training mechanism for the accurate restoration of the rotation verification code.

[0087] Further, it can be seen that Figure 2 , Figure 2 is a flowchart of a second embodiment of the image restoration method based on the rotation verification code of the present application, based on Figure 2 , after the step of scheduling a task object to execute a task chain through the task flow arrangement template, the steps S50-S70 are further included: Step S50, obtaining a training sample based on the rotation verification code, and inputting the training sample into a pre-constructed initial visual feature network; Step S60, calculating the difference measure of the training sample through the initial visual feature network; Step S70, adjusting the parameter configuration of the initial visual feature network according to the difference measure to obtain the visual Transformer model.

[0088] In this embodiment, the acquisition of the training sample based on the rotation verification code involves a multi-source data acquisition and preprocessing process. Specifically, the training sample is composed of a verification code image sample and its corresponding real rotation angle label, and the training sample is constructed by combining programmatic generation and manual labeling. The verification code image sample covers rotation verification code variants of different design styles, including but not limited to key feature dimensions such as segmentation line style, texture complexity, and color mode. Each training sample contains a complete verification code image, a separated internal rotation image and an external background image, and an accurately measured real rotation angle value, which is obtained by calibration through a professional image processing tool, ensuring that the labeling accuracy reaches the sub-pixel level.

[0089] In another possible implementation, when obtaining the training samples, a data augmentation strategy is adopted to expand sample diversity. By applying data augmentation operations such as random rotation transformation, brightness adjustment, Gaussian noise injection, and elastic deformation to the basic verification code image, derived samples with different visual characteristics are generated. At the same time, the style transfer technology is used to adapt the verification code content to different visual styles, enhancing the adaptability of the visual Transformer model to various design variants.

[0090] In addition, in the present embodiment, when the training samples are input into the initially constructed initial visual feature network, an end-to-end deep learning training paradigm needs to be followed. The initial visual feature network adopts a ViT-based encoder architecture, including a backbone network composed of multiple Transformer modules. After the input training samples are processed through image blocking, linear projection, and position encoding, they are converted into token sequences to input the network. During the training process, a batch gradient descent algorithm is adopted to balance the training efficiency and memory consumption by dynamically adjusting the batch size.

[0091] The core of calculating the difference measure of the training samples by the initial visual feature network lies in constructing an effective loss function system. The calculation of the difference measure is based on the error between the predicted rotation angle and the real rotation angle, and a ring weight loss function is adopted as the main optimization target. The ring weight loss function fully considers the periodicity of angle data, and performs weighted processing on the angle error in the ring space through a Gaussian kernel function, so that the visual Transformer model can accurately perceive the ring characteristics of the angle deviation. In the early stage of training, an auxiliary loss function is additionally introduced to supervise the intermediate layer feature learning, ensuring that the network maintains stable gradient flow during the training process.

[0092] In another possible implementation, the difference measure can be calculated in combination with a contrast learning strategy. By constructing positive and negative sample pairs, the visual Transformer backbone network is required to not only accurately predict the rotation angle, but also to make the semantically aligned verification code samples close to each other in the feature space, while the unaligned samples are far away from each other in the feature space. In addition, when adjusting the parameter configuration of the initial visual feature network according to the difference measure, an optimization algorithm based on gradient backpropagation is adopted. By calculating the partial derivative of the loss function with respect to the parameters of each layer of the network, the parameter update direction and amplitude of the initial visual feature network are determined. The adaptive moment estimation algorithm is selected as the optimizer, and a hierarchical learning rate strategy is configured, with different learning rates set for the backbone network and the regression head network, to balance the training progress of the feature extraction and angle regression subtasks. During the training process, regularization techniques such as gradient clipping and weight decay are implemented to prevent model overfitting and improve the generalization ability.

[0093] Finally, after a complete training cycle and model selection process, the visual Transformer model is obtained. After completing the specified number of iterations of training on the training set, the model performance is evaluated on the independent validation set, and the model parameters with the smallest validation loss are selected as the final visual Transformer model. The performance evaluation of the visual Transformer model not only considers the average error of angle prediction, but also focuses on key indicators such as success rate and robustness. The final visual Transformer model has strong feature extraction and angle regression capabilities, can accurately understand the image content of the rotation verification code and predict its rotation state, and improves the restoration accuracy.

[0094] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the image restoration method based on the rotation verification code of the present application. More forms of simple transformation based on this technical concept are within the protection scope of the present application.

[0095] The present application provides an image restoration device based on a rotation verification code, which comprises at least one processor and a memory in communication connection with the at least one processor. 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 the rotation verification code in the above-mentioned embodiment one.

[0096] Reference will now be made to the drawings, in which Figure 3 which shows a structural schematic diagram of an image restoration device based on a rotation verification code suitable for implementing the embodiments of the present application. The image restoration device based on a rotation verification code in the embodiments of the present application can include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistant: personal digital assistant), PADs (Portable Application Description: tablet computers), and the like, as well as fixed terminals such as digital TVs, desktop computers, and the like. Figure 3 The image restoration device based on a rotation verification code shown is only an example and should not impose any limitation on the functions and use range of the embodiments of the present application.

[0097] As Figure 3As shown, the rotation authentication-based image restoration device can include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. In the random access memory 1004, various programs and data required for the rotation authentication-based image restoration device to operate are also stored. The processing device 1001, the read only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the rotation authentication-based image restoration device to communicate with other devices wirelessly or by wire to exchange data. Although the rotation authentication-based image restoration device with various systems is shown in the figure, it should be understood that all the shown systems are not required to be implemented or possessed. More or fewer systems can be alternatively implemented or possessed.

[0098] In particular, according to embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program carrying computer program code for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through a communication device, or installed from the storage device 1003, or installed from the read only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of the embodiments of the present disclosure are performed.

[0099] The image restoration device based on the rotation verification code provided in the application adopts the image restoration method based on the rotation verification code in the above embodiment, and can solve the technical problems of insufficient image feature alignment capability, difficulty in modeling long-range dependency between image blocks, and low rotation alignment state perception accuracy. Compared with the prior art, the beneficial effects of the image restoration device based on the rotation verification code provided in the application are the same as those of the image restoration method based on the rotation verification code provided in the above embodiment, and other technical features in the image restoration device based on the rotation verification code are the same as those disclosed in the above embodiment method, and will not be repeated here.

[0100] It should be understood that parts of the present application can be realized by 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 one or more embodiments or examples in a suitable manner.

[0101] The above is merely specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

[0102] The present application provides a storage medium, which is a computer readable storage medium, has computer readable program instructions (i.e. computer programs) stored thereon, and the computer readable program instructions are used to execute the image restoration method based on the rotation verification code in the above embodiment.

[0103] The computer readable storage medium provided in the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination of the above. More specific examples of the computer readable storage medium may include, but are not limited to, an electric connection with one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present 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 can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), or any suitable combination of the above.

[0104] The above computer readable storage medium may be contained in the image restoration device based on the rotation code, or may exist separately without being assembled into the image restoration device based on the rotation code.

[0105] The above computer readable storage medium carries one or more programs, which, when executed by the image restoration device based on the rotation code, enable the image restoration device based on the rotation code to implement the technical content of the above-mentioned image restoration method based on the rotation code.

[0106] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0107] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.

[0108] The modules involved in the embodiments of the present application can be implemented in software or hardware. In some cases, the names of the modules do not limit the modules themselves.

[0109] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., computer programs) for executing the above-mentioned image restoration method based on the rotation verification code. It can solve the technical problems of insufficient image feature alignment capability, difficulty in modeling long-range dependency between image blocks, and low accuracy of rotation alignment state perception. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the image restoration method based on the rotation verification code provided by the above-mentioned embodiments.

Claims

1. A method for image restoration based on a rotation verification code, characterized in that, The image restoration method based on the rotation verification code comprises the following steps: An image of a verification code is acquired, and an original rotation angle is obtained by analyzing the image of the verification code; The image of the verification code is split into an internal rotation image and an external background image, and the internal rotation image and the external background image are input into a visual Transformer model; A self-attention mechanism of the visual Transformer model is used to capture long-distance dependency relationships of the internal rotation image and the external background image, and a predicted rotation angle is output based on the long-distance dependency relationships; The image of the verification code is restored by the predicted rotation angle, the original rotation angle and a preset annular weight loss function.

2. The rotation code-based image restoration method of claim 1, wherein, The step of capturing long-distance dependency relationships of the internal rotation image and the external background image by using the self-attention mechanism of the visual Transformer model and outputting a predicted rotation angle based on the long-distance dependency relationships comprises: The internal rotation image and the external background image are respectively divided into a plurality of image blocks, and each image block is converted into a token sequence; The token sequence is input into a visual Transformer network, and a global correlation between each image block is analyzed by using a self-attention mechanism; 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.

3. The rotation code-based image restoration method of claim 2, wherein, The step of integrating token sequences of the internal rotation image and the external background image and generating the predicted rotation angle based on the integration result comprises: Token sequences of the internal rotation image and the external background image are spliced to obtain a combined token sequence; Correlation weights between each token in the combined token sequence are calculated, and the long-distance dependency relationships are captured according to the correlation weights; According to the long-distance dependency relationships, the token sequences of the internal rotation image and the external background image are weightedly fused to generate a unified feature representation as the integration result; The predicted rotation angle is generated based on the integration result.

4. The rotation code-based image restoration method of claim 3, wherein, The step of generating the predicted rotation angle based on the integration result comprises: The unified feature representation is mapped to a continuous rotation angle value, and the continuous rotation angle is weightedly calculated by using an annular weight loss function; The predicted rotation angle is obtained based on the weighted calculation result.

5. The rotation code-based image restoration method of claim 1, wherein, The step of restoring the image of the verification code by using the predicted rotation angle, the original rotation angle and a preset annular weight loss function comprises: A minimum arc length distance between the predicted rotation angle and the original rotation angle in an annular structure is calculated; An annular weight distribution is generated for the minimum arc length distance by using a preset environmental weight loss function, the angle distribution of the predicted rotation angle is aligned with the annular weight distribution, and a weighted loss value is calculated according to the alignment state; The predicted rotation angle is adjusted according to the weighted loss value, and the image of the verification code is restored by using the adjusted predicted rotation angle.

6. The rotation code-based image restoration method of claim 5, wherein, The step of calculating the minimum arc length distance between the predicted rotation angle and the original rotation angle in the annular structure comprises: An absolute difference value between the predicted rotation angle and the original rotation angle is calculated; The absolute difference value is compared with a complementary value of a data range to which the annular structure belongs, and the smaller value is taken as the minimum arc length distance.

7. The rotation code-based image restoration method of claim 5, wherein, The step of generating an annular weight distribution for the minimum arc length distance by using the preset environmental weight loss function, aligning the angle distribution of the predicted rotation angle with the annular weight distribution, and calculating a weighted loss value according to an alignment state, comprises: Converting the predicted rotation angle into an angle probability distribution; The angle probability distribution is weighted by using the annular weight distribution of the preset environmental weight loss function, and a weighted cross-entropy loss is calculated to obtain the weighted loss value.

8. The rotation code-based image restoration method according to any one of claims 1 to 7, wherein The image restoration method based on the rotation verification code further comprises: Obtaining a training sample based on the rotation verification code, and inputting the training sample into an initial visual feature network constructed in advance; Calculating a difference measure of the training sample by using the initial visual feature network; Adjusting a parameter configuration of the initial visual feature network according to the difference measure to obtain the visual Transformer model.

9. An image restoration apparatus based on a rotation authentication code, characterized by comprising: The device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the image restoration method based on the rotation verification code according to any one of claims 1 to 8.

10. A storage medium, characterized by The storage medium is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by the processor to implement the steps of the image restoration method based on the rotation verification code according to any one of claims 1 to 8.

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

  • Remote sensing image rotating target detection method

    CN120147865A

Cited By

  • Recognition training system for rotary verification code

    CN122116377A