Image verification code data automatic generation method, system, equipment and medium
By using multimodal feature extraction and cosine similarity calculation, combined with a diffusion model to generate CAPTCHA images, the problems of unstable generation quality and poor scene relevance in existing technologies are solved, achieving high-quality, diverse, and secure CAPTCHA generation.
Patent Information
- Application Number
- CN202511063749.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-31
- Publication Date
- 2025-12-16
AI Technical Summary
Existing CAPTCHA generation methods suffer from unstable generation quality, poor scene relevance, and a lack of effective image reference mechanisms, resulting in significant deviations between the generated CAPTCHA images and the expected scenes, making it difficult to meet the requirements of high security and diversity.
The pre-selected images and scene description text are encoded into feature vectors in a shared feature space through a multimodal feature extraction model. Cosine similarity is calculated and sorted in descending order. Pre-selected images with high relevance are selected as references. A CAPTCHA image is generated by combining a diffusion model. The image library is optimized through image quality assessment and storage mechanisms.
It achieves high matching between CAPTCHA images and expected scenarios, improves the stability and diversity of generation quality, and enhances the security and scalability of the CAPTCHA system.
Smart Images

Figure CN121147337A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image generation, in particular to an image verification code data automatic generation method, system, device and medium. BACKGROUND
[0002] As an important means to resist network attacks and prevent automated programs, the generation quality and diversity of verification codes directly affect the security performance of the system. Traditional verification code generation systems usually rely on predefined templates and simple image transformation techniques to create verification codes, which can meet basic security needs, but have obvious shortcomings in image quality and scene diversity.
[0003] With the development of deep learning technology, the industry has begun to use generative adversarial networks or diffusion models and other artificial intelligence technologies to generate verification code images. These methods directly control the image generation process through text prompts, which improves the quality of generated images, but still faces problems such as unstable generation quality and poor scene relevance. In particular, when generating specific scene verification codes, the lack of effective image reference mechanisms results in a large deviation between the generated verification code images and the expected scene. SUMMARY
[0004] The present application provides an image verification code data automatic generation method, system, device and medium, which reduces the deviation between the generated verification code image and the expected scene.
[0005] In a first aspect, the present application provides an image verification code data automatic generation method, which includes: encoding a preselected image into a first feature vector through an image encoder of a multi-modal feature extraction model; receiving a scene description text describing a scene to be generated for a verification code, and encoding the scene description text into a second feature vector through a text encoder of the multi-modal feature extraction model, wherein the text encoder and the image encoder share a feature vector space; calculating the cosine similarity between the second feature vector and the first feature vector, and sorting the first feature vector in descending order according to the size of the cosine similarity to generate a target sequence; selecting the first feature vector in the target sequence that is before a preset position, and obtaining a target preselected image corresponding to the first feature vector that is before the preset position, the target preselected image being an image in the preselected image; inputting the scene description text and the target preselected image into an image generation model to generate a verification code image.
[0006] By adopting the technical scheme, the preselected images and the scene description text are respectively encoded into feature vectors in a shared feature space through a multi-modal feature extraction model, so that semantic alignment of the text and the images is realized. By calculating the cosine similarity and performing descending order sorting, the system can accurately find the preselected image that is most matched with the target scene. By selecting the reference image within the preset position range, the relevance of the selected image is ensured, and randomness is also increased. Finally, the scene description text and the selected target preselected image are jointly input into an image generation model, so as to reduce the deviation of the generated verification code image from the expected scene.
[0007] Optionally, after the verification code image is generated, the method further includes: encoding the verification code image into a third feature vector through the image encoder, and storing the third feature vector and the verification code image into a vector database.
[0008] By adopting the technical scheme, the generated verification code image is encoded into a third feature vector and stored into a vector database, so that a dynamically updated image resource library is established. Since the same image encoder is used for encoding, it is ensured that the feature representation of the newly generated image is in the same feature space as the original preselected image, so that these verification code images can be used as new preselected images to participate in the subsequent generation process. This positive feedback mechanism not only continuously expands the image library capacity of the system, but also continuously optimizes the reference resources by accumulating high-quality verification code images, thereby improving the scalability and generation effect of the system.
[0009] Optionally, the encoding of the preselected image into the first feature vector through the image encoder of the multi-modal feature extraction model includes: performing image size adjustment and pixel normalization on the preselected image to generate a standardized preselected image; inputting the standardized preselected image into the image encoder of the multi-modal feature extraction model to generate a feature mapping of the preselected image; and generating a first feature vector of a fixed dimension according to the feature mapping.
[0010] By adopting the technical scheme, the standardized preselected image is generated through size adjustment and pixel normalization preprocessing, so that the standardization of the input data is ensured, and the differences in size and pixel distribution of images from different sources are eliminated. By inputting the standardized preselected image into the image encoder to generate the feature mapping and then converting it into the first feature vector of the fixed dimension, the unified representation of the image features is realized. This standardized feature extraction process not only improves the stability and reliability of the feature encoding, but also ensures that all preselected images can be converted into the unified format feature vector that is convenient for calculation and comparison, thereby providing a reliable data basis for the subsequent similarity calculation.
[0011] Optionally, the receiving the scene description text for describing the to-be-generated verification code scene comprises: acquiring a plurality of candidate description texts of the to-be-generated verification code scene from a text description library according to a preset scene type; performing text normalization processing on the candidate description texts; and selecting a target number of scene description texts from the processed candidate description texts, wherein the target number is used to determine a to-be-generated verification code image batch number.
[0012] By adopting the above technical solution, the candidate description texts are batched and acquired from the text description library of the preset scene type, and are normalized processed, so as to ensure the consistency and quality standard of the text format. The target number is set to select from the processed candidate texts, which not only realizes the diversity coverage of the verification code scene, but also establishes an automatic control mechanism of the generated batch. This text selection and batch processing method based on the scene type not only improves the running efficiency of the system, but also guarantees the quality and randomness of the generated result through the combination of normalization processing and random selection, effectively enhancing the security and practicability of the verification code system.
[0013] Optionally, the calculating the cosine similarity between the second feature vector and the first feature vector comprises: performing dot product operation on the second feature vector and the first feature vector to generate an operation result; calculating the product of the modulus of the second feature vector and the modulus of the first feature vector to generate a product result; and dividing the operation result by the product result to generate the cosine similarity.
[0014] By adopting the above technical solution, the cosine similarity between the feature vectors is calculated through the standardization method of dot product operation and modulus length calculation, which eliminates the influence of vector length on the similarity calculation, so that the similarity value only depends on the direction of the vector. This calculation method not only provides an accurate quantitative standard for the similarity degree of text features and image features, but also ensures the comparability of the similarity value through normalization processing, providing an objective and reliable numerical basis for the system to select the most matched preselected image. This standardized similarity calculation method effectively improves the accuracy of image-text matching, and further improves the quality and scene relevance of the verification code generation.
[0015] Optionally, the inputting the scene description text and the target preselected image into an image generation model to generate a verification code image comprises: generating a random seed value by using a random number generator, and setting the random seed value as a generation parameter of the image generation model; inputting the scene description text as a text condition and the target preselected image as an image condition into a diffusion model guided by text and image; and on the basis of the random seed value, iteratively processing the text condition and the image condition by the diffusion model to generate a verification code image.
[0016] By adopting the technical scheme, the generation process of the diffusion model is initialized by setting the random seed value, and the scene description text and the target preselected image are input as double condition, realizing the joint control of the text semantics and the image visual features. The iteration processing is performed on the basis of the random seed value, which not only ensures the randomness and unpredictability of the generation process, but also ensures the quality and relevance of the generation result through the continuous guidance of the text condition and the image condition. The iterative generation mechanism based on the random seed and the double condition effectively improves the security of the verification code image and reduces the risk of being cracked by the machine learning model while maintaining the overall style and semantic consistency of the verification code image.
[0017] Optionally, after the generation of the verification code image, the method further includes: performing quality assessment on the verification code image according to a preset image quality assessment model to obtain a quality assessment score; determining the verification code image with the quality assessment score greater than a preset score as a to-be-encoded image; and performing data cleaning processing on the to-be-encoded image to generate a target verification code image.
[0018] By adopting the technical scheme, the generated verification code image is scored and screened by the preset image quality assessment model, and the score threshold mechanism is combined to ensure that only high-quality images can enter the subsequent processing flow. The to-be-encoded image that passes the quality assessment is subjected to data cleaning processing, which effectively removes possible interference factors and performs standardized processing to generate a target verification code image. This multi-level quality control mechanism not only ensures the visual quality and use security of the verification code image, but also improves the standardization and practicality of the image through data cleaning, thereby providing stable and reliable image resources for the verification code system.
[0019] In a second aspect, the present application provides an image verification code data automatic generation system, which comprises a first encoding module, a second encoding module, a calculation module, a selection module and a generation module, wherein, The first encoding module is configured to encode a preselected image into a first feature vector by an image encoder of a multi-modal feature extraction model; the second encoding module is configured to receive a scene description text describing a scene to be generated for a verification code, and encode the scene description text into a second feature vector by a text encoder of the multi-modal feature extraction model, wherein the text encoder and the image encoder share a feature vector space; the calculation module is configured to calculate a cosine similarity between the second feature vector and the first feature vector, sort the first feature vectors in descending order according to the size of the cosine similarity, and generate a target sequence; the selection module is configured to select a first feature vector in the target sequence before a preset position, and obtain a target preselected image corresponding to the first feature vector before the preset position, the target preselected image being an image in the preselected images; and the generation module is configured to input the scene description text and the target preselected image into an image generation model to generate a verification code image.
[0020] In a third aspect, the present application provides an electronic device, which adopts the technical scheme as follows: comprising a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory, so that the electronic device executes the computer program of any one of the image verification code data automatic generation methods.
[0021] In a fourth aspect, the present application provides a computer readable storage medium, which adopts the technical scheme as follows: storing a computer program capable of being loaded by a processor and executing any one of the image verification code data automatic generation methods.
[0022] In summary, the present application includes at least one of the following beneficial technical effects: By encoding the preselected images and the scene description text into feature vectors in a shared feature space through a multi-modal feature extraction model, semantic alignment of the text and the image is achieved. By calculating the cosine similarity and performing descending order sorting, the system can accurately find the preselected image that best matches the target scene. By selecting the reference image within the preset position range, the relevance of the selected image is ensured, and randomness is increased. Finally, the scene description text and the selected target preselected image are input into the image generation model, reducing the deviation of the generated verification code image from the expected scene. BRIEF DESCRIPTION OF DRAWINGS
[0023] Figure 1 is a flowchart of an image verification code data automatic generation method provided by an embodiment of the present application; Figure 2 is a structural schematic diagram of an image verification code data automatic generation system provided by an embodiment of the present application; Figure 3 Figure 1 is a structural schematic diagram of an electronic device provided by an embodiment of the present application.
[0024] Marker explanation: 1000, electronic device; 1001, processor; 1002, communication bus; 1003, user interface; 1004, network interface; 1005, memory. DETAILED DESCRIPTION
[0025] In order to enable persons skilled in the art to better understand the technical solutions in the specification, the technical solutions in the specification will be clearly and completely described below in combination with the drawings in the embodiments of the specification. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments.
[0026] In the description of the embodiments of the present application, the words "exemplary", "for example", or "for instance" are used to mean serving as an example, instance, or illustration. Any embodiment or design solution described as "exemplary", "for example", or "for instance" in the embodiments of the present application should not be interpreted as being more preferred or having more advantages than other embodiments or design solutions. Rather, the words "exemplary", "for example", or "for instance" are used herein to represent a specific way of implementing the relevant concept.
[0027] As an important means of preventing network attacks and automated programs, verification codes are widely used in Internet applications. Traditional verification code generation methods mainly rely on predefined templates and simple image transformation techniques, such as rotation, distortion, and adding noise, to increase the difficulty of recognition. However, such methods have obvious shortcomings in terms of image diversity and quality, and require high maintenance costs.
[0028] With the development of deep learning technology, verification code generation methods based on generative models have gradually emerged. A typical scheme is to use diffusion models such as Stable Diffusion to generate verification code images through text prompts. Diffusion models are a class of generative models that generate new images by adding and removing noise from images. The working principle includes two processes: forward diffusion and backward diffusion. The forward process gradually adds Gaussian noise to the original image through multiple iterations until it is completely randomized. The backward process starts from random noise and gradually predicts and removes noise through a trained neural network to generate the target image. Stable Diffusion is an efficient implementation of diffusion models. It performs the diffusion process in the compressed latent space to reduce computational complexity and uses text conditions and cross-attention mechanisms to guide image generation. In the present invention, Stable Diffusion receives scene description text and retrieved high-quality images as input conditions, generates diversified verification code images through the backward diffusion process and random seed control.
[0029] However, existing generation model-based methods often require the design of sophisticated text prompt words to ensure the quality of generation, which not only increases the complexity of making verification codes, but also makes it difficult to guarantee the stability and diversity of generated images. Especially when multiple scene verification code images need to be generated in batches, designing appropriate text prompt words for each scene is not only time-consuming, but also difficult to ensure the generation effect. In addition, existing methods are prone to unstable generation quality, single image style and other problems when dealing with complex scenes, and lack effective quality control mechanisms, which may pose a security risk to the generated verification codes. Therefore, there is an urgent need for a verification code generation method that can simplify the design of text prompt words, improve the stability of generation quality, enhance image diversity, and have automated batch processing capabilities.
[0030] Figure 1 is a flowchart of an image verification code data automatic generation method provided by an embodiment of the present application. As shown in Figure 1 the method comprises S101-S105: S101, encoding a preselected image into a first feature vector by an image encoder of a multi-modal feature extraction model.
[0031] In the process of implementing image verification code data automatic generation, a high-quality preselected image feature vector library needs to be established first. The image encoder of the multi-modal feature extraction model (Contrastive Language-Image Pretraining, CLIP for short, which is a deep learning model capable of processing image and text data simultaneously) is used in the present application to extract feature vectors from preselected images.
[0032] Specifically, the input preselected image is first preprocessed, including uniformly adjusting the image to a standard size of 224x224 pixels, and normalizing the image pixel values (i.e., scaling the pixel values to between 0 and 1) to ensure the consistency of the input data. Then, the standardized preselected image is input into the image encoder of the CLIP model, which extracts the visual features of the image through a multi-layer convolutional neural network and generates a feature map of the preselected image.
[0033] Next, the feature map is compressed into a first feature vector of fixed dimension (e.g., 512 dimensions) through global average pooling and other operations, which contains high-level semantic feature information of the preselected image. This encoding method can convert the visual content of the image into a compact numerical representation, facilitating subsequent similarity calculation and matching with text features. In this way, the system can efficiently store and retrieve the feature information of a large number of preselected images, providing high-quality visual references for subsequent verification code generation, while ensuring the style diversity and content relevance of the generated images.
[0034] Based on the above embodiments, as an optional implementation, in S101, the preselected image is encoded into a first feature vector by an image encoder of the multi-modal feature extraction model, which specifically includes S11-S13: S11, image size adjustment and pixel normalization are performed on the preselected image to generate a standardized preselected image.
[0035] S12, the standardized preselected image is input into the image encoder of the multi-modal feature extraction model to generate a feature map of the preselected image.
[0036] S13, a first feature vector of fixed dimension is generated according to the feature map.
[0037] Before image feature extraction, the preselected image needs to be standardized to ensure the consistency of input data. Since the preselected image may come from different sources, its size and pixel value range may vary greatly, which will affect the quality of feature extraction. Therefore, the system first uses the bilinear interpolation algorithm to uniformly adjust the size of the preselected image to 224x224 pixels, which is the standard input size of the CLIP model; then the image pixel values are normalized, the pixel values of the RGB three channels are mapped from the range of 0-255 to 0-1, and the mean and standard deviation are normalized according to the standard of the pre-trained model, to generate a standardized preselected image.
[0038] The standardized image is input into the image encoder of the multi-modal feature extraction model CLIP, which contains a multi-layer convolutional neural network. Through layer-by-layer feature extraction and transformation, the visual information of the image is encoded into multi-channel feature maps. These feature maps contain local features and global semantic information of the image, but the dimension is high and not conducive to subsequent processing. In order to obtain compact and informative feature representation, the system performs global average pooling operation on the feature map to compress the spatial dimension information, and finally generates a 512-dimensional first feature vector.
[0039] S102, receiving a scene description text describing the scene to be generated, encoding the scene description text into a second feature vector by a text encoder of the multi-modal feature extraction model, wherein the text encoder and the image encoder share a feature vector space.
[0040] In order to realize the automatic generation of the verification code image, the system needs to understand the content of the verification code scene that the user expects to generate. This application guides the generation process of the verification code through the scene description text, which can be obtained from a pre-established text description library or directly input by the user.
[0041] In processing the scene description text, first, the text is normalized, including removing special characters, unifying case, tokenization, etc., to ensure the consistency of the text format.
[0042] Next, the processed scene description text is encoded using a text encoder that belongs to the same multi-modal feature extraction model CLIP as the image encoder. The text encoder uses a Transformer architecture, a neural network structure based on self-attention mechanism that can effectively process sequence data, to convert the text content into a second feature vector with the same dimension as the image feature vector. What is particularly important here is the design of the text encoder sharing the feature vector space with the image encoder, which means that the feature vectors output by the two encoders are in the same mathematical space and are directly comparable. This shared space design is achieved through the contrastive learning training of the CLIP model, which makes semantically related images and texts closer in the feature space, while unrelated content is farther apart. Such a design enables the system to accurately find the pre-selected image that best matches the semantic of the scene description text, thereby generating a verification code image that meets the expected scene.
[0043] At the same time, since the dimension of the feature vector is fixed and has good semantic expression ability, the system can efficiently process scene description texts of different lengths and contents, providing reliable semantic guidance for subsequent similarity calculation and image generation.
[0044] Based on the above embodiments, as an optional implementation, in S102, the received scene description text for describing the to-be-generated verification code scene specifically includes S21-S24: S21, acquires a plurality of candidate description texts for the to-be-generated verification code scene from a text description library according to a preset scene type.
[0045] S22, performs text normalization processing on the candidate description texts.
[0046] S23, selects a target number of scene description texts from the processed candidate description texts, wherein the target number is used to determine the number of batches of verification code images to be generated.
[0047] In actual application, the verification code image usually needs to cover multiple different scene types, in order to realize batch generation and automation, the system needs to effectively manage and process the scene description text. First, the system retrieves relevant candidate description texts from the text description library according to the pre-defined scene types (such as natural scenery, buildings, animals, vehicles, etc.).
[0048] The text description library stores high-quality description texts that have been manually written and reviewed. These texts are classified and labeled by scene, making them easy to search and use. After obtaining the candidate description texts, the system performs normalization processing on these texts, including removing special characters and unnecessary spaces, unifying case formats, performing word segmentation and lemmatization, and other operations to ensure the consistency and standardization of the text format. Normalization processing helps improve the accuracy and reliability of subsequent text encoding.
[0049] Subsequently, the system randomly selects the corresponding number of scene description texts from the processed candidate description texts according to the target number set by the user. The target number directly determines the number of batches of verification code images that the system will generate. For example, if the target number is set to 10, the system will select 10 different scene description texts and ultimately generate 10 batches of verification code images. This scene type-based text selection mechanism not only ensures the diversity of generated images but also improves the system's running efficiency through batch processing.
[0050] S103, calculate the cosine similarity between the second feature vector and the first feature vector, sort the first feature vector in descending order according to the cosine similarity, and generate a target sequence.
[0051] To find the most suitable image from the preselected image library as a reference for generating verification codes, this application uses the cosine similarity calculation method to measure the semantic relevance between scene description texts and preselected images. Cosine similarity is an index that measures the directional similarity of two vectors, with a value range of -1 to 1. The closer the value is to 1, the closer the direction of the two vectors, which means the more relevant the semantic content of the text and image.
[0052] The specific calculation process is to perform dot product operation between the second feature vector (text feature) and the first feature vector (image feature), get the inner product between the vectors, and then divide by the product of the lengths of the two vectors (the square root of the sum of the squares of the components of the vector). The advantage of this calculation method is that it only focuses on the direction of the vector and is not affected by the length of the vector, which can more accurately reflect the correlation between the text and the image in the semantic space.
[0053] After calculating the cosine similarity of all preselected images and target scene description texts, the system sorts the first feature vector in descending order according to the similarity value, generating a target sequence. This sorting method ensures that the images with the strongest semantic relevance are placed at the front of the sequence, providing a priority basis for subsequent image selection. Through this cosine similarity-based sorting mechanism, the system can efficiently and accurately locate the preselected image that best meets the scene description requirements, thereby improving the quality and scene relevance of the final generated verification code images. This sorting result also has good interpretability, making it easy for the system to analyze and control the results.
[0054] On the basis of the above embodiments, as an optional implementation, in S103, the calculation of the cosine similarity between the second feature vector and the first feature vector specifically includes S31-S33: S31, the second feature vector and the first feature vector are dot product operation, generating operation result.
[0055] S32, calculate the product of the modulus of the second feature vector and the modulus of the first feature vector, generate product result.
[0056] S33, divide the operation result by the product result, generate cosine similarity.
[0057] In the process of generating the verification code, accurately calculating the similarity between the text features and the image features is a key step for selecting appropriate reference images. The present application uses cosine similarity as a measure, which focuses on the angle between vectors and can effectively reflect the directional similarity of feature vectors in high-dimensional space.
[0058] The specific calculation process first performs dot product operation on the second feature vector obtained by text encoding and the first feature vector obtained by image encoding. This operation multiplies the corresponding dimensions of the two 512-dimensional vectors and sums them up to get a scalar value as the operation result. This result reflects the matching degree of the two vectors in each dimension.
[0059] Then, the modulus of each of the two feature vectors is calculated, that is, the square of each component of the vector is added and then the square root is taken, and then the two modulus lengths are multiplied to obtain the product result, which is used to normalize the dot product value.
[0060] Finally, the dot product operation result is divided by the modulus product result to obtain a cosine similarity value with a value range of -1 to 1. This calculation method eliminates the influence of vector length, so that the similarity value only depends on the direction of the vector, thereby more accurately reflecting the semantic relevance of text description and image content.
[0061] S104, select the first feature vector in the target sequence whose ranking is before the preset position, and obtain the target preselected image corresponding to the first feature vector whose ranking is before the preset position, the target preselected image being an image in the preselected image.
[0062] After obtaining the target sequence arranged in descending order of cosine similarity, the system needs to select appropriate preselected images as reference for generating verification codes. In order to ensure image quality while increasing the randomness and diversity of the generated results, the present application sets a preset position parameter (for example, top-k, k can be set to 10 or 20, etc.), and selects from the feature vectors before the preset position.
[0063] In implementation, the system first determines the value k of the preset position, which determines the range of the candidate image. The setting of k value needs to balance between similarity reliability and diversity: too small k value will limit the diversity of generated images, and too large k value may introduce images with weak relevance. After determining the candidate range, the system randomly selects a first feature vector whose ranking position in the target sequence is before the preset position k, and obtains the target preselected image corresponding to the feature vector through the mapping relationship between the feature vector and the original preselected image.
[0064] This selection mechanism ensures that the selected target preselected image has both high semantic relevance and uncertainty brought by random selection, effectively avoiding the problem of single generation result caused by using fixed highest similarity image. At the same time, this selection method also improves the anti-attack ability of the system, because even if the same scene description text is used, different reference images may be used each time to generate the verification code image, increasing the security of the verification code. Through this flexible selection mechanism, the system can significantly improve the diversity and randomness of the verification code image while ensuring the generation quality.
[0065] S105, inputting the scene description text and the target preselected image into the image generation model to generate the verification code image.
[0066] After obtaining the matching scene description text and target preselected image, the system uses the image generation model to generate the final verification code image. This application uses Stable Diffusion (a deep learning model that generates images through an iterative denoising process) based on diffusion model as the image generation model, and combines IP-Adapter (a model component for enhancing image condition control ability) to realize the generation process guided by both text and image.
[0067] In the generation process, a random number generator is first used to generate a random seed value, which is used to initialize the noise distribution of the diffusion model to ensure a certain randomness in each generation process. The system takes the scene description text as the text condition and guides the semantic content in the generation process through the cross-attention mechanism; at the same time, the target preselected image is converted into an image condition through IP-Adapter to control the visual style and structural features of the generated image. The diffusion model gradually transforms random noise into a clear image through a preset number of inference steps (e.g. 20 steps), and considers the guidance of both text and image conditions in each iteration step to ensure that the generated verification code image meets the semantic requirements of the scene description and inherits the high-quality visual features of the preselected image. This dual-guided generation method can significantly improve the quality and stability of the generated image, while the setting of the random seed ensures the diversity of the generation result.
[0068] The generated CAPTCHA images inherit the high-quality visual features of the pre-selected images and incorporate semantic information specific to the scene through text guidance, ultimately achieving automated generation of high-quality, diverse, and scene-relevant CAPTCHA images. This generation method not only improves the efficiency of CAPTCHA production but also provides better security and user experience for the CAPTCHA system.
[0069] Based on the above embodiments, as an optional implementation, in S105, inputting the scene description text and the target pre-selected image into the image generation model to generate the verification code image specifically includes S51-S53: S51 uses a random number generator to generate a random seed value, and sets the random seed value as the generation parameter of the image generation model.
[0070] In the process of generating CAPTCHA images, to ensure the randomness and unpredictability of the generated results, the system needs to reasonably set the random seed value of the image generation model. This application uses a cryptographically secure random number generator (such as the Mersenne Twister algorithm) to generate the random seed value, which is usually a 32-bit or 64-bit integer. The random seed value directly affects the initial noise distribution of the diffusion model during the denoising process, and therefore plays a decisive role in the detailed features of the final generated image. The system sets the generated random seed value as the generation parameter of the Stable Diffusion model to initialize the model's sampling process. This random seed-based generation mechanism ensures that even when using the same scene description text and target pre-selected image, each generated CAPTCHA image will exhibit unique visual details.
[0071] S52, the scene description text is input as a text condition and the target pre-selected image is input as an image condition into the image-text guided diffusion model.
[0072] In the process of generating CAPTCHA images, to simultaneously ensure the semantic relevance and visual quality of the generated images, the system adopts a dual-guided generation strategy of text and image. This application uses Stable Diffusion as the basic diffusion model and integrates an IP-Adapter module to enhance the control over image conditions. During the input phase, the system first processes the scene description text through the text encoder built into the diffusion model to generate text embedding features. These features continuously guide the generation of semantic content in the image during the denoising process through a cross-attention mechanism. Simultaneously, the system processes the pre-selected target image through the image encoder of the IP-Adapter to generate image conditional embedding features. These features are fused with the feature map of the diffusion model through the attention module of the IP-Adapter to control the visual style and structural features of the generated image.
[0073] S53, on the basis of the random seed value, the text condition and the image condition are iteratively processed by a diffusion model to generate the verification code image.
[0074] After completing the condition input setting, the system starts to execute the iterative generation process of the diffusion model based on the pre-set random seed value. The Stable Diffusion model used in this application gradually converts random noise into a clear image through a reverse diffusion process, which usually sets the iteration number to 20 to 50 steps. In each iteration step, the system first generates a noise distribution according to the current time step and the random seed value, and then embeds the text condition into the feature through the attention mechanism to interact with the current noise feature map, guiding the generation direction of the image content; at the same time, the image condition embedding feature is injected into the denoising process through the IP-Adapter module to regulate the visual features of the generated image. The model will predict the noise residual in each iteration, and update and denoise the image features according to the pre-set sampling strategy (such as DDIM or DPM-Solver).
[0075] After generating the verification code image, further comprising: encoding the verification code image into a third feature vector through an image encoder, and storing the third feature vector and the verification code image into a vector database.
[0076] In one example, in order to continuously expand and optimize the image library of the verification code generation system, after generating the verification code image, the generated image is extracted and stored. The system reuses the image encoder of the aforementioned multi-modal feature extraction model CLIP to encode the newly generated verification code image, obtaining a third feature vector with the same dimension as the original feature vector. This encoding process ensures that the feature representation of the newly generated image is in the same feature space as the pre-selected image, maintaining the consistency and comparability of the features.
[0077] Subsequently, the system stores the third feature vector and the corresponding verification code image as a key-value pair in the vector database, which supports efficient similarity retrieval operations and can quickly locate semantically related images. This storage mechanism forms a positive feedback loop: the newly generated high-quality verification code image is encoded and stored, and can be used as a reference image for subsequent generation processes, thereby continuously expanding the image library capacity of the system and enriching the available visual reference resources.
[0078] After generating the verification code image, further comprising: performing quality assessment on the verification code image according to a pre-set image quality assessment model to obtain a quality assessment score; determining the verification code image with a quality assessment score greater than a pre-set score as a to-be-encoded image; performing data cleaning processing on the to-be-encoded image to generate a target verification code image.
[0079] To ensure that the generated CAPTCHA images meet practical application requirements, the system implements a rigorous quality control process after image generation. This application employs a pre-defined image quality assessment model (such as NIMA or FID evaluator) to evaluate the quality of the generated CAPTCHA images. This model scores the images from multiple dimensions, including image clarity, structural integrity, and content rationality. The quality assessment score output by the model typically ranges from 0 to 10, reflecting the overall quality level of the image. The system compares these scores with a pre-defined quality threshold (e.g., 7 points). Only CAPTCHA images with scores higher than the threshold are selected for encoding. This screening mechanism ensures that all images entering the database have a high quality standard. For images that pass the quality assessment, the system also performs data cleaning, including removing potential watermarks, noise, inappropriate content, and other interfering factors. Simultaneously, the system performs format standardization and compression optimization to ultimately generate a standardized target CAPTCHA image.
[0080] Based on the above method, this application also discloses an automated image verification code data generation system, such as... Figure 2 As shown, Figure 2 This is a schematic diagram of the structure of an automated image verification code data generation system provided in an embodiment of this application. The system includes: a first encoding module, a second encoding module, a calculation module, a selection module, and a generation module; wherein, The first encoding module encodes a pre-selected image into a first feature vector using an image encoder based on a multimodal feature extraction model. The second encoding module receives scene description text describing the scenario to be generated for the CAPTCHA and encodes the scene description text into a second feature vector using a text encoder based on a multimodal feature extraction model, wherein the text encoder and the image encoder share the feature vector space. The calculation module calculates the cosine similarity between the second feature vector and the first feature vector, sorts the first feature vectors in descending order based on the magnitude of the cosine similarity, and generates a target sequence. The selection module selects the first feature vector in the target sequence that is sorted before a preset position and obtains the target pre-selected image corresponding to the first feature vector that is sorted before the preset position; the target pre-selected image is an image in the pre-selected images. The generation module inputs the scene description text and the target pre-selected image into an image generation model to generate a CAPTCHA image.
[0081] In one example, the system described above is also used to encode the CAPTCHA image into a third feature vector using an image encoder, and to store the third feature vector and the CAPTCHA image in a vector database.
[0082] In an example, the first encoding module is further configured to perform image resizing and pixel normalization on the preselected image to generate a standardized preselected image; input the standardized preselected image into an image encoder of the multi-modal feature extraction model to generate a feature map of the preselected image; and generate a first feature vector of a fixed dimension according to the feature map.
[0083] In an example, the second encoding module is further configured to obtain a plurality of candidate description texts of the to-be-generated CAPTCHA scene from a text description library according to a preset scene type; perform text normalization processing on the candidate description texts; and select a target number of scene description texts from the processed candidate description texts, wherein the target number is used to determine a number of batches of to-be-generated CAPTCHA images.
[0084] In an example, the computing module is further configured to perform dot product operation on the second feature vector and the first feature vector to generate an operation result; calculate a product of a norm of the second feature vector and a norm of the first feature vector to generate a product result; and divide the operation result by the product result to generate a cosine similarity.
[0085] In an example, the generating module is further configured to generate a random seed value by using a random number generator, set the random seed value as a generation parameter of the image generation model; input the scene description text as a text condition and the target preselected image as an image condition into the text-image guided diffusion model; and perform iterative processing on the text condition and the image condition by using the diffusion model based on the random seed value to generate a CAPTCHA image.
[0086] In an example, the system is further configured to perform quality evaluation on the CAPTCHA image according to a preset image quality evaluation model to obtain a quality evaluation score; determine a CAPTCHA image with a quality evaluation score greater than a preset score as a to-be-encoded image; and perform data cleaning processing on the to-be-encoded image to generate a target CAPTCHA image.
[0087] It should be noted that the apparatus provided in the above examples is only used as an example for dividing the above functional modules, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above examples belong to the same concept, and the specific implementation process is described in detail in the method embodiments, which will not be repeated here.
[0088] Please refer to Figure 3 The embodiment of the present application provides a structural schematic diagram of an electronic device. As shown in Figure 3As shown, the electronic device 1000 can include at least one processor 1001, at least one network interface 1004, a user interface 1003, a memory 1005, at least one communication bus 1002.
[0089] The communication bus 1002 is configured to realize the connection communication between the components.
[0090] The user interface 1003 can include a display, a camera, and optionally a standard wired interface and a wireless interface.
[0091] The network interface 1004 can optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
[0092] The processor 1001 can include one or more processing cores. The processor 1001 connects various parts of the server through various interfaces and lines, executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Optionally, the processor 1001 can be implemented in at least one of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 1001 can be integrated with a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU is mainly used to process the operating system, user interface and application programs; the GPU is used to render and draw the content to be displayed on the display; and the modem is used to process wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 1001, but can be realized by a separate chip.
[0093] The memory 1005 can include a Random Access Memory (RAM) and can also include a Read-Only Memory (ROM). Optionally, the memory 1005 includes a non-transitory computer-readable storage medium. The memory 1005 can be used to store instructions, programs, codes, code sets, or instruction sets. The memory 1005 can include a program storage area and a data storage area, where the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the various method embodiments described above, etc.; the data storage area can store data involved in the various method embodiments described above, etc. The memory 1005 can also optionally be at least one storage device located away from the aforementioned processor 1001. As shown in Figure 3 The memory 1005, as a computer storage medium, can include an operating system, a network communication module, a user interface module, and an application program of an image verification code data automatic generation method.
[0094] In the electronic device 1000 shown in Figure 3 In the electronic device 1000 shown in, the user interface 1003 is mainly used to provide an interface for user input and obtain data input by the user; and the processor 1001 can be used to call an application program of an image verification code data automatic generation method stored in the memory 1005, which, when executed by one or more processors, causes the electronic device to perform the method described in one or more of the above embodiments.
[0095] An electronic device readable storage medium stores instructions. When executed by one or more processors, the electronic device performs the method described in one or more of the above embodiments.
[0096] It should be noted that, for the above-mentioned method embodiments, in order to simplify the description, they are all described as a combination of a series of actions, but those skilled in the art should know that the application is not limited by the order of the described actions, because according to the application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily required by the application.
[0097] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0098] In several embodiments provided in the present application, it should be understood that the disclosed apparatus can be implemented in other manners. For example, the division of the apparatus embodiments is merely illustrative, and the units can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0099] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they can be located in one place or distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0100] In addition, the functional units in each embodiment of the present application can be integrated into a processing unit, or each unit can be physically present separately, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0101] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable memory. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product, which is stored in a memory and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0102] The above is only exemplary embodiments of the present disclosure, which cannot limit the scope of the present disclosure. Any equivalent changes and modifications made in accordance with the teachings of the present disclosure are still within the scope of the present disclosure. Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the specification and practicing the present disclosure. The present application is intended to cover any variations, uses or adaptive changes of the present disclosure that follow the general principles of the present disclosure and include common knowledge or conventional techniques in the art that are not described in the present disclosure. The specification and embodiments are only considered exemplary, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. An image verification code data automatic generation method, characterized in that, The method comprises: encoding a preselected image into a first feature vector by an image encoder of a multi-modal feature extraction model; receiving a scene description text for describing a to-be-generated verification code scene, and encoding the scene description text into a second feature vector by a text encoder of the multi-modal feature extraction model, wherein the text encoder shares a feature vector space with the image encoder; calculating a cosine similarity between the second feature vector and the first feature vector, sorting the first feature vector in descending order according to the size of the cosine similarity, and generating a target sequence; selecting a first feature vector in the target sequence before a preset position, and obtaining a target preselected image corresponding to the first feature vector before the preset position, wherein the target preselected image is an image in the preselected images; inputting the scene description text and the target preselected image into an image generation model to generate a verification code image.
2. The image verification code data automatic generation method according to claim 1, characterized in that, After the verification code image is generated, the method further comprises: encoding the verification code image into a third feature vector by the image encoder, and storing the third feature vector and the verification code image into a vector database.
3. The image authentication data automatic generation method of claim 1, wherein, The method of encoding a preselected image into a first feature vector by an image encoder of a multi-modal feature extraction model comprises: performing image size adjustment and pixel normalization on the preselected image to generate a standardized preselected image; inputting the standardized preselected image into an image encoder of a multi-modal feature extraction model to generate a feature map of the preselected image; generating a first feature vector with a fixed dimension according to the feature map.
4. The image authentication data automatic generation method of claim 1, wherein, The method of receiving a scene description text for describing a to-be-generated verification code scene comprises: obtaining a plurality of candidate description texts for the to-be-generated verification code scene from a text description library according to a preset scene type; performing text normalization processing on the candidate description texts; selecting a target number of scene description texts from the processed candidate description texts, wherein the target number is used to determine a batch number of to-be-generated verification code images.
5. The image authentication data automatic generation method of claim 1, wherein, The method of calculating a cosine similarity between the second feature vector and the first feature vector comprises: performing a dot product operation on the second feature vector and the first feature vector to generate an operation result; calculating a product of a modulus of the second feature vector and a modulus of the first feature vector to generate a product result; dividing the operation result by the product result to generate a cosine similarity.
6. The image authentication data automatic generation method of claim 1, wherein, The method of inputting the scene description text and the target preselected image into an image generation model to generate a verification code image comprises: generating a random seed value by using a random number generator, and setting the random seed value as a generation parameter of the image generation model; inputting the scene description text as a text condition and the target preselected image as an image condition into a diffusion model guided by text and image; based on the random seed value, iteratively processing the text condition and the image condition by the diffusion model to generate a verification code image.
7. The image verification code data automatic generation method according to claim 1, characterized in that, After the verification code image is generated, the method further comprises: performing quality evaluation on the verification code image according to a preset image quality evaluation model to obtain a quality evaluation score; determine the verification code image with the quality evaluation score greater than the preset score as a to-be-encoded image; perform data cleaning processing on the to-be-encoded image to generate a target verification code image.
8. An image authentication data automated generation system, characterized by, The system comprises a first encoding module, a second encoding module, a calculation module, a selection module and a generation module, wherein The first encoding module is configured to encode a preselected image into a first feature vector by an image encoder of a multi-modal feature extraction model; The second encoding module is configured to receive a scene description text describing a to-be-generated verification code scene, and encode the scene description text into a second feature vector by a text encoder of the multi-modal feature extraction model, wherein the text encoder and the image encoder share a feature vector space; The calculation module is configured to calculate a cosine similarity between the second feature vector and the first feature vector, sort the first feature vectors in descending order according to the size of the cosine similarity, and generate a target sequence; The selection module is configured to select the first feature vector in the target sequence before a preset position, and obtain a target preselected image corresponding to the first feature vector before the preset position, the target preselected image being an image in the preselected images; The generation module is configured to input the scene description text and the target preselected image into an image generation model to generate a verification code image.
9. An electronic device, comprising: An electronic device comprising a processor, a memory, a user interface and a network interface, the memory being configured to store instructions, the user interface and the network interface being configured to communicate with other devices, and the processor being configured to execute the instructions stored in the memory to enable the electronic device to perform the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, A computer program stored in a memory and capable of being loaded and executed by a processor to perform the method of any one of claims 1-7.