A seal image correction method and related apparatus

CN122966487APending Publication Date: 2026-10-23BEIJING SURSEN ELECTRONIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611179563.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-05
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0003]而目前的校正算法为消除旋转差异,常以固定旋转步长进行360°的循环遍历匹配,造成大量的冗余计算,无法满足大批量合同实时比对的高性能需求

Benefits of technology

[0039]借由上述技术方案,本申请提供的一种印章图像校正方法及相关装置。本方法提取印章图像并识别印章图像的几何形状,锁定圆形形状的印章并定位圆心,提取印章图像的五角星轮廓,依托五角星的固有结构提取五组顶点,每组顶点包含对应的凸顶点与凹顶点,通过各组的凸顶点和凹顶点分别构建直线,可表征五角星的几何姿态信息。通过计算圆心至各条直线的几何垂直距离,筛选出最小垂直距离对应的直线作为印章图像的主轴线,还原印章图像的当前偏转状态,基于主轴线计算印章图像真实的偏转角,依据偏转角完成印章图像的旋转校正。本方法基于印章图像中五角星的固有几何特征完成偏转角的精准确定,无需冗余遍历运算,可大幅简化校正运算流程、提升校正响应速度,满足大批量合同实时比对的高性能需求。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122966487A_ABST
    Figure CN122966487A_ABST
Patent Text Reader

Abstract

The application discloses a seal image correction method and related device, and relates to the field of image correction, and comprises the following steps: extracting a seal image, judging the geometric shape of the seal image, if the seal image is determined as a circular shape, determining the center of the seal image and extracting a five-pointed star contour in the seal image, the five-pointed star contour comprises five groups of vertices, each group of vertices comprises a convex vertex and a concave vertex farthest from the convex vertex; obtaining a plurality of straight lines of the seal image, each straight line is determined by the convex vertex and the concave vertex of a group of vertices; the geometric perpendicular distance from the center to each straight line is calculated respectively, and the straight line with the smallest geometric perpendicular distance is determined as the main axis of the seal image; the deflection angle of the seal image is determined based on the main axis, and the seal image is rotated and corrected based on the deflection angle. The application completes accurate determination of the deflection angle based on the inherent geometric characteristics of the five-pointed star in the seal image, does not need redundant traversal operation, and effectively simplifies the correction operation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image correction technology, and in particular to a method and apparatus for correcting seal images. Background Technology

[0002] In intelligent scenarios such as corporate contract review, financial compliance, and legal document auditing, consistent comparison of seal images on contract texts is a core task. Because seals are highly random in the actual physical affixing process, the same seal often exhibits different deflection angles on different contract texts. Therefore, seal images must be corrected before seal comparison.

[0003] Current correction algorithms often use a fixed rotation step size to perform 360° cyclic matching in order to eliminate rotation differences, resulting in a large amount of redundant calculations and failing to meet the high-performance requirements of real-time comparison of large batches of contracts. Summary of the Invention

[0004] In view of the above problems, this application provides a method and related apparatus for correcting seal images, so as to achieve the purpose of quickly correcting seal images. The specific solution is as follows:

[0005] The first aspect of this application provides a seal image correction method, the seal image correction method comprising:

[0006] Extract the seal image, determine the geometric shape of the seal image, if the seal image is determined to be circular, then determine the center of the seal image and extract the pentagram outline in the seal image. The pentagram outline includes five sets of vertices, each set of vertices includes a convex vertex and a concave vertex that is farthest from the convex vertex.

[0007] Multiple straight lines are obtained from the seal image, each straight line being determined by a set of convex and concave vertices;

[0008] Calculate the geometric perpendicular distance from the center of the circle to each straight line, and determine the straight line with the smallest geometric perpendicular distance as the main axis of the seal image;

[0009] The deflection angle of the seal image is determined based on the main axis, and the seal image is rotated and corrected based on the deflection angle.

[0010] In one possible implementation, extracting the pentagram outline from the seal image includes:

