Method for generating a seal image and method for recognizing a seal
By automatically generating seal images, the problem of low annotation efficiency in seal recognition is solved, enabling rapid generation and accurate positioning of seal image information, simplifying training data construction, and improving annotation efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2023-03-27
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies for seal recognition are inefficient, requiring extensive manual annotation of real seal images, resulting in long annotation times, low quality, and a high risk of errors.
By automatically generating seal images, an initial template image, organization name, and base plate image are obtained. The text curvature and character size are determined. Characters are arranged in the base plate image according to the target information to generate a target base plate image that matches the characters. Characters are then added to the initial template image to construct the seal image.
It enables rapid generation of seal images and rapid determination of image information, improves annotation efficiency, simplifies the construction of training data for seal recognition models, and avoids the problems of long time and low quality of manual annotation.
Smart Images

Figure CN116311273B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and more specifically, to a method for generating seal images and a method for recognizing seals. Background Technology
[0002] Seal recognition is a crucial task in OCR (Optical Character Recognition) and is widely used in financial industries for invoice verification and contract proofreading. Currently, deep learning-based OCR technologies require extensive sample training to obtain a robust and accurate model. However, the inherent unclearness and random rotation of seals make annotation extremely difficult. Not only must the seal's circumscribed rectangle on the image be accurately drawn manually, but the irregularly rotated arc-shaped text and serial numbers on the seal must also be accurately annotated. This necessitates significant manpower and time investment to obtain high-quality, broadly applicable sample data, resulting in low annotation efficiency.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This invention provides a method for generating seal images and a method for recognizing seals, so as to at least solve the technical problem of low annotation efficiency in the prior art when using real seal images as training samples for seal recognition models.
[0005] According to one aspect of the present invention, a method for generating a seal image is provided, comprising: acquiring an initial template image containing a circular seal outline, an organization name, and a base image, and determining the text radian and character size in the text corresponding to each organization name; for each character in the organization name, determining target information of the character in the base image based on the text radian, character size, and the initial template image, and arranging the character in the base image according to the target information to obtain a target base image matching the character, wherein the target information includes the initial position information and rotation angle of the character; and adding each character to the initial template image according to the target base image matching each character in the organization name to obtain a seal image matching the organization name.
[0006] Furthermore, the method for generating the seal image also includes: determining initial position information based on the character size and image information of the initial template image, and adding characters to the base image based on the initial position information; determining the rotation angle for character matching based on the text radian and the target sequence of the character in the organization name, and rotating the character in the base image according to the rotation angle to obtain the target base image for character matching.
[0007] Furthermore, the method for generating the seal image also includes: determining the character width based on the character size; constructing a target coordinate system with the target vertex of the base image as the origin, and determining the horizontal coordinate information of the character in the target coordinate system based on the character width and the width of the initial template image; determining the vertical coordinate information of the character in the target coordinate system based on the radius information of the circular seal outline and the height of the initial template image, wherein the horizontal coordinate information and the vertical coordinate information constitute the initial position information.
[0008] Furthermore, the method for generating the seal image also includes: determining the target coefficient based on the number of characters in the organization name and the target sequence, wherein the target coefficient is a value less than 1; and calculating the product of the text radian and the target coefficient to obtain the rotation angle.
[0009] Furthermore, the method for generating the seal image also includes: scaling the base image and the characters in the base image according to the target width scaling ratio of the characters to obtain the scaled base image and the scaled characters, wherein the target width scaling ratio is determined based on the text curvature and the radius information of the circular seal outline; determining the center point of the scaled base image, and rotating the scaled characters in the scaled base image with the center point as the center according to the rotation angle to obtain the target base image.
[0010] Furthermore, the method for generating the seal image also includes: cropping the target base image to the image size of the initial template image to obtain a cropped target base image, wherein the center point of the cropped target base image is the same as the center point of the target base image before cropping, and the image area of the target base image before cropping is larger than that of the initial template image; according to the position information of each character in the organization name in the cropped target base image, pasting the scaled characters in the cropped target base image into the initial template image to obtain the seal image.
[0011] Furthermore, the method for generating the seal image also includes: obtaining the text radian and the initial character size, and determining the initial character width based on the initial character size; determining the initial arc length based on the text radian, the radius information of the circular seal outline, and the initial character width; determining the initial text length based on the initial character width, the number of characters in the organization name, and the initial width scaling ratio of the characters; if the initial text length is greater than the initial arc length, adjusting the initial width scaling ratio of the characters and / or the initial character size, and re-determining the initial arc length and the initial text length, until the updated initial text length is less than or equal to the updated initial arc length, then determining the current initial width scaling ratio as the target width scaling ratio, and determining the current initial character size as the character size.
[0012] According to another aspect of the present invention, a seal recognition method is also provided, comprising: acquiring a seal image to be recognized; inputting the seal image to be recognized into a seal recognition model, and recognizing the characters in the seal image to be recognized by the seal recognition model to obtain a target character sequence, wherein the training set data of the seal recognition model is generated based on the above-described seal image generation method.
[0013] Furthermore, the seal recognition method also includes: acquiring multiple sample seal images, wherein the sample seal images are generated based on the seal image generation method described above; for each sample seal image, preprocessing the sample seal image to obtain a processed sample seal image, wherein the preprocessing is at least one of the following: blurring, rotation; acquiring a preset background image, and merging the processed sample seal image into the background image to obtain a target sample seal image, wherein the target sample seal image is used to constitute the training set data.
[0014] According to another aspect of the present invention, a seal image generation apparatus is also provided, comprising: a first determining module, configured to acquire an initial template image containing a circular seal outline, an organization name, and a base image, and determine the text radian and character size in the text corresponding to each organization name; a second determining module, configured to, for each character in the organization name, determine the target information of the character in the base image based on the text radian, character size, and the initial template image, and arrange the character in the base image according to the target information to obtain a target base image matching the character, wherein the target information includes the initial position information and rotation angle of the character; and an adding module, configured to add each character to the initial template image according to the target base image matching each character in the organization name to obtain a seal image matching the organization name.
[0015] According to another aspect of the present invention, a seal recognition device is also provided, comprising: a first acquisition module for acquiring a seal image to be recognized; and a recognition module for inputting the seal image to be recognized into a seal recognition model, and recognizing characters in the seal image to be recognized by the seal recognition model to obtain a target text sequence, wherein the training set data of the seal recognition model is generated based on the above-described seal image generation method.
[0016] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-described method for generating a seal image and the method for generating a seal image when running.
[0017] According to another aspect of the present invention, an electronic device is also provided, the electronic device including one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are configured to execute the above-described method for generating a seal image or a seal recognition method.
[0018] According to another aspect of the present invention, a computer program product is also provided, including a computer program / instructions, which, when executed by a processor, implement the above-described method for generating a seal image or a seal recognition method.
[0019] In this embodiment of the invention, an automatic seal image generation method is adopted. This involves acquiring an initial template image containing the outline of a circular seal, an organization name, and a base image. The text curvature and character size corresponding to each organization name are determined. Then, for each character in the organization name, the target information of the character in the base image is determined based on the text curvature, character size, and the initial template image. The characters are then arranged in the base image according to the target information to obtain a target base image matching the characters. Finally, based on the target base images matching each character in the organization name, each character is added to the initial template image to obtain a seal image matching the organization name. The target information includes the initial position information and rotation angle of the characters.
[0020] In the above process, by determining the target information of the characters in the base image based on the text curvature, character size, and initial template image, and obtaining the target base image containing the characters based on the target information, the accurate determination of the position information of each character in the seal image to be generated is achieved. Furthermore, by drawing the initial template image based on the target base image, the seal image is obtained, realizing the rapid generation of the seal image and the rapid determination of the image information of the seal image. This improves annotation efficiency, facilitates the rapid construction of training data for the seal recognition model, and avoids the problems of long annotation time, low annotation quality, and easy annotation errors that occur when using real seal images as training data and requiring manual annotation of seal information in the images.
[0021] Therefore, the solution provided in this application achieves the goal of automatically generating seal images, thereby improving the technical effect of annotation efficiency and solving the technical problem of low annotation efficiency in the existing technology when using real seal images as training samples for seal recognition models. Attached Figure Description
[0022] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0023] Figure 1 This is a schematic diagram of an optional method for generating a seal image according to an embodiment of the present invention;
[0024] Figure 2 This is a schematic diagram of an optional initial template image according to an embodiment of the present invention;
[0025] Figure 3 This is a schematic diagram of an optional addition of characters to a base plate image based on initial position information according to an embodiment of the present invention;
[0026] Figure 4 This is an illustration of an optional method according to an embodiment of the present invention, where scaled characters from a cropped target base image are pasted into an initial template image.
[0027] Figure 5 This is a schematic diagram of an optional seal image according to an embodiment of the present invention;
[0028] Figure 6 This is a schematic diagram of an optional initial template image with a pentagram pattern according to an embodiment of the present invention;
[0029] Figure 7 This is a schematic diagram of another optional seal image according to an embodiment of the present invention;
[0030] Figure 8 This is a schematic diagram of an optional seal recognition method according to an embodiment of the present invention;
[0031] Figure 9 This is a schematic diagram of an optional processed sample stamp image according to an embodiment of the present invention;
[0032] Figure 10 This is a schematic diagram of an optional stamp image generation apparatus according to an embodiment of the present invention;
[0033] Figure 11 This is a schematic diagram of an optional seal recognition device according to an embodiment of the present invention;
[0034] Figure 12 This is a schematic diagram of an optional electronic device according to an embodiment of the present invention. Detailed Implementation
[0035] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0036] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0037] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0038] Example 1
[0039] According to an embodiment of the present invention, an embodiment of a method for generating a seal image is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0040] Figure 1 This is a schematic diagram of an optional method for generating a seal image according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0041] Step S101: Obtain an initial template image containing the outline of a circular seal, the organization name, and a base plate image, and determine the text radii and character size for each organization name.
[0042] Optionally, an application system, electronic device, server, or other device can be used as the execution subject of this application. In this embodiment, the target generation system is used as the execution subject. In step S101, the initial template image containing the outline of a circular seal can be generated using image processing software. Figure 2 This is a schematic diagram of an optional initial template image according to an embodiment of the present invention, such as... Figure 2 As shown, it can be a square image in RGBA format with a fill color of (255, 255, 255, 0). At least a circular stamp outline is drawn in this image, and other patterns, such as a five-pointed star, can be drawn within the circular stamp outline. In other embodiments, the initial target image can also be other shapes. The base image can be a blank grayscale image, and the image area of the base image is larger than that of the initial template image.
[0043] The organization name can be obtained from the internet or preset by staff. The text corresponding to the organization name has undergone data cleaning. For example, during the data cleaning process, the following symbols can be removed from the text: ".[]!!*_、。·<>,??+《》\ / ;“”:;:|,<>'"”. All English symbols in the text can be replaced with Chinese format, and all spaces or hidden symbols such as (\t, \r, \n, etc.) in the text can be replaced with empty characters, etc.
[0044] Furthermore, after obtaining the organization name, the target generation system can obtain the text radian value and character size corresponding to the organization name entered by the staff. The target generation system can also automatically and randomly determine the text radian value and character size. For example, the target generation system randomly selects a number from the interval [180, 280] as the text radian value α (in degrees), and randomly selects a character size from the character size interval corresponding to the character width interval [80, 96].
[0045] Step S102: For each character in the organization name, determine the target information of the character in the base image based on the text radian, character size and initial template image, and arrange the character in the base image according to the target information to obtain the target base image matching the character. The target information includes the initial position information and rotation angle of the character.
[0046] Optionally, the target generation system can first arrange the characters of the company name in the base image to determine the position information of each character in the seal image to be generated. Specifically, for each character, the target generation system can determine the initial position information of the character in the base image based on the image information of the initial template image and the character size, and determine the rotation angle of the character in the base image based on the text curvature.
[0047] Furthermore, the target generation system can first generate characters in the base plate image according to the initial position information, and then rotate the characters according to the rotation angle to obtain a target base plate image that matches the characters.
[0048] It should be noted that by determining the target information of the characters in the base image based on the text curvature, character size, and the initial template image, and then arranging the characters in the base image according to the target information, accurate determination of the position information of each character in the seal image to be generated is achieved. Furthermore, by determining the position information of each character in the seal image to be generated within the base image, the problem of limited character adjustment caused by the circular seal outline in the initial template image is avoided when directly arranging characters. This improves the flexibility of character arrangement and thus increases image generation efficiency.
[0049] Step S103: Based on the target base image matched by each character in the organization name, add each character to the initial template image to obtain the seal image matching the organization name.
[0050] In step S103, the target generation system can crop the target base image so that the image size of the cropped target base image is the same as the initial template image. Then, based on the position information of each character in the cropped target base image, each character is added to the initial template image to obtain a seal image matching the organization name.
[0051] Furthermore, the target generation system can generate training samples based on the target template image and use the image information of the target template image as the real label to construct a target training sample set. The target training sample set is used to train the seal recognition model, and the image information includes, but is not limited to, the text content in the image.
[0052] It should be noted that by drawing the initial template image based on the target base image to obtain the seal image, the seal image can be generated quickly and the image information of the seal image can be determined quickly. This improves the annotation efficiency and facilitates the rapid construction of training data for the seal recognition model. It avoids the problems of long annotation time, low annotation quality, and easy annotation errors that occur when using real seal images as training data and requiring manual annotation of the seal information in the images.
[0053] Based on the scheme defined in steps S101 to S103 above, it can be understood that in this embodiment of the invention, an automatic seal image generation method is adopted. This involves acquiring an initial template image containing the outline of a circular seal, the organization name, and a base image. The text curvature and character size corresponding to each organization name are determined. Then, for each character in the organization name, the target information of the character in the base image is determined based on the text curvature, character size, and the initial template image. The character is then arranged in the base image according to the target information to obtain a target base image matching the character. Finally, based on the target base images matching each character in the organization name, each character is added to the initial template image to obtain a seal image matching the organization name. The target information includes the initial position information and rotation angle of the character.
[0054] It is noteworthy that in the above process, by determining the target information of the characters in the base image based on the text curvature, character size, and initial template image, and obtaining the target base image containing the characters based on the target information, the accurate determination of the position information of each character in the seal image to be generated is achieved. Furthermore, by drawing the initial template image based on the target base image to obtain the seal image, the rapid generation of the seal image and the rapid determination of its image information are achieved, thereby improving annotation efficiency and facilitating the rapid construction of training data for the seal recognition model. This avoids the problems of long annotation time, low annotation quality, and easy annotation errors that occur when using real seal images as training data, which require manual annotation of the seal information in the images.
[0055] Therefore, the solution provided in this application achieves the goal of automatically generating seal images, thereby improving the technical effect of annotation efficiency and solving the technical problem of low annotation efficiency in the existing technology when using real seal images as training samples for seal recognition models.
[0056] In an optional embodiment, during the process of determining the target information of the character in the base image based on the text radian, character size, and initial template image, and arranging the character in the base image according to the target information to obtain the target base image of the character matching, the target generation system can determine the initial position information based on the character size and the image information of the initial template image, add the character in the base image according to the initial position information, and then determine the rotation angle of the character matching based on the text radian and the target order of the character in the organization name, and rotate the character in the base image according to the rotation angle to obtain the target base image of the character matching.
[0057] In the process of determining the initial position information, the image information of the initial template image includes the width of the initial target image, the height of the initial image, and the radius information of the circular seal outline. The target generation system can determine the horizontal coordinate information of the character based on the width of the initial target image, and determine the vertical coordinate information of the character based on the height of the initial image and the radius information of the circular seal outline. Thus, the initial position information is composed of the horizontal coordinate information and the vertical coordinate information.
[0058] Furthermore, the target generation system can determine the rotation angle of the character based on the target position of the character in the organization name and the text arc length. Based on the rotation angle, the character is rotated in the base image from the initial position to the target position to obtain a target base image that matches the character. The target base image includes the rotated character.
[0059] It should be noted that by first generating characters in the base image based on the initial position information, and then rotating the characters to the target position according to the rotation angle, the target position can be quickly determined, thereby improving the image generation efficiency.
[0060] In an optional embodiment, during the process of determining the initial position information based on the character size and the image information of the initial template image, the target generation system can determine the character width based on the character size, then construct a target coordinate system with the target vertex of the base image as the origin, and determine the horizontal coordinate information of the character in the target coordinate system based on the character width and the width of the initial template image, thereby determining the vertical coordinate information of the character in the target coordinate system based on the radius information of the circular seal outline and the height of the initial template image, wherein the horizontal coordinate information and the vertical coordinate information constitute the initial position information.
[0061] Optionally, in this embodiment, for ease of description, the process of determining the initial position information of the character in the base image is described using the example of an initial template image being a square with side length h and a base image being a square with side length 2h. Optionally, the target generation system can determine the character width s based on the character size, wherein the mapping relationship between character size and character width is pre-stored in the target generation system. Then, the target generation system can construct a target coordinate system with the upper left corner vertex of the base image (i.e., the aforementioned target vertex) as the origin, where the x-axis of the target coordinate system points from left to right, and the y-axis points from top to bottom.
[0062] After that, the target generation system can determine (h, h) as the center point coordinates of the bottom plate image, and then can determine (h - 0.5s) as the abscissa information of the character, and determine (h - r + e) as the ordinate information of the character, where h is the side length of the initial template image (i.e., width or height), s is the character width, r is the radius information of the circular seal outline, specifically, the radius information is the radius value of the inner ring of the circular seal outline, and e is the distance required between the top of the character and the inner ring of the circular seal outline when the organization name is arranged in an arc within the circular seal outline. Optionally, in other embodiments, the radius information can also be the radius value of the outer ring of the circular seal outline. Correspondingly, e is the distance required between the top of the character and the outer ring of the circular seal outline when the organization name is arranged in an arc within the circular seal outline. Optionally, when determining the abscissa information, it can also be determined in combination with the thickness of the character. For example, determine (h - 0.5s - w) as the abscissa information of the character, where w represents the thickness of the character.
[0063] It should be noted that when the character is displayed on the electronic device, it is default that the shape of the pixels actually occupied by it is a rectangle. Therefore, in this embodiment, after determining the abscissa and ordinate information, the target generation system can control the upper left vertex of the character to be located at the aforementioned coordinates (h - 0.5s, h - r + e), so that the center coordinates of the character are (h, h - r + e), that is, the character is directly above the center point coordinates of the bottom plate image, and use (r - e) as the rotation radius. The schematic diagram of adding the character to the bottom plate image according to the initial position information is as Figure 3 shown in Figure 3 where the character is "中".
[0064] Optionally, it should be emphasized that in other embodiments, when the initial template image is rectangular, only need to replace h in the abscissa information with the width of the initial template image, and replace h in the ordinate information with the height of the initial template image, so it will not be elaborated here.
[0065] It should be noted that by constructing a target coordinate system in the bottom plate image and respectively determining the abscissa and ordinate information of the character based on different information, the rapid and accurate determination of the abscissa and ordinate information of the character is realized.
[0066] In an optional embodiment, in the process of determining the rotation angle matched by the character according to the text radian and the target sequence position of the character in the organization name, the target generation system can determine the target coefficient according to the number of characters in the organization name and the target sequence position, and then calculate the product of the text radian and the target coefficient to obtain the rotation angle. The target coefficient is a value less than 1.
[0067] Specifically, the target generation system can calculate the rotation angle based on the following formula:
[0068]
[0069] Where i represents the target sequence position of the character, θ i This represents the rotation angle corresponding to the i-th character in the text, and n represents the number of characters in the organization name. This is the aforementioned target coefficient. α represents the text radians.
[0070] It should be noted that, since the characters in the text corresponding to the company name in a circular seal are arranged in an arc, the rotation angle of the characters is determined by determining the rotation angle based on the number of characters, the target order, and the curvature of the text, thus achieving accurate determination of the rotation angle.
[0071] In one optional embodiment, during the process of rotating the characters in the base image according to the rotation angle to obtain the target base image for character matching, the target generation system can scale the base image and the characters in the base image according to the target width scaling ratio of the characters to obtain a scaled base image and scaled characters. Then, the center point of the scaled base image is determined, and the scaled characters are rotated in the scaled base image with the center point as the center according to the rotation angle to obtain the target base image. The target width scaling ratio is determined based on the text curvature and the radius information of the circular seal outline.
[0072] Since the area within the circular seal outline is limited, when creating a seal pattern, it is usually necessary to control the width of the characters to be narrower than the standard width to avoid the circular seal outline being unable to accommodate all the characters. The aforementioned target width scaling ratio is used to control the degree of narrowing of the characters. The smaller the text curvature and the smaller the radius of the circular seal outline, the greater the degree of narrowing required for the characters.
[0073] Optionally, taking the initial template image as a square with side length h and the base image as a square with side length 2h as an example, the process of determining the target base image will be explained. Assuming the target width scaling ratio of the character is ρ, the width of the scaled base image is 2h*ρ, the height is 2h, and the width of the scaled character is s*ρ. Then, the center point coordinates of the scaled base image are determined to be (h*ρ, h). Since the character and the base image are scaled together, the character is still directly above the center point of the base image.
[0074] Furthermore, the target generation system can rotate the scaled characters in the scaled base image with the center point (h*ρ, h) as the center and according to the rotation angle to obtain the target base image.
[0075] Optionally, in other embodiments, if the initial template image is rectangular, the target base plate image can also be determined using the above method, so it will not be described again here.
[0076] It should be noted that by first scaling the base image and the characters according to the target width scaling ratio, the target shape of the characters is effectively determined. Furthermore, by rotating the scaled characters, the target position of the characters is effectively determined.
[0077] In one optional embodiment, during the process of adding each character to the initial template image based on the target base image matched with each character in the organization name to obtain a seal image matching the organization name, the target generation system can crop the target base image to the image size of the initial template image to obtain a cropped target base image. Then, according to the position information of each character in the organization name in the cropped target base image, the scaled characters in the cropped target base image are pasted into the initial template image to obtain the seal image. The center point of the cropped target base image is the same as the center point of the original target base image, and the image area of the original target base image is larger than that of the initial template image.
[0078] Specifically, the target generation system can crop the target base image using the center point of the target base image as the center and the image size of the initial template image as the target size, to obtain the cropped target base image. That is, during cropping, the coordinates of the top left corner of the cropping are (h*ρ-h / 2, h / 2), and the coordinates of the bottom right corner of the cropping are (h*ρ+h / 2, 3h / 2).
[0079] Furthermore, the target generation system can determine the current position of each character in the cropped target base image, which is also the required placement position of each character in the initial template image. Therefore, based on the position information of the characters in the cropped target base image, the scaled characters in the cropped target base image are pasted into the initial template image. An optional illustration of pasting the scaled characters from the cropped target base image into the initial template image is shown below. Figure 4 As shown. Furthermore, Figure 5 This is a schematic diagram of an optional stamp image according to an embodiment of the present invention. After each character is pasted, the result is as follows: Figure 5 The seal image shown indicates that the company name in the seal image is "China XX Co., Ltd."
[0080] The target generation system can also pre-draw a pentagram pattern in the initial template image, such as... Figure 6 As shown, Figure 6This is a schematic diagram of an optional initial template image with a pentagram pattern according to an embodiment of the present invention. During the drawing process, to obtain better anti-aliasing, the initial template image can be drawn first at eight times the predetermined side length, and then scaled to the predetermined side length h. When drawing the pentagram, the coordinates of its 10 vertices need to be input, and their calculation formulas are as follows:
[0081]
[0082] In this system, a rectangular coordinate system is constructed with the top left corner of the initial template image as the origin. x1 represents the x-coordinate of the vertex of the (k+1)th acute angle of the pentagram, y1 represents the y-coordinate of the vertex of the (k+1)th acute angle of the pentagram, and R represents the radius of the circumcircle of the pentagram, which is generally 0.36 times the inner (or outer) radius of the circular seal outline.
[0083]
[0084] Where x2 represents the x-coordinate of the vertex of the (k+1)th obtuse angle of the pentagram, and y2 represents the y-coordinate of the vertex of the (k+1)th obtuse angle of the pentagram.
[0085] Furthermore, Figure 7 This is a schematic diagram of another optional seal image according to an embodiment of the present invention. The target generation system can add text and numbers to the lower part of the circular seal outline of the seal image, based on the seal image already containing a five-pointed star pattern. Figure 7 As shown, the words "Finance Seal" and the number "0123456789" were added.
[0086] It should be noted that by cropping the target base image to the image size of the initial template image, it is easier to determine the position and shape of the characters in the initial template image, thereby further improving the efficiency of generating the seal image.
[0087] In one optional embodiment, during the process of determining the character size in the text corresponding to the organization name, the target generation system can obtain the text radian and the initial character size, and determine the initial character width based on the initial character size. Then, it determines the initial arc length based on the text radian, the radius information of the circular seal outline, and the initial character width. Next, it determines the initial text length based on the initial character width, the number of characters in the organization name, and the initial width scaling ratio of the characters. Thus, if the initial text length is greater than the initial arc length, the initial width scaling ratio and / or the initial character size are adjusted, and the initial arc length and the initial text length are re-determined until the updated initial text length is less than or equal to the updated initial arc length. At this point, the current initial width scaling ratio is determined as the target width scaling ratio, and the current initial character size is determined as the character size.
[0088] Optionally, the text radian and initial character size can be pre-input by the staff, or randomly selected by the target generation system within a corresponding preset range. For example, the target generation system randomly selects a number from the range [180, 280] as the text radian α (in degrees), and randomly selects a character size from the character size range corresponding to the character width range [80, 96] as the initial character size. Furthermore, the target generation system can determine the initial character width based on the mapping relationship between character width and character size, according to the initial character size.
[0089] Optionally, the target generation system can calculate the initial arc length using the following formula:
[0090]
[0091] Where C represents the initial arc length and s′ represents the initial character width. The initial arc length is used to characterize the arc length formed between the bottom of the first character and the bottom of the last character.
[0092] The target generation system can calculate the initial text length using the following formula:
[0093] L=n((s′+4)ρ′+1)-1
[0094] Where L represents the initial text length and ρ′ represents the initial width scaling ratio. In this embodiment, the default value of ρ′ is 0.66. The initial text length represents the length formed between the first and last characters when the font is normally arranged horizontally.
[0095] Furthermore, the target generation system can compare the initial text length and the initial arc length. When the initial text length is greater than the initial arc length, it can adjust the initial width scaling ratio and / or the initial character size, and redetermine the initial arc length and the initial text length. When the updated initial text length is less than or equal to the updated initial arc length, the current initial width scaling ratio used for calculation is determined as the target width scaling ratio, and the current initial character size used for calculation is determined as the character size.
[0096] In this embodiment, for example, when the initial text length is greater than the initial arc length, ρ′ is updated to 0.5, and the character width that makes the updated initial text length less than or equal to the updated initial arc length is determined based on the following formula, and then the character size corresponding to the character width is determined.
[0097]
[0098] Here, s″ is the character width that makes the updated initial text length less than or equal to the updated initial arc length.
[0099] Therefore, the solution provided in this application achieves the goal of automatically generating seal images, thereby improving the technical effect of annotation efficiency and solving the technical problem of low annotation efficiency in the existing technology when using real seal images as training samples for seal recognition models.
[0100] Example 2
[0101] According to an embodiment of the present invention, an embodiment of a seal recognition method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0102] Figure 8 This is a schematic diagram of an optional seal recognition method according to an embodiment of the present invention, such as... Figure 8 As shown, the method includes the following steps:
[0103] Step S801: Obtain the image of the seal to be identified.
[0104] Optionally, an application system, electronic device, server, or other device can be used as the execution subject of this application. In this embodiment, the target generation system is used as the execution subject, and the target generation system is preferably a distributed system. In step S801, the target generation system can acquire the image of the seal to be recognized input by the staff.
[0105] Step S802: Input the seal image to be recognized into the seal recognition model, and use the seal recognition model to recognize the text in the seal image to obtain the target text sequence. The training set data of the seal recognition model is generated based on the seal image generation method provided in Example 1.
[0106] The seal recognition model is a model pre-trained based on training set data. The training set data contains multiple training samples, and the training samples include sample seal images. The sample seal images are generated based on the seal image generation method provided in Example 1. The real labels corresponding to the training samples are automatically saved during the generation of training samples.
[0107] Optionally, the OCR model can be trained on these massive amounts of simulated data (i.e., training samples containing the aforementioned sample seal images) and a small amount of real data mixed together, which can ultimately effectively improve the robustness and accuracy of the seal detection and recognition model.
[0108] Based on the scheme defined in steps S801 to S802 above, it can be understood that in this embodiment of the invention, a method of training a seal recognition model based on an automatically generated seal image is adopted. By acquiring the seal image to be recognized, and then inputting the seal image to be recognized into the seal recognition model, the seal recognition model recognizes the text in the seal image to be recognized to obtain the target text sequence. The training set data of the seal recognition model is generated based on the seal image generation method provided in Embodiment 1.
[0109] It is noteworthy that in the above process, by determining the target information of the characters in the base image based on the text curvature, character size, and initial template image, and obtaining the target base image containing the characters based on the target information, the accurate determination of the position information of each character in the seal image to be generated is achieved. Furthermore, by drawing the initial template image based on the target base image to obtain the seal image, the rapid generation of the seal image and the rapid determination of its image information are achieved, thereby improving annotation efficiency and facilitating the rapid construction of training data for the seal recognition model. This avoids the problems of long annotation time, low annotation quality, and easy annotation errors that occur when using real seal images as training data, which require manual annotation of the seal information in the images.
[0110] Therefore, the solution provided in this application achieves the goal of automatically generating seal images, thereby improving the technical effect of annotation efficiency and solving the technical problem of low annotation efficiency in the existing technology when using real seal images as training samples for seal recognition models.
[0111] In an optional embodiment, the target generation system can generate training set data using the following method. Specifically, the target generation system can acquire multiple sample stamp images, then preprocess each sample stamp image to obtain a processed sample stamp image, then acquire a preset background image, and composite the processed sample stamp image into the background image to obtain a target sample stamp image. The preprocessing includes at least one of the following: blurring, rotation. The sample stamp images are generated based on the stamp image generation method provided in Embodiment 1, and the target sample stamp images are used to constitute the training set data.
[0112] Optionally, after acquiring the sample stamp image, the target generation system can blur and rotate the image. Specifically, the target generation system can use a noisy grayscale image to adjust the A channel value of the sample stamp image (a PNG image with transparency contains four channels: R, G, B, and A) based on the following formula:
[0113] SealA' = Gray / 255 * SealA
[0114] Among them, SealA’ represents the value of the A channel of the adjusted sample seal image, Gray represents the gray value of the noise grayscale image, and SealA represents the value of the A channel of the sample seal image before adjustment. Figure 9 It is a schematic diagram of an optional processed sample seal image according to an embodiment of the present invention. As Figure 9 shown, the target generation system performs blurring processing and rotation processing on the sample seal image.
[0115] Furthermore, the target generation system can store a certain amount of image data of scanned copies of documents, invoices, contracts, etc. without seals to construct a background image library. After obtaining the processed sample seal image, the target generation system can select a background image from the background image library, and then synthesize the processed sample seal image onto the background image to obtain the target sample seal image. Among them, the target sample seal image contains all the content of the sample seal image, and there can be multiple seal images in the target sample seal image, as long as the seal images do not overlap with each other.
[0116] For example, a rectangular coordinate system is constructed with the upper left corner of the background image as the origin, and it is assumed that the coordinate library where the processed sample seal image can be pasted on the background image is O = {(x, y)|x < W - h, y < H - h}, where W represents the width of the background image, H represents the height of the background image, then there are (W - h)*(H - h) coordinates where the processed sample seal image can be pasted. At this time, a coordinate such as (x0, y0) is selected, and then an RGB picture with the same size as the processed sample seal image is cut from the background image, the upper left corner coordinate of the cutting frame is (x0, y0), and the lower right corner coordinate is (x0 + h, y0 + h), where x0 belongs to [0, W - h], y0 belongs to [0, H - h]. The formula for merging the cut picture with the processed sample seal image is:
[0117]
[0118] Among them, CombineRGB represents the values of the R, G, and B channels of the image obtained by merging the RGB image cut from the background image with the processed sample seal image, SealRGB represents the values of the R, G, and B channels of the processed sample seal image, and BackgroundRGB represents the values of the R, G, and B channels of the RGB image cut from the background image.
[0119] Furthermore, the image obtained by merging the RGB image cut from the background image with the processed sample seal image can be filled into the cropped background image at the original cutting frame position, so as to obtain the target sample seal image.
[0120] Optionally, if multiple stamps need to be placed on a background image, the coordinate library O can be updated based on the coordinate information of the stamp images that have been merged into the background image to avoid occlusion when placing the next stamp image.
[0121] Furthermore, the target generation system can use a target sample seal image as a training sample to construct training set data. The target generation system can record relevant information about the generated target sample seal image as the true label of the training sample. For example, it can record the text in the seal image in the target sample seal image to train the seal recognition model. Or, it can record the coordinates of the seal image in the target sample seal image on the background image to train the seal detection model. Optionally, it can also record information such as the rotation angle of the seal.
[0122] It should be noted that by preprocessing the sample seal images and combining them with a preset background image, the realism of the target sample seal images is increased, thereby facilitating the improvement of the training effect for seal recognition.
[0123] Example 3
[0124] According to an embodiment of the present invention, an embodiment of a seal image generation apparatus is provided, wherein, Figure 10 This is a schematic diagram of an optional seal image generation apparatus according to an embodiment of the present invention, such as... Figure 10 As shown, the device includes:
[0125] The first determining module 1001 is used to obtain an initial template image containing the outline of a circular seal, an organization name, and a base plate image, and to determine the text radian and character size in the text corresponding to each organization name;
[0126] The second determining module 1002 is used to determine the target information of each character in the base plate image based on the text radian, character size and initial template image for each character in the organization name, and to arrange the character in the base plate image according to the target information to obtain the target base plate image matching the character. The target information includes the initial position information and rotation angle of the character.
[0127] Add module 1003 to add each character to the initial template image based on the target base image matched by each character in the organization name, so as to obtain the seal image matching the organization name.
[0128] It should be noted that the first determining module 1001, the second determining module 1002, and the adding module 1003 mentioned above correspond to steps S101 to S103 in the above embodiments. The examples and application scenarios implemented by the three modules and the corresponding steps are the same, but are not limited to the content disclosed in the above embodiment 1.
[0129] Optionally, the second determining module 1002 further includes: a first determining submodule, used to determine initial position information based on the character size and image information of the initial template image, and add characters to the base plate image based on the initial position information; and a second determining submodule, used to determine the rotation angle for character matching based on the text radian and the target sequence of the character in the organization name, and rotate the character in the base plate image according to the rotation angle to obtain the target base plate image for character matching.
[0130] Optionally, the first determining submodule further includes: a first determining unit, used to determine the character width based on the character size; a second determining unit, used to construct a target coordinate system with the target vertex of the base image as the origin, and to determine the horizontal coordinate information of the character in the target coordinate system based on the character width and the width of the initial template image; and a third determining unit, used to determine the vertical coordinate information of the character in the target coordinate system based on the radius information of the circular seal outline and the height of the initial template image, wherein the horizontal coordinate information and the vertical coordinate information constitute the initial position information.
[0131] Optionally, the second determining submodule further includes: a fourth determining unit, used to determine the target coefficient based on the number of characters in the organization name and the target sequence, wherein the target coefficient is a value less than 1; and a calculation unit, used to calculate the product of the text radian and the target coefficient to obtain the rotation angle.
[0132] Optionally, the second determining submodule further includes: a scaling unit, used to scale the base image and the characters in the base image according to the target width scaling ratio of the characters, to obtain a scaled base image and scaled characters, wherein the target width scaling ratio is determined based on the text curvature and the radius information of the circular seal outline; and a rotation unit, used to determine the center point of the scaled base image, and rotate the scaled characters in the scaled base image with the center point as the center and according to the rotation angle, to obtain the target base image.
[0133] Optionally, the adding module 1003 further includes: a cropping submodule, used to crop the target base image to the image size of the initial template image to obtain a cropped target base image, wherein the center point of the cropped target base image is the same as the center point of the target base image before cropping, and the image area of the target base image before cropping is larger than the initial template image; and an adding submodule, used to paste the scaled characters in the cropped target base image into the initial template image according to the position information of each character in the organization name in the cropped target base image to obtain a seal image.
[0134] Optionally, the first determining module 1001 further includes: an acquisition submodule, used to acquire the text radian and the initial character size, and determine the initial character width based on the initial character size; a third determining submodule, used to determine the initial arc length based on the text radian, the radius information of the circular seal outline, and the initial character width; a fourth determining submodule, used to determine the initial text length based on the initial character width, the number of characters in the organization name, and the initial width scaling ratio of the characters; and a fifth determining submodule, used to adjust the initial width scaling ratio of the characters and / or the initial character size when the initial text length is greater than the initial arc length, and to redetermine the initial arc length and the initial text length until the updated initial text length is less than or equal to the updated initial arc length, at which point the current initial width scaling ratio is determined as the target width scaling ratio, and the current initial character size is determined as the character size.
[0135] Example 4
[0136] According to an embodiment of the present invention, an embodiment of a seal recognition device is provided, wherein... Figure 11 This is a schematic diagram of an optional seal recognition device according to an embodiment of the present invention, such as... Figure 11 As shown, the device includes:
[0137] The first acquisition module 1101 is used to acquire the image of the seal to be identified;
[0138] The recognition module 1102 is used to input the seal image to be recognized into the seal recognition model, and to recognize the characters in the seal image to be recognized by the seal recognition model to obtain the target text sequence. The training set data of the seal recognition model is generated based on the seal image generation method described above.
[0139] It should be noted that the first acquisition module 1101 and the identification module 1102 mentioned above correspond to steps S801 to S802 in the above embodiments. The examples and application scenarios implemented by the two modules and the corresponding steps are the same, but are not limited to the content disclosed in the above embodiment 1.
[0140] Optionally, the seal recognition device further includes: a second acquisition module for acquiring multiple sample seal images, wherein the sample seal images are generated based on the above-described seal image generation method; a preprocessing module for preprocessing each sample seal image to obtain a processed sample seal image, wherein the preprocessing is at least one of the following: blurring, rotation; and a synthesis module for acquiring a preset background image and synthesizing the processed sample seal image into the background image to obtain a target sample seal image, wherein the target sample seal image is used to constitute training set data.
[0141] Example 5
[0142] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-described method for generating a seal image or a method for recognizing a seal when it is run.
[0143] Example 6
[0144] According to another aspect of the present invention, an electronic device is also provided, wherein, Figure 12 This is a schematic diagram of an optional electronic device according to an embodiment of the present invention, such as... Figure 12 As shown, the electronic device includes one or more processors; and a memory for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to run the programs, wherein the programs are configured to execute the above-described method for generating a seal image or a seal recognition method during runtime.
[0145] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0146] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0147] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.
[0148] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0149] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0150] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0151] The above are merely preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for generating a seal image, characterized in that, include: Obtain an initial template image containing the outline of a circular seal, an organization name, and a base image, and determine the text radian and character size for each organization name, wherein the image area of the base image is larger than that of the initial template image; For each character in the organization name, the target information of the character in the base image is determined according to the text radian, the character size and the initial template image, and the character is arranged in the base image according to the target information to obtain the target base image matching the character, wherein the target information includes the initial position information and rotation angle of the character; Based on the target base image matched by each character in the organization name, each character is added to the initial template image to obtain a seal image matching the organization name; The method further includes: The base image and the characters in the base image are scaled according to the target width scaling ratio of the characters to obtain the scaled base image and scaled characters. The target width scaling ratio is determined based on the text curvature and the radius information of the circular seal outline. Determine the center point of the scaled base image, and rotate the scaled characters in the scaled base image with the center point as the center and according to the rotation angle to obtain the target base image.
2. The method according to claim 1, characterized in that, The target information of the character in the background image is determined based on the text radian, the character size, and the initial template image. The character is then arranged in the background image according to the target information to obtain a target background image matching the character. This includes: The initial position information is determined based on the character size and the image information of the initial template image, and the character is added to the base image based on the initial position information; Based on the text radian and the target position of the character in the organization name, the rotation angle for matching the character is determined, and the character in the base image is rotated according to the rotation angle to obtain the target base image for matching the character.
3. The method according to claim 2, characterized in that, The initial position information is determined based on the character size and the image information of the initial template image, including: The character width is determined based on the character size; A target coordinate system is constructed with the target vertex of the base image as the origin, and the horizontal coordinate information of the character is determined in the target coordinate system according to the character width and the width of the initial template image; The vertical coordinate information of the character is determined in the target coordinate system based on the radius information of the circular seal outline and the height of the initial template image, wherein the horizontal coordinate information and the vertical coordinate information constitute the initial position information.
4. The method according to claim 2, characterized in that, Based on the text radians and the target position of the character in the organization name, determine the rotation angle for matching the character, including: The target coefficient is determined based on the number of characters in the organization name and the target ordinal position, wherein the target coefficient is a value less than 1; The rotation angle is obtained by calculating the product of the text radian and the target coefficient.
5. The method according to claim 2, characterized in that, Based on the target base image matched by each character in the organization name, the characters are added to the initial template image to obtain a seal image matching the organization name, including: The target base image is cropped to the image size of the initial template image to obtain the cropped target base image, wherein the center point of the cropped target base image is the same as the center point of the target base image before cropping, and the image area of the target base image before cropping is larger than the initial template image. Based on the position information of each character in the organization name in the cropped target base image, the scaled characters in the cropped target base image are pasted into the initial template image to obtain the seal image.
6. The method according to claim 2, characterized in that, Determine the character size in the text corresponding to the organization name, including: Obtain the text radian and initial character size, and determine the initial character width based on the initial character size; The initial arc length is determined based on the text arc length, the radius information of the circular seal outline, and the initial character width. The initial text length is determined based on the initial character width, the number of characters in the organization name, and the initial width scaling ratio of the characters; If the initial text length is greater than the initial arc length, adjust the initial width scaling ratio and / or the initial character size, and redetermine the initial arc length and initial text length until the updated initial text length is less than or equal to the updated initial arc length. Then, determine the current initial width scaling ratio as the target width scaling ratio and the current initial character size as the character size.
7. A seal recognition method, characterized in that, include: Obtain the image of the seal to be identified; The seal image to be identified is input into the seal recognition model, and the seal recognition model is used to identify the characters in the seal image to obtain the target character sequence. The training set data of the seal recognition model is generated based on the seal image generation method according to any one of claims 1 to 6.
8. The method according to claim 7, characterized in that, The training set data was generated using the following method: Multiple sample seal images are obtained, wherein the sample seal images are generated based on the seal image generation method according to any one of claims 1 to 6; For each sample stamp image, the sample stamp image is preprocessed to obtain a processed sample stamp image, wherein the preprocessing is at least one of the following: blurring, rotation; A preset background image is obtained, and the processed sample stamp image is synthesized into the background image to obtain a target sample stamp image, wherein the target sample stamp image is used to constitute the training set data.
9. A device for generating a seal image, characterized in that, For performing the method according to any one of claims 1 to 6, comprising: The first determining module is used to obtain an initial template image containing the outline of a circular seal, the organization name, and the base plate image, and to determine the text radian and character size in the text corresponding to each organization name; The second determining module is used to determine the target information of each character in the base image based on the text radian, the character size and the initial template image for each character in the organization name, and to arrange the character in the base image according to the target information to obtain the target base image matching the character, wherein the target information includes the initial position information and rotation angle of the character; An adding module is used to add each character to the initial template image based on the target base image matched by each character in the organization name, so as to obtain a seal image matching the organization name.
10. A seal recognition device, characterized in that, include: The first acquisition module is used to acquire the image of the seal to be identified; The recognition module is used to input the seal image to be recognized into the seal recognition model, and to recognize the characters in the seal image to be recognized by the seal recognition model to obtain the target text sequence. The training set data of the seal recognition model is generated based on the seal image generation method according to any one of claims 1 to 6.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute, when running, the method for generating a seal image as described in any one of claims 1 to 6, or the method for recognizing a seal as described in any one of claims 7 to 8.
12. An electronic device, characterized in that, The electronic device includes one or more processors; A memory for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to be configured to run the programs, wherein the programs are configured to execute the method for generating a seal image as described in any one of claims 1 to 6, or the method for recognizing a seal as described in any one of claims 7 to 8.