Signature image generation method and device, computer equipment and readable storage medium
By generating a target mask image containing the occluded area to erase the initial signature image, the problem of insufficient negative sample data is solved and the accuracy of font stroke missing detection is improved.
Patent Information
- Application Number
- CN202510535322.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-09-05
AI Technical Summary
In the prior art, due to the small number of signature image samples with missing font strokes, the algorithm model has a low accuracy in detecting missing font strokes.
The initial signature image is erased by generating a target mask image containing the occluded area to generate a sample signature image with missing font strokes. The processed signature image that meets the preset relationship is used as the sample signature image to enrich the negative sample data.
The algorithm model's detection accuracy for missing font strokes is improved, negative sample data is enhanced, and the problem of low detection accuracy caused by missing sample data is reduced.
Smart Images

Figure CN120599093A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of artificial intelligence technology and financial technology, and specifically to a signature image generation method, apparatus, computer equipment, and computer-readable storage medium. Background Art
[0002] With the continuous development of human civilization and information technology, signatures are increasingly required for legal validity in more and more scenarios, such as leasing in the financial sector. However, in real-world business scenarios, signatures may be intentionally or unintentionally missing strokes. When signatures are missing, they lose their legal validity.
[0003] Related technologies use algorithms to detect missing font strokes in signature images to reduce the occurrence of illegal signatures. However, due to the relatively small number of signature image samples with missing font strokes (i.e., negative samples), it is difficult to collect negative samples for the algorithm model. Consequently, the algorithm model has low accuracy in detecting missing font strokes due to the lack of sample data. Summary of the Invention
[0004] The present application provides a signature image generation method, apparatus, computer equipment and computer-readable storage medium, which belong to the field of artificial intelligence technology. The method can generate sample signature images with missing font strokes, enrich the negative sample data of the signature font stroke missing detection algorithm model, and improve the detection accuracy of the algorithm model for font stroke missing to a certain extent.
[0005] In a first aspect, the present application provides a method for generating a signature image, the method comprising:
[0006] Get the initial signature image;
[0007] generating a target mask image including a blocked area according to the pixel size of the initial signature image;
[0008] Erasing the initial signature image based on the target mask image to obtain a processed signature image;
[0009] If the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship, the processed signature image is used as a sample signature image.
[0010] In a second aspect, the present application provides a signature image generation device, the signature image generation device comprising:
[0011] an acquiring unit, configured to acquire an initial signature image;
[0012] a generating unit, configured to generate a target mask image including a blocked area according to a pixel size of the initial signature image;
[0013] a processing unit, configured to perform erasing processing on the initial signature image based on the target mask image to obtain a processed signature image;
[0014] The processing unit is further configured to use the processed signature image as a sample signature image if a relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship.
[0015] In a third aspect, the present application further provides a computer device comprising a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement the signature image generation method when executing the computer program.
[0016] In a fourth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, and the computer program is loaded by a processor to execute the signature image generation method.
[0017] In the present application, on the one hand, the processed signature image is obtained by erasing the initial signature image based on the target mask image containing the occlusion area, and the occlusion area of the target mask image can be used to occlude the pixels of the initial signature image; on the other hand, since the processed signature image is used as the sample signature image only when the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image meets the preset relationship (such as the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image, the ratio of the number of font pixels of the processed signature image to the number of font pixels of the initial signature image is less than the preset ratio threshold, etc.), the font strokes of the initial signature image can be occluded and erased by the target mask image to achieve the effect of incomplete font, thereby generating a sample signature image with missing font strokes, enriching the negative sample data of the signature font stroke missing detection algorithm model, and thus improving the detection accuracy of the algorithm model for font stroke missing to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 This is a flow chart of a signature image generation method provided by an embodiment of the present application;
[0020] Figure 2 This is a schematic diagram illustrating the font stroke erasure process provided in an embodiment of the present application;
[0021] Figure 3 This is a flowchart of an embodiment of step 1022A in the embodiment of the present application;
[0022] Figure 4 This is another example flow chart of step 1022A in the embodiment of the present application;
[0023] Figure 5 This is a flow chart of an embodiment of step 102 in the embodiment of the present application;
[0024] Figure 6 This is a schematic diagram of the structure of an embodiment of a signature image generation device provided in an embodiment of the present application;
[0025] Figure 7 This is a schematic block diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0027] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, combined, or partially merged, so the actual execution order may vary depending on the actual situation.
[0028] In the description of the embodiments of the present application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0029] In order to enable any person skilled in the art to implement and use the present application, the following description is provided. In the following description, details are listed for the purpose of explanation. It should be understood that one of ordinary skill in the art will recognize that the present application can be implemented without using these specific details. In other examples, well-known processes will not be elaborated in detail to avoid obscuring the description of the embodiments of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in accordance with the embodiments of the present application.
[0030] Embodiments of the present application provide a signature image generation method, apparatus, computer device, and computer-readable storage medium.
[0031] The execution entity of the signature image generation method of the embodiment of the present application can be the signature image generation device provided in the embodiment of the present application, or the computer device provided in the embodiment of the present application, wherein the signature image generation device can be implemented in hardware or software.
[0032] The following embodiments of the present application are described in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments may be combined with each other.
[0033] See also Figure 1 , Figure 1 101 to 104, wherein:
[0034] 101. Obtain an initial signature image.
[0035] The initial signature image is an image containing the signature font, specifically, an image containing the complete signature font. The initial signature image can be collected based on actual business scenario requirements. For example, in a leasing scenario in the financial sector, a lease contract signature image can be captured by photographing the signature, and then used as the initial signature image.
[0036] 102. Generate a target mask image including a blocked area according to the pixel size of the initial signature image.
[0037] The target mask image is used to erase the signature font strokes in the initial signature image. The target mask image can be a binary image or a grayscale image. Each pixel value in the target mask image determines whether the corresponding area in the initial signature image is hidden or retained. For example, taking the target mask image as a binary image, assuming that a pixel point in the target mask image has a first preset pixel value (such as the first pixel value is 1), the pixel point at the corresponding position in the initial signature image is retained, and when it has a second preset pixel value (such as the second pixel value is 0), the pixel point at the corresponding position in the initial signature image is hidden, thereby erasing the signature font strokes in the initial signature image.
[0038] For example, first, a mask image of the initial signature image can be generated according to the pixel size of the initial signature image; then, an occlusion area is generated on the mask image to obtain a preliminary mask image containing the occlusion area; and then the target mask image is determined based on the preliminary mask image.
[0039] In step 102, there are multiple ways to generate the target mask image, illustratively including:
[0040] (1) In some embodiments, a mask image is generated according to the pixel size of the initial signature image. After randomly generating one or more occlusion regions on the mask image, a preliminary mask image containing the one or more occlusion regions is obtained. The preliminary mask image is directly used as the target mask image. In this case, step 102 may specifically include the following steps 1021A to 1023A:
[0041] 1021A. Generate a mask image of the initial signature image according to the pixel size of the initial signature image.
[0042] Please refer to Figure 2 , Figure 2 This is a schematic diagram illustrating the font stroke erasure process provided in the embodiment of the present application. Figure 2 (a) represents the initial signature image, (b) represents the mask image, (c) represents the target occlusion image, and (d) represents the processed signature image. Figure 2 Each small square in the figure represents a pixel, and the number in each small square represents the pixel value of the pixel position. It can be understood that for the sake of convenience, Figure 2 The image is shown in a simplified pixel size format. Figure 2 The image pixel sizes shown do not directly represent the actual image pixel sizes.
[0043] Taking the target mask image as a binary image as an example, assuming that the pixel size of the initial signature image is 3000 pixels * 2000 pixels, then in step 1021A, an image with a pixel size of 3000 pixels * 2000 pixels and pixel values initialized to a first preset pixel value (such as the first preset pixel value is 1) can be generated as the mask image of the initial signature image; Figure 2 As shown in (b), an image with a pixel size of 3000 pixels * 2000 pixels and a pixel value initialized to 1 can be generated as a mask image of the initial signature image.
[0044] Among them, the specific value of the first preset pixel value can be set according to the actual business scenario requirements, and the specific value of the first preset pixel value is not limited here.
[0045] 1022A. Generate an occlusion area on the mask image to obtain a preliminary mask image including the occlusion area.
[0046] The preliminary mask image refers to a mask image containing the occlusion area after the occlusion area is generated on the mask image.
[0047] Exemplarily, one or more occlusion areas can be randomly generated on the mask image, such as one or more circular occlusion areas, rectangular occlusion areas, triangular occlusion areas, diamond occlusion areas, etc., and the mask image containing circular occlusion areas, rectangular occlusion areas, triangular occlusion areas or diamond occlusion areas, etc. is used as the preliminary mask image.
[0048] Depending on the generation of the occlusion area, there are multiple ways to determine the preliminary mask image in step 1022A. For example, the following ways include: ①, ②, and ③:
[0049] ① In some embodiments, the preliminary mask image includes one or more circular occlusion areas. Figure 3 As shown, step 1022A may specifically include the following steps A1 to A4:
[0050] A1. Obtain a random center pixel point from each pixel point of the mask image.
[0051] A2. Get the radius of the random circle.
[0052] A3. Generate a circular occlusion area on the mask image based on the random circle center pixel point and the random circle radius.
[0053] For example, Figure 2As shown in (c), assuming that the pixel value of each pixel in the mask image is initialized to a first preset pixel value (such as the first preset pixel value is 1), the pixel point a in the mask image can be used as the random center pixel point and the random circle radius is 2 pixels in length. At this time, the random center pixel point (such as pixel point a) is used as the center of the circle and the random circle radius (such as the length of 2 pixels) is used as the radius of the circle to form a random circular area on the mask image, and the pixels in the random circular area are set to a second preset pixel value (such as the second preset pixel value is 0), thereby generating a circular occlusion area on the mask image.
[0054] Among them, the specific value of the second preset pixel value can be set according to the actual business scenario requirements, and the specific value of the second preset pixel value is not limited here.
[0055] A4. Use the mask image containing the circular occlusion area as the preliminary mask image.
[0056] ② In some embodiments, the preliminary mask image includes one or more rectangular occlusion areas. Figure 4 As shown, step 1022A may specifically include the following steps B1 to B4:
[0057] B1. Obtain random rectangular corner pixel points from each pixel point of the mask image.
[0058] B2. Get the random rectangle length and random rectangle width.
[0059] B3. Generate a rectangular occlusion area on the mask image based on the pixels of the random rectangle corner points, the length of the random rectangle, and the width of the random rectangle.
[0060] For example, Figure 2 As shown in (c), taking the random rectangle corner pixel point being the upper left corner point of the rectangle as an example, assuming that the pixel value of each pixel point in the mask image is initialized to a first preset pixel value (such as the first preset pixel value is 1), the pixel point b in the mask image can be used as the random circle center pixel point, the random rectangle length is 2 pixels in length, and the random rectangle width is 2 pixels in length. At this time, the random rectangle corner pixel point (such as pixel point b) is used as the upper left corner point of the rectangle, the random rectangle length (such as the length of 2 pixels) is used as the rectangle length, and the random rectangle width (such as the length of 2 pixels) is used as the rectangle width. A random rectangular area is formed on the mask image, and the pixels in the random rectangular area are set to a second preset pixel value (such as the second preset pixel value is 0), thereby generating a rectangular occlusion area on the mask image.
[0061] B4. Use the mask image containing the rectangular occlusion area as the preliminary mask image.
[0062] ③ In some embodiments, the preliminary mask image includes one or more circular occlusion areas and one or more rectangular occlusion areas. In this case, step 1022A may specifically include the following steps C1 to C7:
[0063] C1. Obtain a random center pixel point from each pixel point of the mask image.
[0064] C2. Get the radius of the random circle.
[0065] C3. Generate a circular occlusion area on the mask image based on the random circle center pixel point and the random circle radius.
[0066] The implementation of steps C1 to C3 is similar to that of steps A1 to A3. For details, please refer to the relevant description above and will not be repeated here.
[0067] C4. Obtain random rectangular corner pixel points from each pixel point of the mask image.
[0068] C5. Get the random rectangle length and random rectangle width.
[0069] C6. Generate a rectangular occlusion area on the mask image based on the pixels of the random rectangle corner points, the length of the random rectangle, and the width of the random rectangle.
[0070] The implementation of steps C4 to C6 is similar to that of steps B1 to B3. For details, please refer to the relevant description above and will not be repeated here.
[0071] C7. Use the mask image containing the circular occlusion area and the mask image containing the rectangular occlusion area as the preliminary mask image.
[0072] 1023A. Use the preliminary mask image as the target mask image.
[0073] (2) In some embodiments, a mask image is generated according to the pixel size of the initial signature image, and one or more occlusion areas are randomly generated on the mask image to obtain a preliminary mask image containing one or more occlusion areas; the preliminary mask image is then processed, such as moving the occlusion areas and rotating the preliminary mask image, to obtain an image as the target mask image. In this case, Figure 5 As shown, step 102 may specifically include the following steps 1021B to 1023B:
[0074] 1021B. Generate a mask image of the initial signature image according to the pixel size of the initial signature image.
[0075] 1022B. Generate an occlusion area on the mask image to obtain a preliminary mask image including the occlusion area.
[0076] The implementation of steps 1021B to 1022B is similar to that of steps 1021A to 1022A. For details, please refer to the relevant description above and will not be repeated here.
[0077] 1023B. Perform post-processing on the preliminary mask image to obtain the target mask image, wherein the post-processing includes at least one of moving the occluded area and rotating the preliminary mask image.
[0078] There are many ways to implement step 1023B, illustratively including the following: <1> to <3> :
[0079] <1> In some embodiments, the occlusion region of the preliminary mask image is moved to obtain a target mask image.
[0080] Depending on the occlusion area included in the preliminary mask image, there are multiple ways to move the occlusion area of the preliminary mask image. For example, the following ways <1.1> to <1.3> are included:
[0081] <1.1> In one embodiment, the preliminary mask image includes a circular occlusion area, and the circular occlusion area is moved. In this case, in step 1023B, the circular occlusion area in the preliminary mask image can be moved according to a first preset movement strategy (for example, when the circular occlusion area is greater than the first range right value * the font area of the preliminary signature image, such as when the circular occlusion area is greater than 30% * the font area of the preliminary signature image, the circular occlusion area is moved away from the font area; when the circular occlusion area is less than or equal to the first range left value * the font area of the preliminary signature image, such as when the circular occlusion area is less than or equal to 5% * the font area of the preliminary signature image, the circular occlusion area is moved toward the font area so that the coverage of the circular occlusion area to the font area is within a first preset coverage range, such as 5% to 30%). The preliminary mask image containing the circular occlusion area and after the circular occlusion area is moved is used as the target mask image. By moving the circular occlusion area in the preliminary mask image according to the first preset movement strategy, on the one hand, the problem that the sample signature image cannot be used as valid sample data due to the circular occlusion area occluding too much of the strokes in the initial signature image can be avoided; on the other hand, the problem that the sample signature image has a high similarity with the initial signature image and the sample signature image cannot be used as valid sample data due to the circular occlusion area occluding too little of the strokes in the initial signature image can be avoided.
[0082] The first preset movement strategy refers to the movement strategy of the circular occlusion area. The first preset movement strategy can be set according to actual business scenario requirements, and there is no restriction on the setting of the first preset movement strategy here.
[0083] Among them, the specific value of the first preset coverage range can be set according to the actual business scenario requirements. There is no restriction on the specific value of the first preset coverage range here. For example, the first preset coverage range can be 5% to 30%, 10% to 20%, etc.
[0084] The first range right value refers to the maximum value of the first preset coverage range.
[0085] The left value of the first range refers to the minimum value of the first preset coverage range.
[0086] <1.2> In one embodiment, the preliminary mask image includes a rectangular occlusion area, and the rectangular occlusion area is moved. In this case, in step 1023B, the rectangular occlusion area in the preliminary mask image can be moved according to a second preset movement strategy (for example, when the rectangular occlusion area is greater than the right value of the second range * the font area of the preliminary signature image, such as when the rectangular occlusion area is greater than 20% * the font area of the preliminary signature image, the rectangular occlusion area is moved away from the font area; when the rectangular occlusion area is less than or equal to the left value of the second range * the font area of the preliminary signature image, such as when the rectangular occlusion area is less than or equal to 10% * the font area of the preliminary signature image, the rectangular occlusion area is moved toward the font area so that the coverage of the font area by the rectangular occlusion area is within a second preset coverage range, such as 10% to 20%). The preliminary mask image containing the rectangular occlusion area and after the rectangular occlusion area is moved is used as the target mask image. By moving the rectangular occlusion area in the preliminary mask image according to the second preset movement strategy, on the one hand, the problem that the sample signature image cannot be used as valid sample data due to the rectangular occlusion area occluding too much of the strokes in the initial signature image can be avoided; on the other hand, the problem that the sample signature image has a high similarity with the initial signature image and the sample signature image cannot be used as valid sample data due to the rectangular occlusion area occluding too little of the strokes in the initial signature image can be avoided.
[0087] The second preset movement strategy refers to the movement strategy of the rectangular occlusion area. The second preset movement strategy can be set according to actual business scenario requirements, and there is no restriction on the setting of the second preset movement strategy here.
[0088] Among them, the specific value of the second preset coverage range can be set according to the actual business scenario requirements. There is no restriction on the specific value of the second preset coverage range here. For example, the second preset coverage range can be 10% to 20%, 15% to 20%, etc.
[0089] <1.3> In some embodiments, the preliminary mask image includes a circular occlusion region and a rectangular occlusion region, and the circular occlusion region and / or the rectangular occlusion region are moved. In this case, in step 1023B, the circular occlusion region in the preliminary mask image can be moved according to a first preset movement strategy, and the preliminary mask image including the rectangular occlusion region and the preliminary mask image including the circular occlusion region after the circular occlusion region is moved can be used as the target mask image. Alternatively, the rectangular occlusion region in the preliminary mask image can be moved according to a second preset movement strategy, and the preliminary mask image including the circular occlusion region and the preliminary mask image including the rectangular occlusion region after the rectangular occlusion region is moved can be used as the target mask image. Alternatively, the circular occlusion region in the preliminary mask image can be moved according to the first preset movement strategy, and the rectangular occlusion region in the preliminary mask image can be moved according to the second preset movement strategy, and the preliminary mask image including the circular occlusion region after the circular occlusion region is moved and the preliminary mask image including the rectangular occlusion region after the rectangular occlusion region is moved can be used as the target mask image.
[0090] <2> In some embodiments, after rotating the preliminary mask image, a target mask image is obtained. In this case, in step 1023B, the preliminary mask image can be rotated according to a random rotation angle to obtain a rotated result image, which serves as the target mask image. For example, the preliminary mask image containing the rectangular masking area can be randomly rotated by a small angle, such as within ±10 degrees, to simulate the tilt of the font itself, thereby improving the naturalness of erasing the font strokes using the rectangular masking area, and thereby improving the authenticity of the incomplete signature effect of the sample signature image.
[0091] <3> In some embodiments, the occlusion region of the preliminary mask image is moved and the preliminary mask image is rotated to obtain a target mask image.
[0092] 103. Erasing the initial signature image based on the target mask image to obtain a processed signature image.
[0093] There are many ways to implement step 103, illustratively including:
[0094] (1) In some embodiments, the result of multiplying the pixel value of each pixel point in the initial signature image with the pixel value of the corresponding position pixel point in the target mask image can be used as the processed signature image. For example, Figure 2As shown in (a), (c) and (d), the result obtained by multiplying the pixel value of the pixel point in the i-th row and j-th column of the initial signature image with the pixel value of the pixel point in the i-th row and j-th column of the target mask image can be used as the pixel value of the pixel point in the i-th row and j-th column of the processed signature image, where 1≤i≤M, 1≤j≤N, M and N are the height and width of the initial signature image respectively. For example, the pixel value of the pixel point in the 1st row and 1st column of the initial signature image and the pixel value of the pixel point in the 1st row and 1st column of the target mask image are multiplied as the pixel value of the pixel point in the 1st row and 1st column of the processed signature image, and the pixel value of the pixel point in the 1st row and 2nd column of the initial signature image is used as the pixel value of the pixel point in the 1st row and 1st column of the processed signature image. The pixel value of the pixel point in the 1st row and 2nd column of the target mask image is multiplied by the pixel value as the pixel value of the 1st row and 2nd column of the processed signature image, ..., the pixel value of the pixel point in the 1st row and Nth column of the initial signature image is multiplied by the pixel value of the pixel point in the 1st row and Nth column of the target mask image as the pixel value of the 1st row and Nth column of the processed signature image, ..., the pixel value of the pixel point in the Mth row and Nth column of the initial signature image is multiplied by the pixel value of the Mth row and Nth column of the target mask image as the pixel value of the Mth row and Nth column of the processed signature image, and so on, to finally obtain the processed signature image.
[0095] In this way, by multiplying the pixel value of each pixel point in the initial signature image with the pixel value of the corresponding position pixel point in the target mask image, since the pixel value of the pixel point in the occluded area in the target mask image is the second preset pixel value (such as the second preset pixel value is 0), the pixel value of the pixel point in the initial signature image corresponding to the occluded area is set to 0. In this way, the pixel value of the pixel point where the font stroke is located can be reset, thereby achieving the font stroke erasing effect of the initial signature image.
[0096] (2) In some embodiments, a result image obtained by multiplying the pixel value of each pixel point in the initial signature image by the pixel value of the corresponding position pixel point in the target mask image can be used as an intermediate signature image; the intermediate signature image is then corroded to obtain a corroded image; and the corroded image is then dilated to obtain a dilated image, which is used as the processed signature image. For example, the cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel) algorithm can be used to perform an opening operation on the intermediate signature image, thereby corroding the intermediate signature image to obtain a corroded image, and then dilating the corroded image to obtain a dilated image, which is used as the processed signature image. In the cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel) algorithm, kernel is a structuring element (or kernel), which can be a 5x5 matrix of all ones. img represents the input intermediate signature image, and cv2.MORPH_OPEN is an "opening" operation, which consists of two steps: erosion (which removes small objects in the image, shrinking white areas and expanding black areas) and dilation (which expands the remaining white areas, filling the gaps left by the erosion and restoring some of the shape). By performing the opening operation on the intermediate signature image, first eroding and then dilating it, the sharp edges of the font strokes, implemented by the occluded areas, can be "melted" into the necessary structure and unclean strokes can be erased.
[0097] 104. If the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship, use the processed signature image as a sample signature image.
[0098] Exemplarily, first, on the one hand, the number of font pixels of the initial signature image is counted. For example, the number of font pixels of the initial signature image can be counted based on the binary image of the initial signature image: first, the preliminary signature image (denoted as img_before) is converted into a binary image. For example, the pixel value of the pixel point where the signature font is located in the preliminary signature image img_before is set to a third preset pixel value (such as the third preset pixel value is 255), and the pixel value of the pixel point where the non-signature font is located is set to a fourth preset pixel value (such as the fourth preset pixel value is 0), thereby obtaining a binary image of the preliminary signature image img_before; then, the total number of pixel points of the third preset pixel value in the binary image of the preliminary signature image img_before is counted as the number of font pixels of the initial signature image img_before (denoted as before_sum). On the other hand, the number of font pixels in the processed signature image can be counted. For example, the number of font pixels of the initial signature image can be counted based on the binary image of the processed signature image: first, the processed signature image (denoted as img_after) is converted into a binary image. For example, the pixel value of the pixel point where the signature font is located in the processed signature image img_after is set to a third preset pixel value (such as the third preset pixel value is 255), and the pixel value of the pixel point where the non-signature font is located is set to a fourth preset pixel value (such as the fourth preset pixel value is 0), thereby obtaining the binary image of the processed signature image img_after; then, the total number of pixels of the third preset pixel value in the binary image of the processed signature image img_after is counted as the number of font pixels of the processed signature image img_after (denoted as after_sum). Next, the relationship between the number of font pixels after_sum in the processed signature image img_after and the number of font pixels before_sum in the initial signature image img_before satisfies a preset relationship. If the relationship between the number of font pixels after_sum and the number of font pixels before_sum does satisfy the preset relationship, the processed signature image img_after is used as the sample signature image. If the relationship between the number of font pixels after_sum and the number of font pixels before_sum does not satisfy the preset relationship, the processed signature image img_after is used as the initial signature image in steps 102-103. Steps 102-103 are repeated until the relationship between the number of font pixels in the processed signature image and the number of font pixels in the initial signature image obtained in step 101 satisfies the preset relationship. The resulting processed signature image is then used as the sample signature image.
[0099] Among them, the specific value of the third preset pixel value and the specific value of the fourth preset pixel value can be set according to the actual business scenario requirements. There is no restriction on the specific value of the third preset pixel value and the specific value of the fourth preset pixel value.
[0100] Among them, the preset relationship can be set according to the actual business scenario requirements, for example, the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image, and the ratio of the number of font pixels of the processed signature image to the number of font pixels of the initial signature image is less than a preset ratio threshold, etc.
[0101] In some embodiments, taking "the preset relationship is that the font remaining ratio of the initial signature image is less than the preset ratio threshold" as an example, at this time, the ratio of the number of font pixels of the processed signature image after_sum to the number of font pixels of the initial signature image img_before can be obtained as the font remaining ratio of the initial signature image (denoted as a%); when the font remaining ratio of the initial signature image is less than the preset ratio threshold, the processed signature image is used as the sample signature image; when the font remaining ratio of the initial signature image is greater than or equal to the preset ratio threshold, the processed signature image is used as the initial signature image in steps 102 to 103, and the process of steps 102 to 103 is repeated until the font pixel number of the processed signature image is equal to that of step 101. The relationship between the number of font pixels in the initial signature image satisfies the preset relationship (i.e., the font remaining ratio a% in step 101 is less than the preset ratio threshold). Since (100%-font remaining ratio a%) reflects the font erasure ratio, it is possible to determine whether the target occluded image has erased the valid signature pixels based on the font remaining ratio, thereby reducing the occurrence of invalid erasure, thereby avoiding the mixing of positive samples into negative samples (i.e., signature image samples with missing font strokes). As a result, nearly realistic incomplete signature effects can be achieved in batches, and negative samples of the font stroke missing detection algorithm model (i.e., signature image samples with missing font strokes) can be generated in batches, which to a certain extent reduces the problem of low accuracy of the algorithm model in detecting font stroke missing due to missing sample data.
[0102] In some embodiments, taking "the preset relationship is that the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image" as an example, when the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image, the processed signature image is used as a sample signature image; when the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image, but is greater than or equal to a preset ratio threshold, the processed signature image is used as the initial signature image in steps 102 to 103, and the process of steps 102 to 103 is repeated until the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image in step 101. In this way, according to whether the number of font pixels in the processed signature image is less than the number of font pixels in the initial signature image, it is determined whether the target occluded image has erased the valid signature pixels, thereby reducing the occurrence of invalid erasure, thereby avoiding the mixing of positive samples in negative samples (i.e., signature image samples with missing font strokes). As a result, nearly realistic incomplete signature effects can be achieved in batches, and negative samples of the font stroke missing detection algorithm model (i.e., signature image samples with missing font strokes) can be generated in batches, which to a certain extent reduces the problem of low accuracy of the algorithm model in detecting font stroke missing due to missing sample data.
[0103] Based on the above steps 101 to 104, multiple sample signature images after the font strokes are erased can be obtained. Furthermore, the sample signature images can be used as negative samples of the algorithm model, and the preset stroke loss detection model can be trained using the generated multiple sample signature images to obtain a trained stroke loss detection model. In this way, the number of negative samples of the algorithm model can be enriched, sample data enhancement can be achieved, and the problem of difficulty in collecting negative samples of the algorithm model can be solved to a certain extent, thereby improving the accuracy of the algorithm model in detecting font stroke loss. For example, in a signature recognition system for a rental scenario in the financial business field, the sample signature images generated by the signature image generation method are used for the algorithm model training of the rental scenario signature recognition system, which can improve the accuracy of the rental scenario signature recognition system in detecting font stroke loss, improve the accuracy of detecting illegal signatures, and reduce the occurrence of illegal signatures in rental scenarios.
[0104] For better understanding, the following is a specific example to illustrate the signature image generation process in the embodiment of the present application, as follows:
[0105] 1. Get the signature image as the initial signature image img_before.
[0106] 2. Convert the initial signature image img_before into a binary image. For example, the initial signature image img_before can be converted into a binary image with a black background (e.g., the pixel value of the pixel where the font is located is set to 0) and white text (e.g., the pixel value of the pixel where the font is located is set to 255).
[0107] 3. By calculating the grayscale histogram (denoted as hist) of the binary image of the initial signature image img_before, the number of white pixel points, that is, the number of pixel points with a pixel value of 255, is counted as the number of font pixels before_sum in the initial signature image img_before.
[0108] 4. Set after_sum and initialize after_sum. For example, after_sum can be initialized as after_sum = before_sum, where after_sum is used to record the number of font pixels in the processed signature image, and before_sum is used to record the number of font pixels in the initial signature image.
[0109] 5. Repeat steps 5.1 to 5.5 until after_sum < a% * before_sum (that is, the effective occlusion erasure of the font strokes reaches more than (100 - a)%).
[0110] 5.1. Create a mask image mask with the same pixel size as the initial signature image img_before, and initialize the pixel values of the mask image mask to 1.
[0111] 5.2. Randomly generate several occlusion regions on the mask image mask (such as some random circular occlusion regions and rectangular occlusion regions), and use the mask image mask after generating the occlusion regions as the target occlusion image (denoted as mask'). For example, it can be as follows:
[0112] ① Generate circular occlusion regions: Randomly generate the center coordinates and the radius size, and set the region to 0.
[0113] ② Generate rectangular occlusion regions: Randomly generate the upper left corner coordinates of the rectangle, the length and width of the rectangle, and then determine the rectangle range with the horizontal and vertical sides, and set the range to 0.
[0114] ③ After randomly generating several occlusion regions on the mask image mask, rotate the mask image mask randomly (such as using cv2.getRotationMatrix2D) by a small angle (such as within plus or minus 10 degrees) to imitate the inclination of the font itself, and use the rotated mask image mask as the target occlusion image mask'.
[0115] 5.3. Multiply the pixel values of the corresponding pixel points of the initial signature image img_before and the target occlusion image mask' to obtain the intermediate signature image. For example, it can be as follows:
[0116] ① Traverse each row of the initial signature image img_before row by row:
[0117] ② Traverse the pixels of the i-th row of the initial signature image img_before by column:
[0118] ③ Multiply the pixel value of the pixel at the i-th row and j-th column of the initial signature image img_before by the pixel value of the pixel at the i-th row and j-th column of the target occlusion image mask'. Where the target occlusion image mask' is 0, the pixels will be erased.
[0119] ④ Repeat ① to ③ until all pixels of the initial signature image img_before are traversed, and the resulting image after multiplication is used as the intermediate signature image. At this time, the intermediate signature image is obtained to achieve the font stroke erasing effect.
[0120] 5.4. Perform an opening operation on the intermediate signature image to obtain the processed signature image img_after:
[0121] For example, use the cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel) algorithm to perform an opening operation on the intermediate signature image to obtain the processed signature image img_after. The kernel can be a 5x5 matrix of all 1s.
[0122] 5.5. By calculating the grayscale histogram hist of the binary image of the processed signature image img_after, the number of white pixels, that is, the number of pixels with a pixel value of 255, is counted as the number of font pixels after_sum in the processed signature image img_after.
[0123] 6. Save the processed signature image img_after to a new image file, that is, generate an illegal signature image with missing font strokes (i.e., a sample signature image).
[0124] Furthermore, when the number of pictures actually containing signatures (i.e., initial signature images) is small, incomplete signatures can be generated multiple times for the same picture actually containing signatures (i.e., multiple sample signature images are generated using the same initial signature image). Since the occlusion area and position size are random, no repeated images will appear when multiple sample signature images are generated using the same initial signature image, thereby achieving further data enhancement.
[0125] From the above content, it can be seen that, on the one hand, the processed signature image is obtained by erasing the initial signature image based on the target mask image containing the occlusion area, and the occlusion area of the target mask image can be used to occlude the pixels of the initial signature image; on the other hand, since the processed signature image is used as the sample signature image only when the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image meets the preset relationship (such as the number of font pixels of the processed signature image is less than the number of font pixels of the initial signature image, the ratio of the number of font pixels of the processed signature image to the number of font pixels of the initial signature image is less than the preset ratio threshold, etc.), the font strokes of the initial signature image can be occluded and erased by the target mask image to achieve the effect of incomplete font, thereby generating a sample signature image with missing font strokes, enriching the negative sample data of the signature font stroke missing detection algorithm model, and thus improving the detection accuracy of the algorithm model for font stroke missing to a certain extent. Third, the inherent connectivity of individual strokes allows for the deletion of some strokes from a signature font. In this embodiment, a mask image is used to erase font strokes, rather than using a connected region deletion task. This avoids the problem of the connected region deletion task being unable to effectively delete font strokes due to densely written characters. Fourth, by using an opening operation to first erode and then dilate the intermediate signature image, obscured sharp edges can be "melted" into a pen-shaped structure, eliminating strokes that were not cleanly erased, thereby achieving a near-realistic incomplete signature effect in batches. Fifthly, by judging whether the font remaining ratio a% is less than the preset ratio threshold, since (100% - font remaining ratio a%) reflects the font erasure ratio, it is possible to determine whether the target occluded image has erased the valid signature pixels based on the font remaining ratio, thereby reducing the occurrence of invalid erasure, thereby avoiding the mixing of positive samples in negative samples (i.e., signature image samples with missing font strokes). As a result, nearly realistic incomplete signature effects can be achieved in batches, and negative samples of the font stroke missing detection algorithm model (i.e., signature image samples with missing font strokes) can be generated in batches, which to a certain extent reduces the problem of low accuracy of the algorithm model in detecting font stroke missing due to missing sample data.
[0126] In addition, in order to better implement the signature image generation method in the embodiment of the present application, based on the signature image generation method, the embodiment of the present application also provides a signature image generation device, such as Figure 6 FIG. 1 is a schematic diagram of the structure of an embodiment of a signature image generation device provided in an embodiment of the present application. The signature image generation device 600 includes:
[0127] An acquisition unit 601 is used to acquire an initial signature image;
[0128] A generating unit 602 is configured to generate a target mask image including an occluded area according to the pixel size of the initial signature image;
[0129] The processing unit 603 is configured to perform erasing processing on the initial signature image based on the target mask image to obtain a processed signature image;
[0130] The processing unit 603 is further configured to use the processed signature image as a sample signature image if the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship.
[0131] In some embodiments, the generating unit 602 is specifically configured to:
[0132] generating a mask image of the initial signature image according to the pixel size of the initial signature image;
[0133] generating an occlusion region on the mask image to obtain a preliminary mask image including the occlusion region;
[0134] The target mask image is determined according to the preliminary mask image.
[0135] In some embodiments, the generating unit 602 is specifically configured to:
[0136] Obtaining a random center pixel point from each pixel point of the mask image;
[0137] Get the radius of a random circle;
[0138] Generating a circular occlusion area on the mask image based on the random circle center pixel point and the random circle radius;
[0139] The mask image containing the circular occlusion area is used as the preliminary mask image.
[0140] In some embodiments, the generating unit 602 is specifically configured to:
[0141] Obtaining random rectangular corner pixel points from each pixel point of the mask image;
[0142] Get the random rectangle length and random rectangle width;
[0143] Generating a rectangular occlusion area on the mask image based on the random rectangle corner pixel points, the random rectangle length and the random rectangle width;
[0144] The mask image containing the rectangular occlusion area is used as the preliminary mask image.
[0145] In some embodiments, the generating unit 602 is specifically configured to:
[0146] The preliminary mask image is rotated according to a random rotation angle to obtain the target mask image.
[0147] In some embodiments, the processing unit 603 is specifically configured to:
[0148] Multiplying the pixel value of each pixel point in the initial signature image by the pixel value of the corresponding position pixel point in the target mask image to obtain a result image as the intermediate signature image;
[0149] performing corrosion processing on the intermediate signature image to obtain a corroded image;
[0150] The eroded image is dilated to obtain a dilated image as the processed signature image.
[0151] In some embodiments, the preset relationship is that the ratio of the number of font pixels in the processed signature image to the number of font pixels in the initial signature image is less than a preset ratio threshold, and the processing unit 603 is specifically configured to:
[0152] Based on the binary image of the initial signature image, counting the number of font pixels of the initial signature image;
[0153] Based on the binary image of the processed signature image, counting the number of font pixels of the initial signature image;
[0154] Obtaining a ratio of the number of font pixels of the processed signature image to the number of font pixels of the initial signature image as a font remaining ratio of the initial signature image;
[0155] If the remaining font ratio is less than a preset ratio threshold, the processed signature image is used as a sample signature image.
[0156] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined and implemented as the same entity or several entities. The specific implementation of the above units can be found in the above signature image generation method embodiment, which will not be repeated here.
[0157] See also Figure 7 , Figure 7 This is a schematic block diagram of the structure of a computer device provided in an embodiment of the present application. The computer device may be a server.
[0158] like Figure 7 As shown, the computer device includes a processor, a memory, and a network interface connected via a system bus, wherein the memory may include a non-volatile storage medium and an internal memory.
[0159] The non-volatile storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any one of the signature image generation methods.
[0160] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
[0161] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor, the processor can execute any signature image generation method.
[0162] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0163] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0164] In one embodiment, the processor is configured to execute a computer program stored in the memory to implement the following steps:
[0165] Acquire an initial signature image; generate a target mask image including an occluded area based on the pixel size of the initial signature image; erase the initial signature image based on the target mask image to obtain a processed signature image; if the relationship between the number of font pixels in the processed signature image and the number of font pixels in the initial signature image satisfies a preset relationship, use the processed signature image as a sample signature image.
[0166] Those skilled in the art will appreciate that all or part of the steps in the above-mentioned signature image generation method may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0167] To this end, an embodiment of the present application provides a computer-readable storage medium, which stores multiple computer programs. The computer programs can be loaded by a processor to execute any signature image generation method provided in the embodiment of the present application.
[0168] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0169] In the aforementioned embodiments of the signature image generation device and computer-readable storage medium, the descriptions of each embodiment have their respective emphases. For portions not detailed in a particular embodiment, reference can be made to the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for ease and brevity of description, the specific operating processes and beneficial effects of the aforementioned signature image generation device, computer-readable storage medium, and their corresponding units can be referred to in the description of the signature image generation method in the aforementioned embodiments, and will not be further elaborated upon here.
[0170] The above describes in detail a signature image generation method, apparatus, computer device, and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is intended only to help understand the method and core concept of the present application. At the same time, those skilled in the art may vary in the specific implementation methods and scope of application based on the concepts of the present application. In summary, the contents of this specification should not be construed as limiting the present application. The non-Company software tools or components that appear in the embodiments of the present application are merely examples and do not represent actual use.
Claims
1. A signature image generation method, characterized in that: The method comprises: Get the initial signature image; generating a target mask image including a blocked area according to the pixel size of the initial signature image; Erasing the initial signature image based on the target mask image to obtain a processed signature image; If the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship, the processed signature image is used as a sample signature image.
2. The signature image generation method according to claim 1, characterized in that: Generating a target mask image including a blocked area according to the pixel size of the initial signature image comprises: generating a mask image of the initial signature image according to the pixel size of the initial signature image; generating an occlusion region on the mask image to obtain a preliminary mask image including the occlusion region; The target mask image is determined according to the preliminary mask image.
3. The signature image generation method according to claim 2, characterized in that: Generating the occlusion area on the mask image to obtain a preliminary mask image containing the occlusion area includes: Obtaining a random center pixel point from each pixel point of the mask image; Get the radius of a random circle; Generating a circular occlusion area on the mask image based on the random circle center pixel point and the random circle radius; The mask image containing the circular occlusion area is used as the preliminary mask image.
4. The signature image generation method according to claim 2, wherein: Generating the occlusion area on the mask image to obtain a preliminary mask image containing the occlusion area includes: Obtaining random rectangular corner pixel points from each pixel point of the mask image; Get the random rectangle length and random rectangle width; Generating a rectangular occlusion area on the mask image based on the random rectangle corner pixel points, the random rectangle length and the random rectangle width; The mask image containing the rectangular occlusion area is used as the preliminary mask image.
5. The signature image generation method according to claim 2, characterized in that: Determining the target mask image according to the preliminary mask image includes: The preliminary mask image is rotated according to a random rotation angle to obtain the target mask image.
6. The signature image generation method according to claim 1, wherein: The step of erasing the initial signature image based on the target mask image to obtain a processed signature image includes: Multiplying the pixel value of each pixel point in the initial signature image by the pixel value of the corresponding position pixel point in the target mask image to obtain a result image as the intermediate signature image; performing corrosion processing on the intermediate signature image to obtain a corroded image; The eroded image is dilated to obtain a dilated image as the processed signature image.
7. The signature image generation method according to claim 1, wherein: The preset relationship is that the ratio of the number of font pixels in the processed signature image to the number of font pixels in the initial signature image is less than a preset ratio threshold, and the method further includes: Based on the binary image of the initial signature image, counting the number of font pixels of the initial signature image; Based on the binary image of the processed signature image, counting the number of font pixels of the initial signature image; If the relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship, using the processed signature image as a sample signature image includes: Obtaining a ratio of the number of font pixels of the processed signature image to the number of font pixels of the initial signature image as a font remaining ratio of the initial signature image; If the remaining font ratio is less than a preset ratio threshold, the processed signature image is used as a sample signature image.
8. A signature image generating device, characterized in that: The signature image generating device comprises: an acquiring unit, configured to acquire an initial signature image; a generating unit, configured to generate a target mask image including a blocked area according to a pixel size of the initial signature image; a processing unit, configured to perform erasing processing on the initial signature image based on the target mask image to obtain a processed signature image; The processing unit is further configured to use the processed signature image as a sample signature image if a relationship between the number of font pixels of the processed signature image and the number of font pixels of the initial signature image satisfies a preset relationship.
9. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the signature image generation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that A computer program is stored thereon, and the computer program is loaded by a processor to execute the signature image generation method according to any one of claims 1 to 7.