Text verification code generation method based on visual illusion

By generating text-based CAPTCHAs based on visual illusions, utilizing fluid noise stripes and adversarial color matching, and combining the Monk-White illusion and structured destruction, the problem of insufficient protection capabilities of existing text-based CAPTCHAs in deep learning models is solved, achieving the generation of CAPTCHAs that are both adversarial and human-readable.

CN122049110APending Publication Date: 2026-05-15XIDIAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XIDIAN UNIV
Filing Date
2026-01-28
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing text-based CAPTCHAs are not sufficiently protected against deep learning models. They are easily stripped of noise and interference lines by image preprocessing algorithms. Furthermore, deep neural networks exhibit robustness, making it difficult for them to resist preprocessing through visual mechanisms and mislead deep recognition models.

Method used

By generating fluid noise stripes with controllable frequency, phase, and perturbation coefficients, adversarial color matching based on brightness anchoring and color difference thresholds, combined with the Monk-White illusion and structured destruction, adversarial text CAPTCHAs are generated. This approach leverages the differences in human and machine visual perception to weaken the recognition accuracy of deep learning models while maintaining human readability.

Benefits of technology

It significantly reduces the automatic recognition accuracy of deep learning models, enhances adversarial capabilities, maintains readability for human users, flexibly adapts to different security requirements, and is compatible with image rendering libraries and deep learning evaluation processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122049110A_ABST
    Figure CN122049110A_ABST
Patent Text Reader

Abstract

The invention discloses a text verification code generation method based on visual illusion. The method comprises the following steps: step 1, generating a bright stripe color, a dark stripe color and a character color based on a verification code image canvas, and establishing a brightness and chromatic aberration relationship between the two stripe colors and the character color; step 2, generating fluid noise with spatial coherence based on the verification code image canvas to form a stripe type mask; 3, drawing pseudo-stroke interference on the background, and combining the pseudo-stroke interference with the mask to form a same-color interference layer; 4, drawing to-be-recognized characters in sequence, applying structural damage to a character layer, including cutting, same-color shielding and trap display, and rendering the characters to a canvas; and step 5, applying pixel-level jitter and salt-and-pepper noise to the character-containing composite image in the step 4, completing post-processing and outputting a final text verification code image. According to the method, the readability and recognition stability of human users to character contents are kept while the automatic recognition accuracy based on the deep learning model is remarkably weakened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of network information security and computer vision countermeasures technology, specifically relating to a method for generating text verification codes based on visual illusions. Background Technology

[0002] With the widespread adoption of internet technology, security threats such as malicious registration, data scraping, brute-force attacks, and vote-rigging brought about by automated scripts are becoming increasingly serious. The fully automated Turing Test (CAPTCHA, commonly known as verification code) that distinguishes between computers and humans serves as the first line of defense, and its security is paramount. CAPTCHA is one of its main components, and with continuous development, CAPTCHAs have taken many forms, including text, image semantic understanding, sliding puzzles, and audio recognition. Among these, text-based CAPTCHAs have long been the mainstream choice for industrial applications due to their significant advantages such as low generation cost, intuitive interactive logic, and strong deployment compatibility.

[0003] With the rapid development of deep learning and computer vision technologies, the security of text-based CAPTCHAs is facing severe challenges: on the one hand, mature image preprocessing algorithms such as binarization can easily remove conventional noise and interference lines; on the other hand, end-to-end recognition models based on deep neural networks have shown strong robustness to perturbations that have not been specially designed.

[0004] Therefore, there is an urgent need to explore a new CAPTCHA design scheme that can both counteract preprocessing through visual mechanisms and mislead deep recognition models by utilizing algorithmic noise. Summary of the Invention

[0005] To overcome the shortcomings of the existing technologies, the present invention aims to provide a text CAPTCHA generation method based on visual illusion. This method generates fluid noise stripes with controllable frequency, phase, and perturbation coefficients and generates adversarial color matching based on brightness anchoring and color difference threshold to induce the Monk-White illusion. This introduces structural destruction at the character layer, significantly reducing the accuracy of automatic recognition based on deep learning models while maintaining the readability and recognition stability of the character content for human users. This overcomes the problem of insufficient protection capability of existing CAPTCHA technologies when facing modern neural network recognition systems.