[0011] Detect the closed contour in the seal image. If the closed contour has a number of vertices falling within a preset range and the number of contour convexity defects of the closed contour is not less than a preset number, then the closed contour is determined to be the pentagram contour.

[0012] or,

[0013] The stamp image is matched with an ideal pentagram template to obtain the outline of the pentagram.

[0014] In one possible implementation, determining the center of the seal image includes:

[0015] Using the Hough circle transform, multiple circular contours of the seal image are extracted under the current threshold constraints of the center and radius.

[0016] If the diameter of the target circular outline is detected to fall within a preset diameter range, then the center of the target circular outline is determined as the center of the seal image.

[0017] If the target circular outline is not detected, the current threshold constraints of the center and radius are adjusted, and the process returns to the step of extracting multiple circular outlines of the seal image.

[0018] One possible implementation also includes:

[0019] If there are at least two target circular outlines, then calculate the area and perimeter of each target circular outline;

[0020] The roundness of each target circular contour is calculated based on its area and perimeter, and the target circular contour with the largest area that meets the preset range of roundness is selected.

[0021] In one possible implementation, determining the deflection angle of the seal image based on the main axis includes:

[0022] Determine the angle between the main axis and the correction direction, and define the angle as the deflection angle. The correction direction is one of the following directions of the seal image: the left direction, the right direction, the top direction, or the bottom direction.

[0023] In one possible implementation, extracting the seal image includes:

[0024] The color space of the initial image is converted to the HSV color space, and an initial mask of the initial image is generated based on the hue threshold.

[0025] The initial mask is modified to obtain a cleaned mask for boundary detection;

[0026] Generate an image detail mask for the initial image, and combine the image detail mask with the cleanup mask to obtain the stamp mask for the initial image;

[0027] The seal image is obtained from the initial image using the seal mask.

[0028] In one possible implementation, determining the geometry of the seal image includes:

[0029] Extract the outermost contour of the seal image, perform shape fitting on the outermost contour, and obtain the shape parameters of the outermost contour;

[0030] The geometric shape of the seal image is determined based on the shape parameters.

[0031] In one possible implementation, the shape parameters include the major axis length and the minor axis length, and determining the geometric shape of the seal image based on the shape parameters includes:

[0032] Determine whether the ratio of the major axis length to the minor axis length is greater than a preset ratio;

[0033] If the ratio of the major axis length to the minor axis length is greater than the preset ratio, then the seal image is determined to be elliptical.

[0034] If the ratio of the major axis length to the minor axis length is not greater than the preset ratio, then the seal image is determined to be circular.

[0035] One possible implementation also includes:

[0036] If the seal image is elliptical, the deflection angle of the seal image is calculated based on the angle between the major axis of the seal image and the horizontal line of the seal image.

[0037] The stamp image is corrected based on the deflection angle.

[0038] A second aspect of this application provides a computer program product including computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the seal image correction method of the first aspect or any implementation thereof.

[0039] Based on the above technical solution, this application provides a method and related apparatus for seal image correction. This method extracts a seal image and identifies its geometric shape, identifies a circular seal and locates its center, extracts the outline of a pentagram from the seal image, and extracts five sets of vertices based on the inherent structure of the pentagram. Each set of vertices includes corresponding convex and concave vertices. Straight lines are constructed using the convex and concave vertices of each set, representing the geometric posture information of the pentagram. By calculating the geometric perpendicular distance from the center to each straight line, the line corresponding to the minimum perpendicular distance is selected as the main axis of the seal image, restoring the current deflection state of the seal image. The true deflection angle of the seal image is calculated based on the main axis, and the rotation correction of the seal image is completed based on the deflection angle. This method accurately determines the deflection angle based on the inherent geometric features of the pentagram in the seal image, eliminating the need for redundant traversal calculations. This significantly simplifies the correction calculation process, improves the correction response speed, and meets the high-performance requirements of real-time comparison of large batches of contracts. Attached Figure Description

[0040] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.

[0041] Figure 1 A schematic flowchart illustrating a seal image correction method provided in an embodiment of this application;

[0042] Figure 2 A schematic diagram of a pentagram outline provided in an embodiment of this application;

