An OCR-resistant text watermarking method and system
By adding triangular wave ripple effect to the watermark content, the problem that existing static text watermarks are easily identified and removed when facing OCR technology is solved, achieving higher data security and tracking capabilities.
Patent Information
- Application Number
- CN202411827916.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-04
AI Technical Summary
Existing static text watermarks are easily identified and removed when facing OCR technology, resulting in insufficient data security.
By adding triangular wave ripple effect to the watermark content, the improved triangular wave function T’(t) increases the complexity of deformation, making it difficult for the watermark to be accurately identified by OCR software.
It improves the security of text watermarks, making it difficult to be recognized by existing OCR software while maintaining readability, and enhances data tracking capabilities.
Smart Images

Figure CN119760676A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an OCR-resistant text watermark method and system, and belongs to the field of database data security. Background Art
[0002] In recent years, information technology has achieved rapid development. While enjoying the dividends of information technology, users have gradually realized the importance of information security and paid more and more attention to it. Especially in the process of database management and maintenance, some data in the database can be directly seen through the database performance monitoring system, database security management system, etc. How to ensure the security of data is a problem that database developers and users have to face. For example, in actual operation, users may take screenshots or photos of the content in the information system in order to view or analyze the database status. The picture may contain some sensitive information. If the picture is improperly disseminated, it may lead to data leakage. In various industries in society, the database plays the role of a data storage center. Database users, including those with direct access and indirect access through various information systems, can easily cause data leakage if they receive relevant pictures without supervision and random distribution. Especially for some sensitive data, unconstrained distribution will seriously threaten the security of the data.
[0003] In this context, it is a common method to add text watermarks to the user interface of database-related information systems such as database performance monitoring systems and database security management systems. The watermark is presented in light colors in the background, which ensures that it does not affect the normal user experience and effectively improves the security of the data. If there is a screenshot, the user's identity information and date and other details are embedded in the picture, which increases the protection against unauthorized data transmission. Commonly used watermarking technology mainly uses static text, and the font of the text content is relatively regular. This method has some security risks. For example, using OCR (Optical Character Recognition) technology, attackers can easily identify and remove these watermarks, thereby concealing the source of the data. Moreover, with the advancement of OCR technology, its recognition accuracy is still improving. Therefore, although static text watermarks can play a certain role in security protection, their protection capabilities are relatively weak. BRIEF DESCRIPTION OF THE DRAWINGS
[0004] Figure 1 It is a flow chart of the present invention.
[0005] Figure 2 This is the process diagram of adding triangle wave ripple effect.
[0006] Figure 3 This is the relationship diagram between the new position (x', y') and the four grid points.
[0007] Figure 4 This is the effect diagram after adding watermark after using the present invention. Summary of the invention
[0008] In order to enhance the security of watermark technology and make it difficult to be identified or removed, the present invention proposes an OCR-resistant text watermark method, which comprises the following steps:
[0009] (1) Define watermark attributes;
[0010] (2) Generate watermark image;
[0011] (3) Add watermarks to the system or export files;
[0012] Among them, in step (2), a triangular wave ripple effect is added to the watermark image to achieve deformation.
[0013] Furthermore, the steps for adding the triangle wave ripple effect are:
[0014] 2.1 Definition of triangular wave function Where t is the function variable, tmod 2 represents the remainder when t is divided by 2, || represents the absolute value, and α is a positive real number;
[0015] 2.2 Initialize the amplitude and frequency in the horizontal direction, denoted as A and f respectively; initialize the amplitude and frequency in the vertical direction, denoted as B and g respectively;
[0016] 2.3 For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point, respectively, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point, respectively. ′ =x+A×T′(f×x), y′=y+B×T′(g×y).
[0017] 2.4 For the new position (x', y'), find the 4 nearest grid points (x0, y0), (x1, y0), (x0, y1), (x1, y1), we have y1=y0+1, where Indicates rounding down; d 00 ,d 10 ,d 01 ,d 11 Calculate the distances between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), and (x1, y1) respectively. Where i = 0, 1, and j = 0, 1, β and γ are coefficients, both positive real numbers, then the pixel value at the new position (x', y') is I(x i ,yj ) is the point (x i ,y j ) at the pixel value;
[0018] 2.5 For each pixel, calculate its new position and get the new color value according to the interpolation method, and finally generate a deformed image with a triangle wave effect.
[0019] Based on the above method, the present invention further proposes an OCR-resistant text watermark system, which includes:
[0020] (1) Watermark attribute definition module;
[0021] (2) Watermark image generation module;
[0022] (3) Watermark adding module;
[0023] Among them, in the watermark image generation module, a triangular wave ripple effect is added to the watermark content to achieve deformation.
[0024] Furthermore, the steps for adding the triangle wave ripple effect are:
[0025] 2.1 Definition of triangular wave function Where t is the function variable, tmod 2 represents the remainder when t is divided by 2, || represents the absolute value, and α is a positive real number;
[0026] 2.2 Initialize the amplitude and frequency in the horizontal direction, denoted as A and f respectively; initialize the amplitude and frequency in the vertical direction, denoted as B and g respectively;
[0027] 2.3 For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point respectively, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point respectively, x'=x+A×T'(f×x), y'=y+B×T'(g×y).
[0028] 2.4 For the new position (x', y'), find the 4 nearest grid points (x0, y0), (x1, y0), (x0, y1), (x1, y1), we have y1=y0+1, where Indicates rounding down; d 00 ,d 10 ,d 01 ,d 11 Calculate the distances between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), and (x1, y1) respectively. Where i = 0, 1, and j = 0, 1, β and γ are coefficients, both positive real numbers, then the pixel value at the new position (x', y') is I(x i ,y j ) is the point (x i ,y j ) at the pixel value;
[0029] 2.5 For each pixel, calculate its new position and get the new color value according to the interpolation method, and finally generate a deformed image with a triangle wave effect.
[0030] The present invention uses the function T'(t) to increase the complexity of deformation, increase the difficulty of OCR method recognition, and make the deformation smoother, avoiding the stiff feeling that may be caused by the triangular wave function T(t). By adding a water ripple visual effect to the watermark content, the watermark content is difficult to be accurately recognized by the existing OCR software while maintaining readability. The application of this method improves the security of text watermarks and enhances the data tracking capability when data is leaked by taking screenshots or taking photos of database related information systems. DETAILED DESCRIPTION
[0031] Example 1
[0032] The flow chart of the OCR-resistant text watermarking method proposed by the present invention is as follows: Figure 1 As shown. Figure 1 It can be seen that watermark addition mainly includes the following steps:
[0033] (1) Define watermark attributes
[0034] Define the basic properties of watermarks, which mainly include:
[0035] 1) Determine the watermark text content.
[0036] 2) Set the font of the watermark. If not specified, the default font is Fangsong, bold, and size 16.
[0037] 3) Define the foreground color of the watermark. If no special setting is made, the default is gray.
[0038] 4) Set the background color of the watermark. If no background color is needed, it can be set to empty to indicate a transparent background.
[0039] 5) Determine whether to enable the ripple effect for the watermark. The default setting is not to use it.
[0040] 6) Determine the rotation angle of the watermark text, the default is 35 degrees counterclockwise.
[0041] 7) If necessary, you can specify the width and height of the watermark image. If not specified, it will adapt to the watermark text.
[0042] (2) Generate watermark image
[0043] The generation of watermark images mainly includes the following steps:
[0044] 1) Get the text size
[0045] Measures the actual width and height of the text using the font defined in the watermark object.
[0046] 2) Calculate the size of the bounding box after rotation
[0047] Based on the original size of the text and the specified rotation angle, the width and height of the rotated text bounding box are calculated using affine transformation.
[0048] 3) Create an image
[0049] Create a new image object based on the width and height of the bounding box plus any additional margins.
[0050] 4) Set up the drawing environment
[0051] Get a Graphics2D context to draw graphics, create a transparent image that is compatible with the device, and set the anti-aliasing effect to make the text smoother.
[0052] If a background color is set, the entire image is filled with that color.
[0053] 5) Set the coordinate system
[0054] Moves the origin of the coordinate system to the center of the image. Rotates the coordinate system by the specified rotation angle.
[0055] 6) Draw text
[0056] Draw the text using the font and color defined in the watermark object. Calculate the position of the text relative to the center of the image and ensure that the text is centered in the image.
[0057] 7) Restore the coordinate system
[0058] When you are finished drawing, end the graphics context.
[0059] 8) Apply ripple effect
[0060] In order to ensure that the text watermark will not be easily identified or removed due to the regular font, the present invention proposes an anti-OCR text watermark method, which achieves deformation by adding a triangular wave ripple effect to the watermark content. The process of adding the triangular wave ripple effect is as follows: Figure 2 As shown. Figure 2 It can be seen that the steps for adding the triangle wave ripple effect are:
[0061] a. Define the triangle wave function
[0062] In the present invention, a triangular wave function T(t) is defined, which can calculate the corresponding function value according to the input t value. In one cycle of the triangular wave, the function value increases linearly from the minimum value to the maximum value, and then decreases linearly back to the minimum value. The expression of the triangular wave function T(t) is:
[0063]
[0064] Here, t represents the function variable, t mod 2 represents the remainder when t is divided by 2, and || represents the absolute value.
[0065] In order to make the deformed text more difficult to be recognized by the OCR method, the triangular wave function T(t) was further improved. The improved function T'(t) is expressed as:
[0066]
[0067] Among them, the coefficient α is a positive real number.
[0068] The improved function T'(t) increases the complexity of the deformation and improves the difficulty of OCR recognition. At the same time, it can make the deformation smoother and avoid the harsh feeling that may be caused by the triangular wave function T(t).
[0069] b. Determine the amplitude and frequency
[0070] Amplitude and Frequency control the strength and density of the deformation respectively.
[0071] Initialize the amplitude and frequency in the horizontal direction, denoted as A and f respectively; initialize the amplitude and frequency in the vertical direction, denoted as B and g respectively.
[0072] c. Apply triangle wave transform
[0073] For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point. Here, the improved function T'(t) is used to adjust the position of the pixel. The new position (x', y') can be calculated as follows:
[0074] x′=x+A×T′(f×x)
[0075] y′=y+B×T′(g×y)
[0076] d. Interpolation and resampling
[0077] The horizontal and vertical coordinates x' and y' of the new position (x', y') may not be integer coordinates. To ensure that the deformed image looks smooth and undistorted, the present invention uses an interpolation method to determine the color value of the new position.
[0078] For the new position (x', y'), find the 4 nearest grid points. Assume that the 4 grid points are (x0, y0), (x1, y0), (x0, y1), (x1, y1), and satisfy:
[0079]
[0080] x1=x0+1
[0081]
[0082] y1=y0+1
[0083] in, Indicates rounding down. After using the above method, the relationship between the new position (x', y') and the positions of the four grid points is as follows: Figure 3 shown.
[0084] Definition 00 ,d 10 ,d 01 ,d 11 Respectively represent the distance between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), (x1, y1). Define the function Its expression is:
[0085]
[0086] Among them, i = 0, 1, and j = 0, 1, β and γ are coefficients, and both coefficients are positive real numbers.
[0087] Let the pixel value at the new position (x', y') be I(x', y'), then I(x', y') can be calculated by the following method:
[0088]
[0089] e. Image deformation
[0090] For each pixel, its new position is calculated, and the new color value is obtained according to the interpolation method, and finally a deformed image with a triangle wave effect is generated.
[0091] (3) Add watermarks to the system or export files
[0092] After the watermark image is generated, embed the image into the system or export the file as required.
[0093] 1) Add the generated watermark image to each interface of the information system.
[0094] 2) For the report or export function of the system, add the generated watermark image to the report file or exported file.
[0095] Example 2
[0096] For the OCR-resistant text watermarking method proposed in the present invention, a more specific example is now given to illustrate the specific implementation process of the method.
[0097] (1) Define watermark attributes
[0098] Define the basic properties of watermarks, which mainly include:
[0099] 1) Determine the watermark text content, such as "2024-09-09 New Digital Technology".
[0100] 2) Set the font of the watermark and use the default font, i.e. Fangsong, bold, font size 16.
[0101] 3) Define the foreground color of the watermark, using the default gray.
[0102] 4) Set the background color of the watermark. If no background color is needed, set it to empty to indicate a transparent background.
[0103] 5)Determine whether to enable ripple effect for watermark, use.
[0104] 6) Determine the rotation angle of the watermark text and use the default value, which is 35 degrees counterclockwise.
[0105] 7) If necessary, if not specified, it will adapt according to the watermark text.
[0106] (2) Generate watermark image
[0107] The generation of watermark images mainly includes the following steps:
[0108] 1) Get the text size
[0109] Using the font defined in the watermark object, the actual width and height of the text are measured to be: 177 pixels and 20 pixels respectively
[0110] 2) Calculate the size of the bounding box after rotation
[0111] Based on the original size of the text and the specified rotation angle, the width and height of the rotated text bounding box are calculated using affine transformation: 156 pixels and 117 pixels respectively.
[0112] 3) Create an image
[0113] Create a new image object based on the width and height of the bounding box plus any additional margins.
[0114] 4) Set up the drawing environment
[0115] Get a Graphics2D context to draw graphics, create a transparent image that is compatible with the device, and set anti-aliasing to make text smoother.
[0116] 5) Set the coordinate system
[0117] Move the origin of the coordinate system to the center of the image. Rotate the coordinate system by the specified rotation angle, that is, 35 degrees counterclockwise.
[0118] 6) Draw text
[0119] Draw the text using the font and color defined in the watermark object. Calculate the position of the text relative to the center of the image and ensure that the text is centered in the image.
[0120] 7) Restore the coordinate system
[0121] When you are finished drawing, end the graphics context.
[0122] 8) Apply ripple effect
[0123] In order to ensure that the text watermark will not be easily identified or removed due to the regular font, the present invention proposes an anti-OCR text watermark method, which achieves deformation by adding a triangular wave ripple effect to the watermark content. The specific steps are:
[0124] a. Define the triangle wave function
[0125] In the present invention, a triangular wave function T(t) is defined, which can calculate the corresponding function value according to the input t value. In one cycle of the triangular wave, the function value increases linearly from the minimum value to the maximum value, and then decreases linearly back to the minimum value. The expression of the triangular wave function T(t) is:
[0126]
[0127] Here, t represents the function variable, t mod 2 represents the remainder when t is divided by 2, and || represents the absolute value.
[0128] In order to make the deformed text more difficult to be recognized by the OCR method, the triangular wave function T(t) was further improved. The improved function T'(t) is expressed as:
[0129]
[0130] The coefficient α is a positive real number, and its value is 0.1.
[0131] The improved function T'(t) increases the complexity of the deformation and improves the difficulty of OCR recognition. At the same time, it can make the deformation smoother and avoid the harsh feeling that may be caused by the triangular wave function T(t).
[0132] b. Determine the amplitude and frequency
[0133] Amplitude and Frequency control the strength and density of the deformation respectively.
[0134] The amplitude and frequency in the horizontal direction are initialized to A=20 and f=10 respectively; the amplitude and frequency in the vertical direction are initialized to B=10 and g=5 respectively.
[0135] c. Apply triangle wave transform
[0136] For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point. Here, the improved function T'(t) is used to adjust the position of the pixel. The new position (x', y') can be calculated as follows:
[0137] x′=x+A×T′(f×x)
[0138] y′=y+B×T′(g×y)
[0139] Take 6 pixels as an example, assuming that these 6 pixels are:
[0140] (10,10),(10,20),(50,10),(50,20),(100,10),(100,20)
[0141] After deformation, the new positions of these 6 points are:
[0142] (12.34,11.93),(12.34,21.17),(50.04,11.93),(50.04,21.17),(100.00,11.93),(100.00,21.17)
[0143] d. Interpolation and resampling
[0144] The horizontal and vertical coordinates x' and y' of the new position (x', y') may not be integer coordinates. To ensure that the deformed image looks smooth and undistorted, the present invention uses an interpolation method to determine the color value of the new position.
[0145] For the new position (x', y'), find the 4 nearest grid points. Assume that the 4 grid points are (x0, y0), (x1, y0), (x0, y1), (x1, y1), and satisfy:
[0146]
[0147] x1=x0+1
[0148]
[0149] y1=y0 + 1
[0150] in, Indicates rounding down.
[0151] For the 5 points in the example, the 4 grid points corresponding to each point are shown in the following table:
[0152] Pixels New Location Grid Points (10,10) (12.34,11.93) (12,11)(13,11)(12,12)(13,12) (10,20) (12.34,21.17) (12,21)(13,21)(12,22)(13,22) (50,10) (50.04,11.93) (50,11)(51,11)(50,12)(51,12) (50,20) (50.04,21.17) (50,21)(51,21)(50,22)(51,22) (100,10) (100.00,11.93) (100,11)(101,11)(100,12)(101,12) (100,20) (100.00,21.17) (100,21)(101,21)(100,22)(101,22)
[0153] Definition 00 , d 10 , d 01 , d 11 They represent the distances between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), and (x1, y1) respectively. In the above example, the calculation yields:
[0154] Pixels <![CDATA[d 00 ]]> <![CDATA[d 10 ]]> <![CDATA[d 01 ]]> <![CDATA[d 11 ]]> (10,10) 0.99 1.14 0.35 0.66 (10,20) 0.38 0.68 0.90 1.06 (50,10) 0.93 1.33 0.08 0.96 (50,20) 0.18 0.97 0.83 1.27 (100,10) 0.93 1.37 0.07 1.00 (100,20) 0.17 1.01 0.83 1.30
[0155] Defining functions Its expression is:
[0156]
[0157] Where i = 0, 1, and j = 0, 1, β and γ are coefficients, both of which are positive real numbers. In this example, the values are 2 and 0.5 respectively. In the above example, after calculation, we can get:
[0158]
[0159] Let the pixel value at the new position (x', y') be I(x', y'), then I(x', y') can be calculated by the following method:
[0160]
[0161] Among them, I(x i ,y j ) represents the point (x i ,y j ) is the pixel value at .
[0162] In the above example, assuming it is a grayscale image, calculation shows that the pixel values of the new positions of the six points are 1, 30, 161, 95, 253, and 255 respectively.
[0163] e. Image deformation
[0164] For each pixel, its new position is calculated, and the new color value is obtained according to the interpolation method, and finally a deformed image with a triangle wave effect is generated.
[0165] (3) Add watermarks to the system or export files
[0166] After the watermark image is generated, embed the image into the system or export the file as required.
[0167] 1) Add the generated watermark image to each interface of the information system.
[0168] 2) For the report or export function of the system, add the generated watermark image to the report file or exported file.
[0169] After using the text watermark method of the present invention, the text watermark effect of the user interface of database related information systems such as database performance monitoring system and database security management system is as follows: Figure 4 As shown. It can be seen that from the user's perspective, this watermark effect will not affect the user's normal experience, and the overall deformation is relatively smooth and has a certain aesthetic appeal. From a security perspective, this watermark adds an improved water ripple effect, which has a complex deformation, making the deformed text more difficult to be recognized by the OCR system.
Claims
1. An OCR-resistant text watermarking method, the method comprising the following steps: (1) Define watermark attributes; (2) Generate watermark image; (3) Add watermarks to the system or export files; Features: In step (2), a triangular wave ripple effect is added to the watermark image to achieve deformation.
2. The OCR-resistant text watermarking method according to claim 1, characterized in that: The steps to add a triangle wave ripple effect are: 2.1 Definition of triangular wave function Where t is the function variable, t mod 2 represents the remainder when t is divided by 2, || represents the absolute value, and α is a positive real number; 2.2 Initialize the amplitude and frequency in the horizontal direction, denoted as A and f respectively; initialize the amplitude and frequency in the vertical direction, denoted as B and g respectively; 2.3 For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point, respectively, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point, respectively. ′ =x+A×T ′ (f×x),y ′ =y+B×T ′ (g×y). 2.4 For the new position (x', y'), find the 4 nearest grid points (x0, y0), (x1, y0), (x0, y1), (x1, y1), we have in, Indicates rounding down; d 00 ,d 10 ,d 01 ,d 11 Calculate the distances between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), and (x1, y1) respectively. Where i = 0, 1, and j = 0, 1, β and γ are coefficients, both positive real numbers, then the pixel value at the new position (x', y') is I(x i ,y j ) is the point (x i ,y j ) at the pixel value; 2.5 For each pixel, calculate its new position and get the new color value according to the interpolation method, and finally generate a deformed image with a triangle wave effect.
3. An OCR-resistant text watermark system, the system comprising: (1) Watermark attribute definition module; (2) Watermark image generation module; (3) Watermark adding module; The feature is that in the watermark image generation module, a triangular wave ripple effect is added to the watermark content to achieve deformation.
4. The OCR-resistant text watermark system according to claim 3, characterized in that: The steps to add a triangle wave ripple effect are: 2.1 Definition of triangular wave function Where t is the function variable, t mod 2 represents the remainder when t is divided by 2, || represents the absolute value, and α is a positive real number; 2.2 Initialize the amplitude and frequency in the horizontal direction, denoted as A and f respectively; initialize the amplitude and frequency in the vertical direction, denoted as B and g respectively; 2.3 For each pixel point (x, y) in the image, where x and y represent the horizontal and vertical coordinates of the pixel point, respectively, calculate its new position (x', y') in the deformed image, where x' and y' represent the horizontal and vertical coordinates of the new position of the pixel point, respectively. ′ =x+A×T ′ (f×x),y ′ =y+B×T ′ (g×y). 2.4 For the new position (x', y'), find the 4 nearest grid points (x0, y0), (x1, y0), (x0, y1), (x1, y1), we have x1=x0+1, y1=y0+1, where Indicates rounding down; d 00 ,d 10 ,d 01 ,d 11 Calculate the distances between the new position (x', y') and the points (x0, y0), (x1, y0), (x0, y1), and (x1, y1) respectively. Where i = 0, 1, and j = 0, 1, β and γ are coefficients, both positive real numbers, then the pixel value at the new position (x', y') is I(x i ,y j ) is the point (x i ,y j ) at the pixel value; 2.5 For each pixel, calculate its new position and get the new color value according to the interpolation method, and finally generate a deformed image with a triangle wave effect.