[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A method for generating text verification codes based on visual illusions includes the following steps; Step 1: Generate an adversarial color scheme. Based on the CAPTCHA image canvas, generate bright stripe colors. Dark striped color and character color A relationship between brightness and color difference is established between each stripe color and character color; Step 2: Generate spatially coherent fluid noise based on the CAPTCHA image canvas to form a strip-shaped mask; Step 3: Draw pseudo-stroke interference, using the character colors described in Step 1. The drawing process is performed, spatial filtering is performed using the mask generated in step 2, and the filtered pseudo-stroke fragments are superimposed onto the strip-shaped mask described in step 2 to form a canvas containing interference information. Step 4: Draw the characters to be recognized sequentially on an independent temporary transparent layer, apply random rotation to form a character layer, apply structured destruction within the character layer, including cutting, same-color occlusion, and trap display, and render the characters onto the canvas containing interference information obtained in Step 3 to obtain a composite image containing characters; Step 5: Apply pixel-level dithering and salt-and-pepper noise to the composite image containing characters to output the final text verification code image.

[0007] Furthermore, the specific steps of the adversarial color matching generation method in step 1 are as follows: Step 1.1: Select the brightness difference threshold between the light and dark stripe colors. Brightness tolerance between character color and bright stripe color Color difference threshold between bright stripe color and character color ; Step 1.2: Randomly generate bright stripe colors With dark stripes To create a high-frequency contrast environment sufficient to induce the Monk-White illusion, bright striped colors are used. Brightness L ( Dark striped color Brightness L ( The following brightness difference constraints need to be met: ; This high-brightness background provides the necessary inducing field for subsequent characters to produce color assimilation or contrast illusion; Step 1.3: Under the premise of satisfying the brightness difference constraint, color the characters. Set brightness anchoring conditions, requiring ; The essential function of this step is to force the grayscale value of the character pixels to statistically match the grayscale value of the bright stripes within them. When the CAPTCHA image undergoes traditional grayscale or binarization preprocessing, the character pixels will be statistically consistent with the grayscale values ​​of the bright stripes. The bright stripes are assimilated to grayscale, causing characters located in the background area to disappear directly in the binarization result; at the same time, the edge gradient at the boundary between the character and the background will be significantly reduced or reduced to zero, thus rendering character segmentation algorithms based on connected component analysis or gradient detection ineffective.

[0008] Step 1.4: Apply the bright stripe color With character color The conversion from RGB color space to CIE Lab* color space is denoted as follows: and The perceived color difference between the two was calculated based on the CIEDE2000 color difference formula. : in, for and The difference in brightness between them Chromaticity difference and for and The tonal difference between them; This is a weighting function based on color regions, used to correct for differences in human eye sensitivity in different color regions; This is a rotation factor used to correct the chromatic aberration ellipse deflection in the blue region; This is a parameter factor (usually set to 1); Step 1.5: Iterate repeatedly until... This is to ensure that the color difference remains within a range that is still recognizable to humans.

[0009] Furthermore, in step 2, a background fluid noise texture is generated and a stripe mask is formed. The specific steps are as follows: Step 2.1: Construct a two-dimensional fluid noise field; Step 2.2; For any pixel coordinates on the CAPTCHA image canvas Calculate the transverse disturbance wave at this location. ,in , , These are adjustable parameters; Step 2.3: Superimpose fluctuation and phase terms onto the noise, based on a certain pixel. transverse disturbance wave Longitudinal fundamental frequency Disturbance coefficient and distortion Computational fluid waves The calculation formula is: Step 2.4: Based on fluid waves Calculate binary mask Mask is defined as .

[0010] Furthermore, the specific steps of constructing the two-dimensional fluid noise field in step 2.1 are as follows: Step 2.1.1: Establish the noise sampling grid space, first for a size of The CAPTCHA image canvas is spatially discretized and divided into sections. OK Columns, totals A rectangular grid cell; at this point, the physical size of the grid cell is defined as... and ; Step 2.1.2: In the mesh generation Generate unit-length random gradient vectors at each grid node. , Indicates that it is located at the th Liede The stochastic gradient vector at the row grid node; Step 2.1.3: For any pixel on the canvas First, determine the grid cell to which it belongs and the normalized relative coordinates within that cell. : in, Then, the distance vectors of the pixel relative to the four vertices (top left, top right, bottom left, and bottom right) of its corresponding grid cell are calculated, and the distance vectors are multiplied by the corresponding node gradient vectors to obtain the gradient contribution values ​​of the four corner points. ; Step 2.1.4: Diagonal gradient dot product Applying smooth interpolation polynomial interpolation function The final noise value is obtained by performing smooth interpolation. Define the interpolation function for Step 2.1.5: Analyze the obtained noise field Amplitude scaling is applied to control the final amplitude.

[0011] Furthermore, in step 3, drawing pseudo-stroke interference and synthesizing a layer of interference of the same color depends on the character color determined in step 1. and the mask constructed in step 2 The aim is to further combat segmentation algorithms by generating background noise that is completely consistent with the optical features of real characters. The specific steps are as follows: Step 3.1: Randomly generate Each pseudo-stroke segment is randomly selected according to the following strategy: short straight line, arc segment, Bézier or curve segment. Step 3.2: Pseudo-stroke fragment parameters include the starting point. ,length ,width (pixels), start and end angles ; Step 3.3: Create a temporary transparent layer with the same size as the canvas, using the character colors generated in Step 1. The pseudo-stroke fragments are rasterized and drawn; the non-zero pixel areas of the drawn temporary layer are extracted and defined as pseudo-stroke layers. This layer identifies the spatial distribution of all interfering strokes on the canvas; Step 3.4: Apply the pseudo-stroke layer With the mask generated in step 2 Performing a logical AND operation yields a set of pseudo-strokes visible only within a specific band. ,Right now .

[0012] Furthermore, the specific steps of character rendering and structure destruction in step 4 are as follows: Step 4.1: Randomly select characters from the character set (including numbers and uppercase English letters, with easily confused characters pre-removed) to form a string of length [length missing]. A sequence of characters; Step 4.2: To enhance protection, randomly select several characters as trap characters, with a set size of [size missing]. And record the trap index set. ; Step 4.3: For the first Each character creates an independent transparent layer and is offset randomly. and random rotation angle (Preferred range is ±20°) Draw solid characters to obtain character masks. ; Step 4.4; Perform structured cutting and randomly select endpoints. Cutting length ,angle and cutting width (2–3 pixels); Generate a binarized local mask for each cutting line. and multiply by logical multiplication Combined with this to obtain the cut-off character mask ; Step 4.5: For trap characters, set the visible area along the dark stripe color. The display shows that, due to brightness anchoring, the characters have weak grayscale contrast on the bright stripe and are easily ignored by the machine. Step 4.6: For non-trap characters, set their visible area to... This causes some real characters to be displayed on the darker stripe; this strategy takes advantage of the influence of the Monk-White illusion on machine vision by changing the visibility of characters between stripes. Step 4.7: Put all Render to the final canvas and overlay with the previous pseudo-stroke layer to output a composite image containing characters. .

[0013] Furthermore, the specific steps for adding pixel dithering and salt-and-pepper noise in step 5 are as follows: This step uses the composite image containing characters output in step 4. For the object being processed: Step 5.1: For the composite image generated in step 4 Each pixel position on A small random offset vector is generated using a random function. The original pixel values ​​are mapped to new coordinates through non-linear resampling. To obtain the jittered image Its mathematical representation is Where W represents the width of the image and H represents the height of the image. For boundary constraint functions; Step 5.2: Apply salt-and-pepper noise to the image. Randomly sprinkle points on top, approximately (Preferably 0.02%, or 2%) of the pixel colors are forcibly replaced with the bright stripe color defined in step 1. Another agreement (or a corresponding proportion) of the pixel color are forcibly replaced with the dark stripe color defined in step 1. To further simulate background penetration and discrete noise, increasing the difficulty of denoising; Step 5.3: Obtain the final output, the final text verification code image. It returns the corresponding character label sequence and trap index set for server-side verification or for training and evaluation.

[0014] A text verification code generation system based on visual illusion includes an adversarial color matching generation module, a fluid noise stripe generation module, a pseudo-stroke interference generation module, a character structure destruction module, and a pixel-level perturbation processing module. Among them, the adversarial color generation module serves as the basic parameter source of the system. It is responsible for constructing a color space that utilizes the differences in light perception between the human eye and machine vision, generating bright stripe colors, dark stripe colors, and character colors with brightness anchoring relationships, and providing optical conditions for inducing the Monk-White optical illusion. The fluid noise strip generation module receives the above color matching parameters, uses the Perlin noise algorithm to construct a binary strip mask with spatial coherence, divides the canvas into complementary background areas and fills them with textures, and provides key spatial selection logic for subsequent layer compositing. The pseudo-stroke interference generation module uses character color to generate vectorized stroke fragments, and performs spatial filtering through a binary strip mask to seamlessly integrate them into a specific background strip, forming a background interference layer that is difficult to distinguish from the optical features of real characters. After obtaining the character sequence preset by the system, the character structure destruction module applies rotation and hard cutting operations on an independent transparent layer to destroy the character connectivity. Based on the mask logic, it maps the processed character pixels onto the composite background to obtain a composite image containing characters, thereby achieving differentiated display of true characters and trap characters. The pixel-level perturbation processing module receives the synthesized composite image containing characters, performs nonlinear coordinate resampling and injects salt-and-pepper noise of the same color, disrupts the continuity of local gradients and simulates background penetration effect, and outputs the final text verification code image.

[0015] The beneficial effects of this invention are: (1) This invention systematically integrates three types of adversarial methods—fluid noise texture, Munk-White visual illusion, and structure destruction—to give deep learning recognizers (especially models that rely on connectivity, local gradients, and grayscale contrast) significant misleading capabilities. It utilizes a brightness anchoring mechanism to eliminate the statistical difference between characters and background in the brightness channel, forcing the model to lose target features during the grayscale preprocessing stage. At the same time, it combines a color interference layer to destroy the topological connectivity of characters, cutting off the path for the convolutional neural network to extract continuous feature gradients, thereby effectively defending against gradient-based attacks and end-to-end recognition models. (2) It still maintains high readability for human observers because of the fundamental differences between the human visual system and the perception mechanism of machine vision. The color difference threshold set in step 1... This ensures that even if the luminance channel information is lost, the human eye can still clearly distinguish the character outline through the chrominance channel. Furthermore, human vision has the closure law characteristic in Gestalt psychology, which can automatically repair the stroke breakage caused by the structural destruction in step 4 at the cognitive level, thereby maintaining the human reading experience while ensuring that the machine cannot segment it. (3) The generation process is parameterized and adjustable, which makes it easy to dynamically increase or decrease the protection strength according to the scene requirements. The brightness tolerance in step 1 can be adjusted. Color difference threshold The fluid noise frequency in step 2 and the pseudo-stroke density in step 3 Key parameters are used to switch strategies. For example, in low-risk scenarios, the color difference threshold can be increased to improve user experience, or in high-risk scenarios, the brightness tolerance can be tightened and the interference density increased to maximize security, thereby flexibly adapting to different business security needs. (4) It is simple and efficient, and compatible with existing image rendering libraries and deep learning evaluation processes. Attached Figure Description

[0016] Figure 1 This is the overall flowchart of the present invention.

[0017] Figure 2 This is the flowchart for the adversarial color matching generation module.

[0018] Figure 3 This is a diagram of the Monk-White optical illusion.

[0019] Figure 4 This is a flowchart of the fluid noise strip generation module.

[0020] Figure 5 This is a flowchart for generating pseudo-stroke interference.

[0021] Figure 6 This is the flowchart for the character structure destruction module.

[0022] Figure 7 This is a flowchart of the pixel-level disturbance processing module.

[0023] Figure 8 This is an example diagram of the final verification code generated by this invention.

[0024] Figure 9 These are example images of the binarization results of different algorithms on the same CAPTCHA. Detailed Implementation

[0025] The present invention will now be described in further detail with reference to the accompanying drawings.

[0026] This invention discloses a text CAPTCHA generation method based on visual illusions. By systematically integrating three types of adversarial techniques—fluid noise texture, Monk-White visual illusion, and structured destruction—it exhibits significant misleading capabilities against deep learning recognizers. (Refer to...) Figure 1 The present invention provides a text verification code generation method based on optical illusion, comprising the following steps: Step 1: Generate a contrasting color scheme, generating bright stripes. Dark striped color and character color The brightness and color difference relationship is established between the two stripe colors and the character colors. This is done by taking advantage of the difference between human eyes and machine vision in the perception of the brightness channel, thereby inducing the Monk-White illusion and increasing the difficulty of binarization and character segmentation in the traditional CAPTCHA recognition process. Step 2: Generate spatially coherent fluid noise to form a strip mask. The strip mask controls the character visibility using phase and frequency parameters during the rendering process in the subsequent step 4. Step 3: Draw pseudo-stroke interference on the background stripes and combine it with the mask generated in Step 2 to form a same-color interference layer; use the character color described in Step 1. Pseudo-stroke fragments are drawn, spatial filtering is performed using the mask generated in step 2, and the filtered pseudo-stroke fragments are superimposed on the fluid stripe background described in step 2 to form a canvas containing interference information. Step 4: Draw the characters to be recognized on a separate temporary transparent layer, apply random rotation to form a character layer, draw the characters to be recognized in sequence, apply structured destruction within the character layer, including cutting, same-color occlusion, and trap display, and render the characters onto the canvas obtained in Step 3. Step 5: Apply pixel-level dithering and salt-and-pepper noise to the canvas image synthesized in Step 4, perform post-processing, and output the final text verification code image.

[0027] The specific process of the adversarial color matching generation module in step 1 is as follows: Figure 2 As shown.

[0028] The process for step 1 is as follows: First, two bright stripe colors are randomly sampled and generated within a preset color space. and dark striped colors The brightness is obtained by weighting and summing the red, green, and blue channels according to the weights perceived by the human eye. and After completing the brightness calculation, the brightness difference between the two background colors is determined, and only if the brightness difference is not less than the preset minimum brightness difference threshold is the result determined. Only when the desired background color is determined is the color group retained as a valid candidate background color scheme; after determining the background color, the module further randomly generates character colors. The brightness of the character color is calculated, and a brightness anchoring constraint is used to keep the brightness of the character color within a preset tolerance range compared to the brightness of the first background color. Meanwhile, the color difference between the character color and the first background color is calculated, and only if the color difference is not lower than a preset minimum color difference threshold is the calculation performed. Only after the above-mentioned brightness difference constraint, brightness anchoring constraint, and color difference constraint are all satisfied, will the adversarial color matching generation module output the final two stripe colors. and and the corresponding character colors This is used for subsequent steps of generating fluid noise stripes and drawing characters.

[0029] Figure 3 This is a schematic diagram of the Munch-White optical illusion, used to illustrate that under the color conditions generated by the resistant color matching generation module, when the target color is placed in background areas with different brightness or texture structures, the human visual system will produce subjective perceptual differences in the brightness distribution and banding structure of the surrounding background, thus causing areas that are essentially the same color to appear visually different in brightness or contrast. This schematic diagram, by comparing the display status of the same color in different banded backgrounds, intuitively demonstrates the modulation effect of the Munch-White optical illusion on visual perception, providing a perceptual explanation of the technical principle of controlling character visibility based on banded backgrounds in this invention. It should be noted that... Figure 3 This image is only used to illustrate the generation mechanism of the Monk-White optical illusion and its effect on visual perception. It does not represent the final CAPTCHA image generated by this invention, nor does it reflect the comprehensive processing effect of superimposed fluid noise texture, pseudo-stroke interference, structure destruction and pixel-level perturbation in the CAPTCHA. The final CAPTCHA image is a complex adversarial visual result formed by multi-module collaborative processing based on such visual illusion mechanisms.

[0030] Figure 4 This is the flowchart of the fluid noise strip generation module corresponding to step 2. This module is mainly divided into two parts: the first part is the construction of a two-dimensional fluid noise field, and the second part is the construction of the strip fluid wave function and the generation of a binary mask based on the noise field.

[0031] The construction of the first part, the two-dimensional fluid noise field, can be roughly divided into the following steps: (1) Establish the noise sampling grid space, firstly for a size of The CAPTCHA image canvas is spatially discretized and divided into sections. OK Columns, totals A rectangular grid cell; at this point, the physical size of the grid cell is defined as... and ; (2) In the generation of grid division Generate unit-length random gradient vectors at each grid node. , Indicates that it is located at the th Liede The stochastic gradient vector at the row grid node; (3) For any pixel on the canvas First, determine the grid cell to which it belongs and the normalized relative coordinates within that cell. : in, Then, the distance vectors of the pixel relative to the four vertices (top left, top right, bottom left, and bottom right) of its corresponding grid cell are calculated, and the distance vectors are multiplied by the corresponding node gradient vectors to obtain the gradient contribution values ​​of the four corner points. ; (4) To achieve a smooth transition in the response, a smooth interpolation function is applied to the local coordinates. , The definition of , For normalized coordinates; by first along the horizontal direction according to Interpolating the corner response yields two intermediate values, then along the vertical direction according to... Interpolating the intermediate values ​​yields the noise value at each pixel. ; (5) The obtained noise field Amplitude normalization and optional frequency band superposition are performed to achieve fluid texture details at different scales by adjusting the amplitude scaling factor and multiple frequency superposition. The normalization process can employ linear scaling. The values ​​fall within a preset range to facilitate subsequent parameter coupling and visualization.

[0032] The second part is the construction of strip fluid wavefunctions and the generation of binary masks based on the noise field. The implementation steps are roughly as follows: (1) Based on the generated noise field Constructing the wave function of strip fluid That place, This indicates the amplitude of the horizontal disturbance, used to control the bending amplitude of the strip in the horizontal direction; It represents the angular frequency of the horizontal disturbance, used to control the lateral periodicity; Indicates the initial phase of the horizontal disturbance; This indicates the longitudinal fundamental frequency, used to control the longitudinal spacing density of the stripes; Represents the noise disturbance coefficient, used to control the noise field. The intensity of the effect on the strip phase; Indicates the overall phase offset; (2) For the fluid wave function Perform sign determination to generate a binary stripe mask. ,in Defined as when hour, , representing pixels Belongs to the first zone region; when hour, , representing pixels For the second strip region, a zero-crossing threshold is selected for binarization to ensure the symmetry and phase continuity of the strip. (3) For the generated binary mask Morphological filtering or small-scale smoothing can be used to eliminate isolated small blocks and control the sharpness of strip boundaries. The size and repetition number of the structuring element used in the morphological operation are adjustable parameters to balance the natural curvature and controllable distribution of the strip. (4) Output noise field Fluid wave function Sampling results and binary strip mask and the set of parameters used Save them together for reproduction and parameter tuning.

[0033] The basic flowchart of the pseudo-stroke interference generation module corresponding to step 3 is shown below. Figure 5 .

[0034] During the generation process, this module first generates several stroke interference structures randomly within the effective display area of ​​the CAPTCHA image based on the preset distribution of the number and shape parameters of the pseudo-strokes. Each pseudo-stroke has a random starting position. ,length ,width The pseudo-strokes can take the form of straight line segments, arc segments, or curve segments, thereby simulating the local morphological features of real character strokes in terms of overall structure. Subsequently, the pseudo-strokes are drawn using the same color as the target character and rendered onto a pseudo-stroke layer that includes transparency information. In the process, the pseudo-strokes are made to match the strokes of real characters in the color feature space; after the pseudo-strokes are drawn, the module transfers the pseudo-stroke layer... Strip mask output by the fluid noise strip generation module Spatial logic operations are performed to retain only the pseudo-stroke pixels located within the predetermined strip area, thereby coupling the pseudo-strokes with the character display area in terms of spatial distribution and enhancing the visual confusion effect. Finally, the generated pseudo-stroke interference structure is constrained to remove interference segments that are too short, too dense, or completely overlap with the main character, thus forming a pseudo-stroke interference layer that has a synergistic effect on the subsequent character structure destruction module.

[0035] Figure 6 This is the flowchart for the character structure destruction module corresponding to step 4. Its implementation steps are roughly as follows: (1) After receiving the character sequence to be generated and the corresponding font parameters, character size and image space layout parameters, the character structure destruction module first performs independent rendering processing on each character, that is, draws each character separately into the corresponding transparent layer to obtain the initial character pixel distribution and its corresponding character mask under the current font and size conditions. The character mask is used to represent the effective display area of ​​the character in the pixel coordinate space; (2) For each character mask, a structured destruction operation is introduced, which generates several characters with random positions and lengths inside the character mask. The cutting structure, including its direction and width, directionally severs the stroke connectivity of characters, disrupting the overall topological connectivity of the characters locally while preserving sufficient morphological clues to obtain a mask of the severed characters. ; (3) After completing the structured segmentation process, the visible area of ​​the characters is further controlled according to their functional attributes in the verification code. The characters are selectively restricted to be displayed only in the corresponding stripe area. For trap characters, their visible area is set to follow the bright stripe color. The display shows that, due to brightness anchoring, the characters have weak grayscale contrast on the bright stripe and are easily ignored by the machine. For non-trap characters, set their visible area to... This causes some of the real characters to be displayed on the darker stripe.

[0036] (4) Each character layer that has undergone structure destruction and visibility control processing The mixture is then combined with the pseudo-stroke interference layer output by the pseudo-stroke interference generation module. The characters are superimposed to form a character display result containing structured destruction features. This result is then used as the input to the subsequent pixel-level perturbation processing module, thereby completing the specific implementation of the character structured destruction module.

[0037] In step 5, the flowchart of the pixel-level disturbance processing module is as follows: Figure 7 As shown, this module uses a synthesized image that has already undergone character rendering, pseudo-stroke interference, and structure destruction processing. As input, pixel jitter intensity parameters are also received. With probability During processing, the module first targets each pixel location in the image. Generate random offset and The offset value ranges from a preset finite set of integers, used to introduce local positional perturbations without disrupting the overall structure; subsequently, pixels are remapped based on the generated random offsets to form a perturbed intermediate image. ,in In the formula, W represents the width of the image, and H represents the height of the image. This is a boundary constraint function used to prevent the offset pixel index from going out of bounds; after completing the pixel dithering processing, the module further uses probability... Salt-and-pepper noise is introduced at the pixel level, which involves randomly replacing the values ​​of some pixels with the colors of bright stripes. Or dark striped color This process creates discrete, high-contrast noise points in the image. Based on this, the module can also apply slight smoothing or quantization to the perturbed image as needed, eliminating overly artificial edge effects caused by multiple perturbations. Finally, the pixel-level perturbation processing module outputs the final CAPTCHA image. The system uses the corresponding character tag information to complete the final round of adversarial enhancement processing on the local spatial continuity and statistical features of the image. An example of the generated CAPTCHA can be found in [image link]. Figure 8 .

[0038] In the above embodiments, such as Figure 1 The diagram shows the overall framework of an adversarial CAPTCHA generation method based on visual illusion and structured interference. This method consists of five functional modules: an adversarial color matching generation module, a fluid noise stripe generation module, a pseudo-stroke interference generation module, a character structure destruction module, and a pixel-level perturbation processing module. These modules work collaboratively in a predetermined order to generate the CAPTCHA image. The adversarial color matching generation module and the fluid noise stripe generation module provide the visual and spatial basis for subsequent character display and structure destruction, thereby significantly improving the CAPTCHA's ability to protect against automatic recognition systems while ensuring readability for human users.

[0039] Experimental Results and Evaluation: (1) Evaluation of Anti-binarization Processing Performance. Binarization is a preliminary step in most automated recognition scripts, aiming to remove background noise and extract clear character skeletons. This invention quantifies the effectiveness of the defense mechanism by calculating the average binarization recovery rate (BRR) of five common binarization algorithms when processing the CAPTCHA generated by this scheme. BRR is defined as the intersection-union ratio between the binarized attack image and the original real character mask, and the calculation formula is: in, The total number of test samples, Indicates the first The foreground pixel set obtained after processing an image using an attack algorithm Indicates the first The original set of pixels without interference for each image. This represents the pixel count within the set. A higher value indicates a more complete character structure reconstructed by the attack algorithm; conversely, a lower value indicates a better defense. Experimental results for each algorithm are shown in Table 1.

[0040] Table 1. Binarization reduction rate of different algorithms on the verification code generated by this invention Binarization algorithm Traditional color CAPTCHA The method of this invention generates verification codes Otsu algorithm 90.1% 6.1% Sauvola algorithm 89.2% 8% Niblack Algorithm 90.3% 16.5% Adaptive Mean Algorithm 94.1% 7.3% Adaptive Gaussian threshold 89.4% 9.6% Figure 9 Examples of binarization results on a CAPTCHA generated by the method of this invention using different algorithms are shown. In the processing results, special trap character pixels are incorrectly classified as background or horizontally adhered to dark stripes, resulting in low BRR, with an average of less than 15%. Experimental results show that this scheme demonstrates significant superiority in resisting binarization attacks. For the global thresholding Otsu algorithm, because the method of this invention uses adversarial color matching based on color space optimization, the gray-level histogram of the image exhibits a complex multi-peak distribution. This causes the optimal threshold calculated by the global algorithm to often converge near the gray-level mean of a certain background stripe, rather than the boundary between the character and the background. In contrast, traditional color verification maintains a BRR of over 89% when facing global binarization, indicating that traditional interference methods are difficult to destroy the global gray-level statistical characteristics.

[0041] The CAPTCHA generated by the method of this invention also maintains extremely high resistance to more robust adaptive thresholding algorithms (such as the Sauvola and Niblack algorithms). In the sliding window calculation process of the Sauvola algorithm, the high-frequency alternating and periodically dynamically changing (non-linear fluctuations between different pixels) stripes cause drastic fluctuations in local variance, significantly raising the benchmark for local threshold calculation. Simultaneously, because characters are physically discretized into a series of slices, their grayscale contribution within the local window is masked by strong noise from the background texture. Experimental observations revealed that in partially adaptively binarized images, the vertical connectivity of characters is completely destroyed, and strokes exhibit structural breaks. Statistical data shows that on the dataset of this scheme, the average BRR of the adaptive algorithm is only 10.4%, far lower than its 90.7% on traditional color CAPTCHAs. The results demonstrate that the method of this invention can effectively mislead attackers during the preprocessing binarization step in the recognition process.

[0042] (2) Evaluation of Anti-Segmentation Performance. Based on the verification of the binarization failure mechanism, this invention further explores the blocking ability of the proposed method against character segmentation algorithms. Two types of segmentation algorithms were selected as attack benchmarks in the experiment: one is the vertical projection segmentation method based on pixel cumulative features, which relies on valley features to find segmentation points; the other is the connected component analysis method based on topological connectivity and its improved variants (such as the watershed algorithm), which rely on the connectivity of pixels to extract character entities. In order to quantify the failure degree of these algorithms in the face of visual illusion interference, this paper adopts the character segmentation success rate (CSSR) as the core evaluation index. CSSR is defined as the percentage of characters that can be correctly separated and located by the segmentation algorithm out of the total number of characters in the test set. The specific calculation process is as follows: First, each character is recorded synchronously when generating the verification code. True bounding box coordinates This is used as the absolute truth value for evaluation. Subsequently, the generated CAPTCHA image is input into the aforementioned segmentation algorithm, which outputs a set of predicted character candidate boxes. The Intersection over Union (IoU) ratio is used as the matching metric to calculate the truth box for each frame. Maximum overlap with all predicted boxes: If and only if When the character is successfully segmented, it is determined that the character has been successfully segmented. Ultimately, CSSR is defined as the total number of successfully segmented characters. Total number of characters in the test set The ratio: The experimental results are shown in Table 2.

[0043] Table 2. Segmentation success rate of different segmentation algorithms on the CAPTCHA generated by this invention. Segmentation Algorithm Traditional color CAPTCHA The method of this invention generates verification codes Vertical projection segmentation 78.3% 4.5% Connectivity analysis 74.7% 1.2% Watershed Algorithm 87.5% 8.6% The results show that, in the control group of traditional color CAPTCHAs, the above segmentation algorithms all maintain high accuracy. However, for the CAPTCHAs generated by this invention, the introduction of fluid noise texture and structure destruction modules causes a sharp drop in the performance of all segmentation algorithms. In particular, the vertical projection segmentation and connected component analysis methods, which are highly dependent on connectivity, see their character recall rate drop to almost zero at high thresholds. This fully demonstrates that the method proposed in this invention has good defensive performance even in the preprocessing stage.

[0044] (3) Evaluation of the defensive performance of the end-to-end recognition model. To evaluate the defensive performance of the CAPTCHA generated by this invention in the end-to-end automatic recognition scenario, a variety of representative mainstream end-to-end character recognition models were selected as evaluation objects for comparative experiments. The evaluation models include the ResNet series models characterized by residual structure, the VGG model characterized by hierarchical feature stacking, and the CRNN end-to-end sequence recognition model that combines convolutional neural networks and recurrent neural networks. All of the above models can directly complete character feature extraction, sequence modeling and character prediction from the input image, representing the mainstream technical route of the current automatic CAPTCHA recognition system.

[0045] In the evaluation process, character-level recognition accuracy (CASR) and sequence-level complete recognition success rate (ASR) were used as the main evaluation indicators. Character-level recognition accuracy measures the correctness of the model at the level of single character prediction, while sequence-level complete recognition success rate measures whether the model can completely recognize the entire CAPTCHA sequence without any character errors. This indicator more directly reflects the security of the CAPTCHA in actual protection scenarios. Under the same training strategy and inference configuration, the above ResNet, VGG, and CRNN models were tested by inputting adversarial CAPTCHA samples generated by the method of this invention, and compared with traditional CAPTCHA samples. The experimental results are shown in Table 3.

[0046] Table 3. Success rates of different recognition models on the CAPTCHA generated by this invention. It can be observed that the character-level and sequence-level recognition performance of various end-to-end recognition models has decreased significantly. In particular, under the combined effects of structure destruction, fluid noise stripes and pixel-level perturbations, the end-to-end decoding path of the model is continuously disturbed, thus verifying that the present invention has a stable and consistent defense effect when facing different network structures, different feature extraction and sequence modeling mechanisms.

[0047] The above embodiments are only used to illustrate the design concept and features of the present invention, and their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly. The protection scope of the present invention is not limited to the above embodiments. Therefore, all equivalent changes or modifications made based on the principles and design ideas disclosed in the present invention are within the protection scope of the present invention.

Claims

1. A method for generating text verification codes based on visual illusions, characterized in that, Includes the following steps; Step 1: Generate bright stripes based on the CAPTCHA image canvas Dark striped color and character color A relationship between brightness and color difference is established between each stripe color and character color; Step 2: Generate spatially coherent fluid noise based on the CAPTCHA image canvas to form a strip-shaped mask; Step 3: Draw pseudo-stroke interference, using the character colors described in Step 1. The drawing process is performed, spatial filtering is performed using the mask generated in step 2, and the filtered pseudo-stroke fragments are superimposed onto the strip-shaped mask described in step 2 to form a canvas containing interference information. Step 4: Draw the characters to be recognized sequentially on an independent temporary transparent layer, apply random rotation to form a character layer, apply structural destruction within the character layer, and render the characters onto the canvas containing interference information obtained in Step 3 to obtain a composite image containing characters; Step 5: Apply pixel-level dithering and salt-and-pepper noise to the composite image containing characters to output the final text verification code image.

2. The text verification code generation method based on visual illusion according to claim 1, characterized in that, The specific steps of step 1 are as follows: Step 1.1: Select the brightness difference threshold between the light and dark stripe colors. Brightness tolerance between character color and bright stripe color Color difference threshold between bright stripe color and character color ; Step 1.2: Randomly generate bright stripe colors With dark stripes To create a high-frequency contrast environment sufficient to induce the Monk-White illusion, bright striped colors are used. Brightness L ( Dark striped color Brightness L ( The following brightness difference constraints need to be met: ; Step 1.3: Under the premise of satisfying the brightness difference constraint, color the characters. To set brightness anchoring conditions, the following requirements must be met: ; Step 1.4, apply the bright stripe color. With character color The conversion from RGB color space to CIE Lab* color space is denoted as follows: and The perceived color difference between the two was calculated based on the CIEDE2000 color difference formula. : in, for and The difference in brightness between them Poor chroma for and The tonal difference between them; This is a weighting function based on color regions, used to correct for differences in human eye sensitivity in different color regions; This is a rotation factor used to correct the chromatic aberration ellipse deflection in the blue region; For parameter factors; Step 1.5, iterate repeatedly until... This is to ensure that the color difference remains within a range that is still recognizable to humans.

3. The text verification code generation method based on visual illusion according to claim 2, characterized in that, The specific steps of step 2 are as follows: Step 2.1: Construct a two-dimensional fluid noise field; Step 2.2: For any pixel coordinates on the CAPTCHA image canvas Calculate the transverse disturbance wave at this location. ,in , , These are adjustable parameters; Step 2.3: Superimpose fluctuation and phase terms onto the noise, based on a certain pixel. transverse disturbance wave Longitudinal fundamental frequency Disturbance coefficient and distortion Computational fluid waves The calculation formula is: Step 2.4: Based on fluid waves Calculate binary mask Mask is defined as 。 4. The text verification code generation method based on visual illusion according to claim 3, characterized in that, The specific steps for constructing the two-dimensional fluid noise field in step 2.1 are as follows: Step 2.1.1: Establish the noise sampling grid space, first for a size of The CAPTCHA image canvas is spatially discretized and divided into sections. OK Columns, totals A rectangular grid cell; at this point, the physical size of the grid cell is defined as... and ; Step 2.1.2: In the mesh generation Generate unit-length random gradient vectors at each grid node. , Indicates that it is located at the th Liede The stochastic gradient vector at the row grid node; Step 2.1.3: For any pixel on the canvas First, determine the grid cell to which it belongs and the normalized relative coordinates within that cell. : in, Then, the distance vectors of the pixel relative to the four vertices of its corresponding grid cell are calculated, and the distance vectors are multiplied by the corresponding node gradient vectors to obtain the gradient contribution values ​​of the four corner points. ; Step 2.1.4: Diagonal gradient dot product Applying smooth interpolation polynomial interpolation function The final noise value is obtained by performing smooth interpolation. Define the interpolation function for Step 2.1.5: Analyze the obtained noise field Amplitude scaling is applied to control the final amplitude.

5. The text verification code generation method based on visual illusion according to claim 4, characterized in that, The specific steps for drawing pseudo-stroke interference and compositing a layer of interference of the same color in step 3 are as follows: Step 3.1: Randomly generate Each pseudo-stroke segment is randomly selected according to the following strategy: short straight line, arc segment, Bézier or curve segment. Step 3.2: Pseudo-stroke fragment parameters include the starting point. ,length ,width (pixels), start and end angles ; Step 3.3; Create a temporary transparent layer with the same size as the canvas, using the character colors generated in Step 1. The pseudo-stroke fragments are rasterized and drawn. Extract the non-zero pixel area of ​​the completed temporary layer and define it as a pseudo-stroke layer. ; Step 3.4: Apply the pseudo-stroke layer With the mask generated in step 2 Performing a logical AND operation yields a set of pseudo-strokes visible only within a specific band. ,Right now 。 6. The text verification code generation method based on visual illusion according to claim 5, characterized in that, The specific steps of character rendering and structure destruction in step 4 are as follows: Step 4.1: Randomly select characters from the character set to form a string of length [length missing]. A sequence of characters; Step 4.2: Randomly select several characters as trap characters, with a set size of [size missing]. And record the trap index set. ; Step 4.3: For the first Each character creates an independent transparent layer and is offset randomly. and random rotation angle Draw solid characters below to obtain character masks. ; Step 4.4; Perform structured cutting and randomly select endpoints. Cutting length ,angle and cutting width Generate a binarized local mask for each cutting line. and multiply by logical multiplication Combined with this to obtain the cut-off character mask ; Step 4.5, for trap characters, set the visible area along the dark stripe color. Display, i.e. Step 4.6: For non-trap characters, set their visible area to... This causes some of the actual characters to be displayed on the darker stripe; Step 4.7: Put all Render to the final canvas and overlay with the previous pseudo-stroke layer to output a composite image containing characters. .

7. The text verification code generation method based on visual illusion according to claim 6, characterized in that, The specific steps for adding pixel dithering and salt-and-pepper noise in step 5 are as follows: Step 5.1, regarding the composite image generated in step 4 Each pixel position on A small random offset vector is generated using a random function. The original pixel values ​​are mapped to new coordinates through non-linear resampling. To obtain the jittered image Its mathematical representation is Where W represents the width of the image and H represents the height of the image. For boundary constraint functions; Step 5.2, apply salt-and-pepper noise to the image. Randomly sprinkle points on top, approximately The pixel color is forcibly replaced with the bright stripe color defined in step 1. Another agreement The pixel color is forcibly replaced with the dark stripe color defined in step 1. ; Step 5.3, obtain the final output: the final text verification code image. It returns the corresponding character label sequence and trap index set for server-side verification or for training and evaluation.

8. A text verification code generation system based on visual illusion for implementing the method of any one of claims 1-7, characterized in that, It includes an adversarial color matching generation module, a fluid noise strip generation module, a pseudo-stroke interference generation module, a character structure destruction module, and a pixel-level perturbation processing module; The adversarial color generation module, as the basic parameter source of the system, is responsible for constructing a color space that utilizes the differences in light perception between the human eye and machine vision, generating bright stripe colors, dark stripe colors, and character colors with brightness anchoring relationships, and providing optical conditions for inducing the Monk-White optical illusion. The fluid noise stripe generation module receives color matching parameters for light stripe color, dark stripe color, and character color, and uses the Perlin noise algorithm to construct a spatially coherent binary stripe mask, dividing the canvas into complementary background areas and filling them with textures, while providing key spatial selection logic for subsequent layer compositing. The pseudo-stroke interference generation module uses character color to generate vectorized stroke fragments, and performs spatial filtering through a binary strip mask to seamlessly integrate them into a specific background strip, forming a background interference layer that is difficult to distinguish from the optical features of real characters. After acquiring the character sequence preset by the system, the character structure destruction module applies rotation and hard cutting operations on an independent transparent layer to destroy the character connectivity, and maps the processed character pixels to the composite background according to the mask logic to obtain a composite image containing characters, thereby realizing the differentiated display of true characters and trap characters. The pixel-level perturbation processing module receives the synthesized composite image containing characters, performs nonlinear coordinate resampling and injects salt-and-pepper noise of the same color, disrupts the continuity of local gradients and simulates background penetration effect, and outputs the final text verification code image.