[0043] Figure 3 This is a hardware structure block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0044] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.

[0045] As will be known to those skilled in the art, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.

[0046] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.

[0047] In intelligent scenarios such as corporate contract review, financial compliance, and legal document auditing, consistent comparison of seal images on contract texts is a core task. Due to the high degree of randomness in the actual physical affixing process of seals, the same seal often exhibits different deflection angles on different contract texts. Current seal correction methods generally suffer from the following shortcomings:

[0048] Traversing angle by angle results in poor comparison performance. To eliminate rotational differences, a fixed rotation step size is often used for 360° loop matching, resulting in a large amount of redundant calculations, which cannot meet the high-performance requirements of real-time comparison of large batches of contracts.

[0049] Text background interference is severe. Printed text, table lines, or signatures in the text often intertwine and overlap with the seal area, making it difficult for traditional edge detection techniques to accurately determine the actual outline of the seal;

[0050] Irregularly shaped seals are not well-suited for this purpose. Most traditional algorithms are designed only for standard round seals. When faced with elliptical seals, the dynamic changes in the major and minor axes make angle alignment more prone to failure.

[0051] To address the aforementioned problems, this application provides a seal image correction method. The seal image correction method of this application embodiment will be described in detail below with reference to the accompanying drawings.

[0052] Reference Figure 1 , Figure 1 This is a flowchart illustrating a seal image correction method provided in an embodiment of this application, as shown below. Figure 1 As shown in the figure, the seal image correction method provided in this application embodiment may include steps S10 to S13, which are described in detail below.

[0053] S10. Extract the seal image and determine the geometric shape of the seal image. If the seal image is determined to be circular, determine the center of the seal image and extract the outline of the five-pointed star in the seal image.

[0054] The seal image can refer to an image region in the initial image that contains only the seal pattern. This embodiment can extract the seal image from the initial image using a color isolation and dual-mask fusion mechanism. Specifically, this embodiment first converts the color space of the initial image to the HSV color space, generates an initial mask based on a hue threshold, modifies the initial mask to obtain a cleaned mask for boundary detection, generates an image detail mask for the initial image, combines the image detail mask and the cleaned mask to obtain the seal mask of the initial image, and then uses the seal mask to extract the seal image from the initial image.

[0055] Since the stamps in documents are generally red, while the background text and table lines are mostly black or gray, image processing in the RGB color space is difficult to effectively separate the stamps from the background interference. The HSV color space, however, can decouple color information into three components: hue, saturation, and lightness. Furthermore, the hue component has good stability to changes in illumination, making it suitable for image extraction. However, the red of the stamps spans the boundary between 0 and 360 degrees on the color wheel, resulting in a discontinuous numerical distribution. Therefore, this embodiment sets at least two hue threshold intervals to cover the hue range of the red stamps, ensuring the extraction of the red stamps from the initial image. Optionally, the two hue threshold intervals in this embodiment can be [0, 15] and [160, 180]. This embodiment can perform image processing using one hue threshold interval each, obtaining binarization results corresponding to the two hue threshold intervals. In the binarization results, the values ​​of pixels whose hue values ​​fall within the hue threshold intervals are different from those of pixels whose hue values ​​do not fall within the hue threshold intervals. The binary results corresponding to the two hue threshold ranges are bitwise ORed and merged to generate the initial mask. Bitwise OR is a binary-level calculation where each binary digit is either 1 or 0. In this embodiment, setting multiple hue threshold ranges effectively avoids the problem of missing stamp colors caused by truncation from a single threshold.

[0056] Mask modification can refer to morphological operations or filtering of the mask to optimize its topology. Specifically, since the initial mask may contain noise and voids caused by uneven stamping or paper texture, and the actual stamp is not perfectly circular (a small amount of slippage during stamping may result in a non-circular stamp), and since a circle is a subset of an ellipse, this embodiment can use elliptical structuring elements to sequentially perform closing, dilation, and erosion operations on the initial mask to smooth the stamp edges and fill internal breaks. Closing operations can fill small breaks inside the stamp, dilation operations can connect adjacent discrete regions, and erosion operations can eliminate burr edges while maintaining overall connectivity. After modifying the initial mask, a cleaned mask for boundary detection can be obtained. The stamp image extracted through this cleaned mask can have smooth and continuous outer boundary features, which can be used to support the fitting of the stamp contour in subsequent processing.

[0057] In another alternative embodiment, this embodiment may also employ image processing algorithms such as Gaussian blur, median filtering, or guided filtering to achieve smoothing and image denoising effects.

[0058] Furthermore, to achieve both external contour recognition and internal detail preservation of the seal, this embodiment introduces a combination mechanism of image detail mask and cleansing mask. The image detail mask can refer to a mask used to extract detailed information such as the pentagram and strokes of characters within the seal. In this embodiment, adaptive Gaussian threshold binarization is performed on the initial image and then inverted to obtain an adaptive binary image as the image detail mask. A bitwise AND operation is then performed between the image detail mask and the cleansing mask to obtain the final seal mask. The bitwise AND operation is a binary-level calculation, where each binary digit follows the binary operation rule of all 1s equals 1 and all 0s equals 0. The cleansing mask provides overall shape constraints for the seal, while the image detail mask provides internal structural information that might be lost due to color threshold filtering. The seal image extracted from the initial image using the final generated seal mask maintains a complete external geometric shape and preserves rich internal details, effectively avoiding text background interference.

[0059] After obtaining the seal image from the initial image using a seal mask, the geometric shape of the seal image can be determined. Different geometric shapes require different subsequent processing. Specifically, in this embodiment, the outermost contour of the seal image can be extracted, shape fitting can be performed on the outermost contour to obtain its shape parameters, and the geometric shape of the seal image can be determined based on these shape parameters. Here, the shape parameters can refer to quantified parameters describing the geometric shape, size, orientation, and position of the contour.

[0060] In this embodiment, a least-squares ellipse fitting algorithm based on image moments can be used. By statistically calculating the first and second moments of the contour points, an ellipse parametric equation containing the center coordinates, major axis length, minor axis length, and rotation angle is output. The rotation angle can refer to the angle between the major axis and the horizontal line. This embodiment can transform unstructured pixel-level contours into structured numerical features through shape parameters obtained by shape fitting, providing a quantitative basis for judging geometric shapes. This effectively avoids shape misjudgments caused by relying solely on visual perception or simple threshold segmentation, and can effectively target irregularly shaped elliptical stamps.

[0061] This embodiment can determine the geometric shape of the seal image based on shape parameters. Specifically, the shape parameters may include the major axis length and the minor axis length. This embodiment can determine whether the ratio of the major axis length to the minor axis length is greater than a preset ratio. If the ratio of the major axis length to the minor axis length is greater than the preset ratio, the seal image is determined to be elliptical; if the ratio of the major axis length to the minor axis length is not greater than the preset ratio, the seal image is determined to be circular.

[0062] Since the major axis and minor axis are two orthogonal dimensions describing the shape of an ellipse, the ratio of the major axis to the minor axis can intuitively reflect the flatness of the ellipse, where the major axis is the numerator and the minor axis is the denominator. Furthermore, during the stamping process, a standard circular stamp can undergo a certain degree of elastic deformation due to factors such as paper texture and uneven pressure, resulting in a non-perfect circle. Therefore, the preset ratio in this embodiment can be 1.2, creating a buffer value range of 0.2. This ensures the recognition of both elliptical stamps and slightly deformed circular stamps. When the ratio of the major axis length to the minor axis length is greater than 1.2, the geometric shape of the seal image can be determined to have significant elliptical characteristics and be elliptical. When the ratio of the major axis length to the minor axis length is not greater than 1.2, the geometric shape of the seal image can be determined to be circular. In order to avoid changes in the major and minor axes, this embodiment also sets a minimum value of the preset ratio, which can be 1. When the ratio of the major axis length to the minor axis length is greater than 1 but not greater than 1.2, the geometric shape of the seal image can be determined to be circular.

[0063] Of course, in another optional embodiment, since the seal image has lateral and vertical deformation, this embodiment can also set a range for the ratio of the major axis length to the minor axis length. When the ratio of the major axis length to the minor axis length falls within the range, the geometric shape of the seal image can be determined to be circular; if it does not fall within the range, the geometric shape of the seal image can be determined to be elliptical. Optionally, the range can be specifically [0.8, 1.2].

[0064] If the seal image is elliptical, the deflection angle of the seal image can be directly calculated based on the angle between the major axis of the seal image and the horizontal line of the seal image, and the seal image can be corrected based on the deflection angle. Since an elliptical seal itself has geometric orientation, its major axis can represent the physical axis of symmetry of the seal or the reference direction for text arrangement. Therefore, this embodiment can directly utilize the ellipse parameters obtained in the shape fitting stage for rapid correction. Specifically, this embodiment can determine the angle between the major axis of the seal image and the horizontal line of the seal image as the initial deflection angle of the ellipse, and calculate the final deflection angle of the seal image based on this initial deflection angle. The calculation formula is as follows:

[0065] ;

[0066] in, It can represent the deflection angle of the seal image; The original deflection angle can be represented as the angle between the major axis and the horizontal line of the seal image. In this embodiment, the major axis of the seal image can be forcibly aligned to the horizontal line by adding or subtracting 90 degrees, avoiding traversal matching and achieving rapid image correction.

[0067] This embodiment can construct an affine rotation matrix around the geometric center, reconstruct the canvas size based on trigonometric functions to prevent edge cropping, use the boundary copy mode to perform affine transformation, correct the major axis to the horizontal line, and then crop out a square slice that is close to the edge of the stamp to complete the correction of the elliptical stamp image.

[0068] If the seal image is circular, the center of the seal image can be determined and the outline of the pentagram in the seal image can be extracted. The deflection angle of the corrected seal image can then be determined based on the pentagram outline.

[0069] This embodiment utilizes the Hough circle transform to extract multiple circular contours of the seal image under the current threshold constraints of the center and radius. If the diameter of the target circular contour falls within a preset diameter range, the center of the target circular contour is determined as the center of the seal image. If no target circular contour is detected, the current threshold constraints of the center and radius are adjusted, and the process returns to the step of extracting multiple circular contours of the seal image, performing a second Hough circle transform detection. This process is repeated until a target circular contour with a diameter falling within the preset diameter range is detected, and the center of the target circular contour is determined as the center of the seal image.

[0070] The Hough circle transform can be described as a geometric shape detection algorithm based on parameter space voting, which maps edge points in image space to curve intersections in parameter space, thereby identifying potential circular structures. The Hough circle transform allows setting current threshold constraints for the center and radius of the circle. Specifically, the deviation of the center from the center of the currently extracted image region should not exceed 15%, and the deviation of the radius from the expected standard radius should not exceed 10%.

[0071] The preset diameter range can refer to the diameter range set according to the physical specifications of the standard official seal. Specifically, in this embodiment, the preset diameter range can be [38mm, 45mm], which can filter out noise circles that are too small or arc-shaped interferences that are too large in the background.

[0072] This embodiment can prevent fluctuations in stamp quality in real-world scenarios through a rollback mechanism. When the stamp is clear and complete, the current thresholds for the center and radius can quickly lock the target circular outline. When the stamp is blurred due to insufficient ink or paper wrinkles causing broken edges, the thresholds for the center and radius can be automatically expanded to widen the search range for the circular outline. By sacrificing computational accuracy to improve the detection recall rate of the outline, the center can be determined even under adverse imaging conditions.

[0073] If at least two target circular outlines are determined to exist based on a preset diameter range, the area and perimeter of each target circular outline are calculated. Based on the area and perimeter, the circularity of each target circular outline is calculated, and the target circular outline with the largest area that meets the preset circularity range is selected.

[0074] Circularity refers to the degree to which a closed contour approximates a perfect circle. For an ideal circle, the circularity value is 1. The more irregular or flat the contour, the greater the deviation of the circularity value from 1. The formula for calculating circularity is as follows:

[0075] ;

[0076] in, It can indicate roundness; It can represent pi; It can represent the area of ​​a circular outline; It can represent the circumference of a circular outline. In this embodiment, the preset range of circularity can be specifically [0.7, 1.3] to accommodate the elastic deformation caused by physical stamping.

[0077] When the Hough circle transform detects multiple candidate circular contours that satisfy the diameter condition, and all of them satisfy the diameter condition, the diameter alone cannot determine the outer circular contour. This embodiment chooses to introduce dual constraints of circularity and area. Circularity can eliminate non-circular near-circular noise. Since the outer boundary of the seal is usually the largest red connected region in the image, the maximum area criterion can determine the outer circular contour of the real seal based on the circularity.

[0078] Since seals commonly feature five-pointed stars, this embodiment detects the outline of the five-pointed star in the seal image and determines the degree of offset of the seal image based on the outline of the five-pointed star.

[0079] For the detection of the pentagram outline, this embodiment can detect the closed outline in the seal image. If the closed outline has a number of vertices falling within a preset range and the number of convexity defects in the closed outline is not less than a preset number, then the closed outline is determined to be a pentagram outline. Alternatively, this embodiment can also use an ideal pentagram template to match the seal image, thereby obtaining the pentagram outline in the seal image.

[0080] Here, convexity defects refer to the concave region between the convex hull of an object and its actual contour, which topologically manifests as a local minimum point where the contour folds inward. Since a standard pentagram's geometric essence is a decagon formed by alternating connections of five convex vertices and five concave vertices, its number of vertices should be 8-20, and the number of convexity defects should be at least 3. Therefore, in this embodiment, the preset range for the number of vertices can be set to [8, 20], and the preset number of convexity defects for the closed contour can be set to 3. This embodiment can determine whether a closed contour is a pentagram contour by judging the number of vertices and the number of convexity defects.

[0081] When the extraction of the pentagram fails due to factors such as severe staining or obstruction of the seal, this embodiment can use a preset ideal pentagram template to periodically match the pentagram outline in the seal image from multiple angles, forcibly obtaining the key vertices of the pentagram outline in the seal image. Specifically, this embodiment can achieve multi-angle periodic matching of the pentagram outline in a 2° step within a period of [0°, 72°].

[0082] S11. Obtain multiple straight lines from the seal image, each straight line being determined by a set of convex and concave vertices.

[0083] S12. Calculate the geometric perpendicular distance from the center of the circle to each straight line, and determine the straight line with the smallest geometric perpendicular distance as the main axis of the seal image.

[0084] S13. Determine the deflection angle of the seal image based on the main axis, and perform rotation correction on the seal image based on the deflection angle.

[0085] The pentagram outline can include five sets of vertices. Each set of vertices includes a convex vertex and a concave vertex furthest from the convex vertex. The convex and concave vertices of each set of vertices in the pentagram outline can each define a straight line, thus allowing multiple straight lines to be defined for the pentagram outline. For example... Figure 2 As shown, a simple circular seal contains a pentagram. The pentagram consists of five convex vertices and five concave vertices. A convex vertex A and a concave vertex B that is furthest from the convex vertex form a group, and the straight line determined by them can be a straight line L. Thus, five straight lines can be obtained.

[0086] In this embodiment, the center of the circle determined by the seal image can be used as the origin of the central coordinate system, with the right side of the seal image as the X-axis and the direction perpendicular to the X-axis as the Y-axis. This allows us to obtain the pixel coordinates of the center of the circle, as well as the pixel coordinates of all convex and concave vertices in the pentagram outline. Based on the pixel coordinates of the convex and concave vertices belonging to the same group, the equations of the lines defined by the convex and concave vertices can be obtained. The forms of the line equations can all be as follows:

[0087] ;

[0088] in, , and Both can be coefficients, which can be calculated from the pixel coordinates of the convex vertex and the pixel coordinates of the concave vertex.

[0089] After obtaining the equations of multiple straight lines for the pentagram outline in this embodiment, the geometric perpendicular distance from the center of the circle to each straight line can be calculated separately. The calculation formula is as follows:

[0090] ;

[0091] The principal axis can refer to the straight line representing the rotation reference of the seal. Since the position of the pentagram in the seal can be mainly divided into two categories: the center of the pentagram coincides with the center of the seal, and the pentagram is above the center of the seal. When the center of the pentagram coincides with the center of the seal, all five straight lines of the pentagram's outline can pass through the center of the seal, and any one of these straight lines can be chosen as the principal axis for subsequent image correction. However, when the pentagram is above the center of the seal, only one straight line of the pentagram's outline can pass through the center of the seal. Furthermore, if there is no rotational deviation in the seal image, this straight line should be vertically upwards, while the other straight lines can have a significant offset from the center of the seal. The straight line passing through the center of the seal can be used as the principal axis for subsequent image correction. The rotational deviation of the seal image can be quantified by measuring the rotational deviation of the principal axis. Because the actual seal image may be deformed, causing the straight line that should pass through the seal center to deviate from the seal center, this embodiment determines the main axis by calculating the geometric perpendicular distance from the center of the seal image circle (seal center) to each straight line, and selecting the straight line with the smallest geometric perpendicular distance. This straight line is then determined as the straight line that should pass through the seal center and is used as the main axis of the seal image. The geometric perpendicular distance can refer to the Euclidean distance from the center of the circle to the straight line.

[0092] The deflection angle can refer to the angle between the current main axis and a preset standard correction direction. In this embodiment, after determining the main axis, the angle between the main axis and the correction direction can be calculated, and this angle is determined as the deflection angle. The correction direction can refer to a pre-set unified reference direction, which can eliminate differences in rotational degrees of freedom between different stamp images. The correction direction can be one of the following directions: directly left, directly right, directly up, or directly down of the stamp image. In this embodiment, the correction direction is directly left of the stamp image.

[0093] This embodiment constructs an affine transformation matrix using the final deflection angle, rotating the entire stamp image so that the convex or concave vertices of the pentagram outline within the stamp image, located on the main axis, point towards the correction direction. Furthermore, this embodiment can perform binary inverse masking on the aligned standard image, setting the α channel of the white background to 0 to generate a PNG transparent image. Based on the configuration, pixels in the non-transparent stamp areas are losslessly replaced with the target contrast color, such as blue or red, facilitating pixel-level difference analysis by the subsequent stamp comparison engine. Here, the PNG transparent image refers to a PNG bitmap with an alpha channel, where the transparent areas allow some areas to show through.

[0094] This application provides a seal image correction method. The method extracts a seal image and identifies its geometric shape. It identifies a circular seal and locates its center. The method extracts the outline of a five-pointed star from the seal image and extracts five sets of vertices based on the inherent structure of the five-pointed star. Each set of vertices includes corresponding convex and concave vertices. Straight lines are constructed using the convex and concave vertices of each set, representing the geometric posture information of the five-pointed star. By calculating the geometric perpendicular distance from the center to each straight line, the line with the smallest perpendicular distance is selected as the main axis of the seal image, restoring the current deflection state of the seal image. The true deflection angle of the seal image is calculated based on the main axis, and the rotation correction of the seal image is completed based on the deflection angle. This method accurately determines the deflection angle based on the inherent geometric features of the five-pointed star in the seal image, eliminating the need for redundant traversal calculations. This significantly simplifies the correction calculation process, improves the correction response speed, and meets the high-performance requirements of real-time comparison of large batches of contracts.

[0095] This application also provides an electronic device in its embodiments. (See reference...) Figure 3 The diagram illustrates a structural schematic of an electronic device suitable for implementing the seal image correction method in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 3 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0096] like Figure 3 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. When the electronic device is powered on, the RAM 303 also stores various programs and data required for the operation of the electronic device. The processing unit 301, ROM 302, and RAM 303 are interconnected via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0097] Typically, the following devices can be connected to I / O interface 305: input devices 306 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 307 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 308 including, for example, memory cards, hard drives, etc.; and communication devices 309. Communication device 309 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 3Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.

[0098] This application also provides a computer program product, including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the seal image correction methods provided in this application.

[0099] This application also provides a computer-readable storage medium carrying one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the seal image correction methods provided in this application.

[0100] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.

[0101] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0102] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.

[0103] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).

[0104] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0105] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0106] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for correcting a seal image, characterized in that, The seal image correction method includes: Extract the seal image, determine the geometric shape of the seal image, if the seal image is determined to be circular, then determine the center of the seal image and extract the pentagram outline in the seal image. The pentagram outline includes five sets of vertices, each set of vertices includes a convex vertex and a concave vertex that is farthest from the convex vertex. Multiple straight lines are obtained from the seal image, each straight line being determined by a set of convex and concave vertices; Calculate the geometric perpendicular distance from the center of the circle to each straight line, and determine the straight line with the smallest geometric perpendicular distance as the main axis of the seal image; The deflection angle of the seal image is determined based on the main axis, and the seal image is rotated and corrected based on the deflection angle.

2. The seal image correction method according to claim 1, characterized in that, Extracting the five-pointed star outline from the seal image includes: Detect the closed contour in the seal image. If the closed contour has a number of vertices falling within a preset range and the number of contour convexity defects of the closed contour is not less than a preset number, then the closed contour is determined to be the pentagram contour. or, The stamp image is matched with an ideal pentagram template to obtain the outline of the pentagram.

3. The seal image correction method according to claim 1, characterized in that, Determining the center of the circle of the seal image includes: Using the Hough circle transform, multiple circular contours of the seal image are extracted under the current threshold constraints of the center and radius. If the diameter of the target circular outline is detected to fall within a preset diameter range, then the center of the target circular outline is determined as the center of the seal image. If the target circular outline is not detected, the current threshold constraints of the center and radius are adjusted, and the process returns to the step of extracting multiple circular outlines of the seal image.

4. The seal image correction method according to claim 3, characterized in that, Also includes: If there are at least two target circular outlines, then calculate the area and perimeter of each target circular outline; The roundness of each target circular contour is calculated based on its area and perimeter, and the target circular contour with the largest area that meets the preset range of roundness is selected.

5. The seal image correction method according to claim 1, characterized in that, Determining the deflection angle of the seal image based on the main axis includes: Determine the angle between the main axis and the correction direction, and define the angle as the deflection angle. The correction direction is one of the following directions of the seal image: the left direction, the right direction, the top direction, or the bottom direction.

6. The seal image correction method according to claim 1, characterized in that, The extraction of the seal image includes: The color space of the initial image is converted to the HSV color space, and an initial mask of the initial image is generated based on the hue threshold. The initial mask is modified to obtain a cleaned mask for boundary detection; Generate an image detail mask for the initial image, and combine the image detail mask with the cleanup mask to obtain the stamp mask for the initial image; The seal image is obtained from the initial image using the seal mask.

7. The seal image correction method according to claim 1, characterized in that, The determination of the geometric shape of the seal image includes: Extract the outermost contour of the seal image, perform shape fitting on the outermost contour, and obtain the shape parameters of the outermost contour; The geometric shape of the seal image is determined based on the shape parameters.

8. The seal image correction method according to claim 7, characterized in that, The shape parameters include the length of the major axis and the length of the minor axis. Determining the geometric shape of the seal image based on the shape parameters includes: Determine whether the ratio of the major axis length to the minor axis length is greater than a preset ratio; If the ratio of the major axis length to the minor axis length is greater than the preset ratio, then the seal image is determined to be elliptical. If the ratio of the major axis length to the minor axis length is not greater than the preset ratio, then the seal image is determined to be circular.

9. The seal image correction method according to claim 1, characterized in that, Also includes: If the seal image is elliptical, the deflection angle of the seal image is calculated based on the angle between the major axis of the seal image and the horizontal line of the seal image. The stamp image is corrected based on the deflection angle.

10. A computer program product, characterized in that, It includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the seal image correction method as described in any one of claims 1 to 9.