A method of copying an identity card, a scanner

CN123035268APending Publication Date: 2026-11-03BEIJING ZIGUANG HANTU TECHNOLOGY CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611166357.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

In existing technologies, when a scanner copies an ID card with the cover closed, it is prone to positional shifts, incorrect rotation angles, and discontinuous edge and contour information, resulting in incomplete cropping of the copied image, inconsistent orientation, and low accuracy of subsequent automatic recognition. Furthermore, it cannot accurately copy or automatically recognize the ID card when the cover is open.

Method used

Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization are employed, combined with dilation and erosion operations, to perform connected component analysis, filter out candidate ID card outlines, determine the real ID card region, and center-align it in the original image through rotation and translation.

Benefits of technology

It enables stable and accurate identification and correction of the ID card area whether the cover is open or closed, improving the reliability and accuracy of copying operations, simplifying the operation process, and increasing copying efficiency in high-frequency usage scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123035268A_ABST
    Figure CN123035268A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of scanner image processing, in particular to an ID card copying method and a scanner, the method is applied to the scanner and comprises the following steps: in the case that a scanning instruction is received, an original image is acquired, Laplacian sharpening processing, Gaussian smoothing processing and adaptive Gaussian threshold binarization processing are sequentially performed on the original image, and a binarized image is obtained; an inflation operation and an erosion operation are sequentially performed on the binarized image, and a candidate region image is obtained; connected component analysis is performed on the candidate region image, the contour of all connected regions is extracted, and a candidate ID card contour set is screened out; a real ID card region is determined, a center position and angle information of the real ID card region in the original image are acquired; and the real ID card region is rotated and translated according to the center position and the angle information, so that the real ID card region is centered in the original image and aligned with a preset reference direction, and a corrected ID card image is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of scanner image processing technology, and in particular to a method for photocopying an ID card and a scanner. Background Technology

[0002] In modern office settings, ID card copying is a routine operation. In existing technologies, when a user copies an ID card with the scanner lid closed, the scanner directly acquires the image from the optical acquisition surface. However, it's difficult to guarantee precise centering and consistent orientation when the user manually places the ID card. This often results in the original image showing the ID card being misaligned, slightly rotated, or at an incorrect angle. Furthermore, due to contact pressure between the ID card and the scanner glass, uneven lighting conditions, or background interference, edge and contour information in the scanned image may be broken, blurred, or subject to noise interference, further increasing the difficulty of accurately extracting the ID card area. Existing methods based on fixed threshold binarization, template matching, or simple image cropping often fail to accurately identify the ID card area when processing scanned images with the lid closed, and are also unable to correct rotation or misalignment issues in the image. This can lead to incomplete or incorrectly oriented copies, affecting the copying quality and the reliability of subsequent automated recognition. Moreover, the aforementioned existing methods only work when the scanner lid is closed; they cannot accurately copy or automatically recognize ID cards scanned with the lid open, limiting their application scenarios.

[0003] Furthermore, there are also drawbacks in the operation process of using the closed-cover scanner. For example, since ID card copying usually requires scanning both sides separately, when the cover is closed, the user needs to open the scanner cover after each scan, flip the ID card over, and then close the cover again to perform the next scan. This results in frequent opening and closing of the cover during the entire operation, which not only increases the number of operation steps but also reduces copying efficiency and leads to a poor user experience. This problem is even more prominent in batch copying or high-frequency use scenarios. Summary of the Invention

[0004] (a) Technical problems to be solved

[0005] In view of the above-mentioned shortcomings and deficiencies of the prior art, this application provides an ID card copying method and scanner, which solves the technical problems of the prior art that can only be used when the scanner is closed, cannot adapt to other scanning states, and the ID card is prone to positional shift, incorrect rotation angle, discontinuous edge and contour information, resulting in incomplete cropping of the copied image, inconsistent orientation, and low accuracy of subsequent automatic recognition.

[0006] (II) Technical Solution

[0007] To achieve the above objectives, the main technical solutions adopted in this application include:

[0008] In a first aspect, embodiments of this application provide a method for photocopying an ID card, the method being applied to a scanner, comprising:

[0009] Upon receiving a scanning command, the system acquires the original image and sequentially performs Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization on the original image to obtain a binarized image. The original image is a color or grayscale image captured by the scanner when the cover is open or closed. The binarized image is then subjected to dilation and erosion operations to obtain candidate region images. Connectivity component analysis is performed on the candidate region images to extract the contours of all connected regions, and a candidate ID card contour set is selected. The actual ID card region is determined from the candidate ID card contour set, and the center position and angle information of the actual ID card region in the original image are obtained. Based on the center position and angle information, the actual ID card region is rotated and translated to center it in the original image and align it with a preset reference direction, resulting in a corrected ID card image.

[0010] Optionally, in some embodiments of this application, the original image is subjected to Laplacian sharpening processing, including: performing a Laplacian sharpening operation on the original image to obtain a Laplacian sharpened image, wherein the Laplacian sharpened image is obtained by convolving each row of pixel data of the original image using a custom filter kernel, and the custom filter kernel is {-1, -2, -1, 0, 0, 1, 2, 1}.

[0011] Optionally, in some embodiments of this application, the binarized image is subjected to dilation and erosion operations in sequence, including: dilating the binarized image using a 3×3 rectangular structuring element to obtain a dilated image, and performing an erosion operation on the dilated image using a 3×3 rectangular structuring element to obtain the candidate region image.

[0012] Optionally, in some embodiments of this application, the selection of a candidate ID card outline set includes: traversing the outlines of all connected regions and calculating the area of ​​each outline; filtering the area of ​​each outline according to a preset ID card area range, and retaining the outlines whose area is within the preset ID card area range to form a candidate ID card outline set.

[0013] Optionally, in some embodiments of this application, obtaining the center position of the real ID card region and the angle information of the real ID card region in the original image includes: performing minimum bounding rectangle fitting on each contour in the candidate ID card contour set to obtain the center position, size parameters, and angle information of the corresponding rectangle in the original image; verifying the size parameters to determine whether the length, width, and diagonal length of the corresponding rectangle are within a preset ID card size range; if the length, width, and diagonal length of the corresponding rectangle are within the preset ID card size range, performing internal feature detection on the rectangle, extracting the internal contour features of the rectangle, and determining the region of the rectangle as the real ID card region if the internal contour features meet preset feature conditions, and recording the center position and angle information of the real ID card region in the original image; wherein, the internal contour features include: area features, size features, and fill rate features of the internal contour; the area feature is the pixel area of ​​the region enclosed by the internal contour, or the ratio between the area of ​​the internal contour and the area of ​​the rectangular region; the size feature is the width, height, and aspect ratio obtained after fitting the internal contour with a bounding rectangle; the fill rate feature is the ratio between the pixel area of ​​the internal contour and the area of ​​its bounding rectangle.

[0014] Optionally, in some embodiments of this application, the preset feature conditions specifically include the following: whether the pixel area of ​​the inner contour is greater than or equal to a first preset area threshold and less than or equal to a second preset area threshold, or whether the ratio of the area of ​​the inner contour to the area of ​​the rectangular region is between a first preset ratio value and a second preset ratio value; whether the width obtained after fitting the inner contour with an outer rectangle is between a first width threshold and a second width threshold, whether the height obtained after fitting the inner contour with an outer rectangle is between a first height threshold and a second height threshold, whether the aspect ratio obtained after fitting the inner contour with an outer rectangle is between a first ratio threshold and a second ratio threshold; and whether the ratio of the pixel area of ​​the inner contour to the area of ​​its outer rectangle is between a first fill rate threshold and a second fill rate threshold.

[0015] Optionally, in some embodiments of this application, obtaining the center position of the real ID card area and the angle information of the real ID card area in the original image includes: sorting all contours in the candidate ID card contour set in descending order according to their contour areas to obtain a candidate contour sequence; performing minimum bounding rectangle fitting on each candidate contour in the candidate contour sequence according to the sorting order to obtain the length of the long side, the length of the short side, and the tilt angle of the minimum bounding rectangle, and calculating the aspect ratio feature value, the region fill rate feature value, and the contour compactness feature value of the candidate contour; wherein, the aspect ratio feature value is the ratio between the length of the long side and the length of the short side of the minimum bounding rectangle; the region fill rate feature value is the ratio between the number of foreground pixels in the binarized image corresponding to the candidate contour within its minimum bounding rectangle and the area of ​​the minimum bounding rectangle, and the foreground pixels are pixels in the binarized image whose pixel value is a preset foreground marker value and belong to the connected region of the candidate contour. The contour compactness feature value is the ratio between the area of ​​the candidate contour and the area of ​​the minimum bounding rectangle. The aspect ratio feature value, region fill rate feature value, and contour compactness feature value of each candidate contour are normalized and weighted according to preset weights to obtain a comprehensive score. Candidate contours with comprehensive scores greater than a preset score threshold are identified as initial ID card regions. Edge line detection is performed on the initial ID card regions sequentially according to the comprehensive score values ​​from high to low to obtain the four edge lines of the bounding rectangle of the initial ID card region. The included angles between adjacent edge lines are calculated. If all four included angles are within the preset rectangle angle range, the initial ID card region is identified as the real ID card region. The center position of the real ID card region is determined based on the center point coordinates of the minimum bounding rectangle corresponding to the real ID card region, and the tilt angle of the minimum bounding rectangle is used as the angle information of the real ID card region in the original image.

[0016] Optionally, in some embodiments of this application, obtaining the four edge lines of the circumscribed rectangle of the initial ID card region includes: in the binarized image corresponding to the initial ID card region, for each foreground pixel, using the Sobel operator to calculate its local gradient direction and gradient magnitude, wherein the gradient direction is obtained by pixel difference in the horizontal and vertical directions, and the gradient magnitude is used to represent the edge intensity; clustering foreground pixels whose gradient direction difference is less than a preset angle threshold and are spatially adjacent to each other to form a candidate line segment set; for each candidate line segment, setting weights according to the gradient magnitude of its pixels and the length of the line segment, and using weighted least squares to fit the final line; calculating the boundary fitting score for each final line, wherein the boundary fitting score is a weighted comprehensive value of line coverage and gradient direction consistency, and selecting the four final lines with the highest boundary fitting scores as the edge lines of the circumscribed rectangle of the initial ID card region; wherein, the line coverage is the proportion of the number of sampling points falling on the foreground pixels among the sampling points uniformly selected along the final line to the total number of sampling points, and the gradient direction consistency is the proportion of pixels on the final line whose gradient direction is consistent with the line direction.

[0017] Optionally, in some embodiments of this application, the process of obtaining the corrected ID card image includes: rotating the real ID card area according to the angle information of the real ID card area in the original image, so that the long side of the real ID card area is aligned with the preset reference direction; translating the rotated ID card area according to the center position of the real ID card area, so that the center position of the real ID card area is moved to the preset center position of the original image; and cropping the rotated and translated ID card area to obtain the corrected ID card image.

[0018] Secondly, embodiments of this application provide a scanner, comprising: a scanning module, configured to acquire an original image upon receiving a scanning instruction, and sequentially perform Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization on the original image to obtain a binarized image, wherein the original image is a color or grayscale image acquired by the scanner when the cover is open or closed; a processing module, configured to sequentially perform dilation and erosion operations on the binarized image to obtain a candidate region image; a contour analysis module, configured to perform connected component analysis on the candidate region image, extract the contours of all connected regions, and filter out a set of candidate ID card contours; and an ID card recognition module, configured to determine the real ID card region from the set of candidate ID card contours, acquire the center position of the real ID card region and the angle information of the real ID card region in the original image, and rotate and translate the real ID card region according to the center position and the angle information to center the real ID card region in the original image and align it with a preset reference direction to obtain a corrected ID card image.

[0019] (III) Beneficial Effects

[0020] The ID card copying method of this application acquires an original image upon receiving a scanning instruction, and sequentially performs Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization on the original image. This enhances the edge and contour information of the image, making subsequent binarization image processing more accurate. Sequentially performing dilation and erosion operations on the binarized image yields candidate region images with continuous structure and clear contours, providing reliable input for connected component analysis. By performing connected component analysis on the candidate region images, extracting the contours of all connected regions, and filtering out a candidate ID card contour set, potential ID card regions can be effectively identified. The actual ID card region is determined from the candidate ID card contour set, and its center position and angle information in the original image are obtained, providing accurate basis for subsequent rotation and translation operations. Based on the center position and angle information, the actual ID card region is rotated and translated to center it in the original image and align it with a preset reference direction, resulting in a corrected ID card image. Based on the above technical features, the embodiments of this application can stably and accurately realize the positioning and image correction of the ID card area, improve the reliability of the scanning and copying process, and can also stably and accurately complete the copying operation of the ID card in the open or closed state, thereby improving the accuracy of recognition and copying. Attached Figure Description

[0021] Figure 1 This is a flowchart illustrating an ID card copying method according to an embodiment of this application;

[0022] Figure 2 This is a flowchart illustrating the process of obtaining the center position of the real ID card area and the angle information of the real ID card area in the original image according to one embodiment of this application;

[0023] Figure 3 This is a flowchart illustrating the process of obtaining the center position of the real ID card area and the angle information of the real ID card area in the original image according to another embodiment of this application.

[0024] Figure 4 This is a schematic diagram of the structure of a scanner according to an embodiment of this application. Detailed Implementation

[0025] To better explain and facilitate understanding of this application, the following detailed description of the application is provided in conjunction with the accompanying drawings and specific embodiments.

[0026] In existing technologies, automatic recognition and correction methods for ID card photocopying mainly rely on image preprocessing and multi-step scanning. This approach typically requires users to follow a fixed procedure: first, place the ID card face up on the optical plate; close the cover and scan the first side; then open the cover to flip it over; close the cover again and scan the reverse side; finally, recognize, correct, and merge the scanned images from both sides for printing. While this method can complete photocopying with the cover closed, the process is cumbersome and involves many steps, significantly reducing efficiency, especially in high-frequency scenarios (such as banks). Furthermore, this approach has poor background adaptability, being completely unusable with the cover open, thus limiting its operational capabilities.

[0027] Therefore, the ID card copying method and scanner provided in this application introduce automatic ID card area recognition and feature extraction during the image acquisition stage. This enables accurate acquisition of the center position and angle information of the ID card when the cover is closed, and image centering and alignment are achieved through rotation and translation correction, simplifying the copying operation and ensuring stable copying results. This method not only guarantees accurate correction and merged printing of the front and back images of the ID card, but also offers a relatively efficient and reliable operation process, significantly improving copying efficiency in high-frequency usage scenarios, while avoiding the problem of traditional methods being unusable when the cover is open.

[0028] To better understand the above technical solutions, exemplary embodiments of this application will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this application can be understood more clearly and thoroughly, and that the scope of this application can be fully conveyed to those skilled in the art.

[0029] Figure 1 This is a flowchart illustrating a method for copying an ID card according to an embodiment of this application. Figure 1 As shown, this ID card copying method is applied to a scanner and includes:

[0030] Upon receiving a scanning command, the original image is acquired, and the original image is sequentially processed by Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization to obtain a binarized image. The original image is a color or grayscale image acquired by the scanner when the cover is open or closed.

[0031] The Laplacian sharpening process for the original image includes performing a Laplacian sharpening operation on the original image to obtain a Laplacian sharpened image. The Laplacian sharpened image is obtained by convolving each row of pixel data in the original image using a custom filter kernel, which is {-1, -2, -1, 0, 0, 1, 2, 1}. This operation highlights the abrupt changes in grayscale of the ID card's edges and contours, enhances image detail, and significantly improves the contrast between the ID card and the background, thus providing a reliable foundation for subsequent region extraction. For example, when the scanner is closed, the grayscale difference between the ID card's edges and the white background is usually small. Without sharpening, the edges may be indistinct and misidentified as background. After applying Laplacian sharpening, the edge information is enhanced, and even with slight shadows or reflections in the background, the ID card's contours remain clear, thereby improving the accuracy of edge detection.

[0032] The filter kernel {-1, -2, -1, 0, 0, 1, 2, 1} is symmetrical and set to zero at its center, with values ​​on both sides exhibiting a linear increasing distribution from negative to positive. This design enhances edge information with significant gray-level changes in the image. In ID card images, the edges typically exhibit abrupt gray-level changes, while the background gray-level changes are relatively gradual. The gradient difference between the negative and positive values ​​on both sides of the filter kernel amplifies local gray-level changes, making it sensitive to pixel changes at the ID card edges but less sensitive to flat background areas, thus highlighting the ID card outline and facilitating subsequent outline extraction. Secondly, the zero center position of the filter kernel {-1, -2, -1, 0, 0, 1, 2, 1} ensures that the sharpening operation does not shift the gray-level values ​​in the central region, but instead focuses on detecting and enhancing the gradients of surrounding pixels. This means that when processing ID card images, the edge enhancement effect is significant without introducing overall brightness shifts or background noise, ensuring the reliability of binarization and dilation / erosion operations. Furthermore, compared to standard simple Laplacian operators (such as {-1, 2, -1} or {-1, -1, 2, -1, -1}), this custom filter kernel covers more pixels in the horizontal scanning direction, allowing edge information to be accumulated and amplified in local continuous pixels. This is particularly important for thin or small character edges in ID card images, ensuring that characters and boundaries are fully represented after binarization, reducing breaks or missing parts caused by noise or uneven lighting. In addition, this filter kernel is highly robust to environmental interference. In actual scanning processes, there may be slight shadows, reflections, or uneven lighting. The gradient enhancement characteristic of the filter kernel makes the grayscale difference between the ID card edge and the noisy background more prominent, thereby effectively reducing the impact of background noise on edge detection and ensuring the accuracy of the candidate region image.

[0033] After sharpening, the image is further smoothed using Gaussian smoothing to remove noise while preserving the integrity of the ID card edge information. Subsequently, adaptive Gaussian threshold binarization is used to separate the ID card area from the background, making the ID card outline appear as a continuous and clear region in the binary image, thus creating conditions for subsequent dilation and erosion operations.

[0034] The binarized image is subjected to dilation and erosion operations in sequence to obtain candidate region images. In this embodiment, the dilation operation can connect possible edge breaks in the image and fill small holes, while the erosion operation can remove isolated noise points generated during the binarization process, thereby obtaining a candidate region image with complete and continuous structure.

[0035] In some embodiments of this application, the binarized image is subjected to dilation and erosion operations sequentially, including: dilating the binarized image using a 3×3 rectangular structuring element to obtain a dilated image, and then performing an erosion operation on the dilated image using the same 3×3 rectangular structuring element to obtain the candidate region image. Specifically, using a 3×3 rectangular structuring element ensures the integrity and connectivity of the candidate region image and effectively suppresses noise interference. The dilation operation expands the foreground pixels in the binarized image using structuring elements, connecting edge breaks or tiny holes that may have appeared due to scanning noise, uneven lighting, or binarization errors, thereby forming a candidate region with a continuous structure and complete shape. For example, text, portraits, or borders on an ID card may have breaks or gaps after binarization; the dilation operation can effectively fill these small gaps, ensuring the continuity of the overall outline. Subsequently, the erosion operation is performed on the dilated image, which can remove isolated noise or tiny protrusions around the foreground pixels, while restoring the slightly enlarged area during the dilation process to its original size, making the candidate region outline more regular. By combining dilation and erosion, the connectivity of key information such as edges and text is ensured, while noise interference to subsequent connected component analysis and ID card contour extraction is reduced.

[0036] In this embodiment, a 3×3 rectangular structural element is used. Due to its small size, it can finely process local details such as characters, portraits, and borders in the ID card image. In addition, the coverage area of ​​the 3×3 rectangular structural element is sufficient to connect local breaks or small holes, ensuring the continuity and integrity of the candidate region. Compared with directly using dilation or erosion alone, the dilation-erosion combination can balance the effects of edge enhancement and noise suppression, making the candidate ID card contour extracted by subsequent connected component analysis more accurate.

[0037] Connected component analysis is performed on the candidate region image to extract the contours of all connected regions, and a candidate ID card contour set is selected. Specifically, selecting the candidate ID card contour set includes: traversing the contours of all connected regions and calculating the area of ​​each contour; filtering the area of ​​each contour according to a preset ID card area range, retaining contours whose area falls within the preset ID card area range to form a candidate ID card contour set. During actual scanning, images may contain non-target objects such as noise, text, stamps, or background reflections. These areas may form independent connected regions after binarization and dilation-erosion processing. Therefore, without area filtering, these irrelevant contours may be mistakenly identified as ID card areas, leading to subsequent recognition and correction errors. This embodiment of the application, by presetting the ID card area range, can eliminate contours that are too small or too large, retaining only contours of reasonable size as candidate regions, thereby significantly improving the accuracy of the candidate set. Furthermore, the pixel area occupied by an ID card may vary under different scanners, resolutions, or placement positions, but it usually falls within a reasonable range. By setting upper and lower area thresholds, the system can adapt to scanned images of different sizes and resolutions, avoiding interference from background clutter or small interfering objects, while ensuring that the target ID card outline is not mistakenly excluded. After area filtering, redundant outlines in the candidate set are significantly reduced, and subsequent center point calculation, direction determination, and rotation and translation correction can be performed directly on the actual ID card area, avoiding deviations introduced by misselected outlines and improving the accuracy of recognition and correction.

[0038] The actual ID card region is determined from the candidate ID card contour set, and the center position of the actual ID card region and the angle information of the actual ID card region in the original image are obtained.

[0039] Based on the center position and the angle information, the real ID card area is rotated and translated so that the real ID card area is centered in the original image and aligned with the preset reference direction, thus obtaining the corrected ID card image.

[0040] In this embodiment, Laplacian sharpening combined with Gaussian smoothing and adaptive binarization effectively enhances the edge information of the ID card, significantly improving the accuracy of edge detection and contour extraction. Secondly, dilation and erosion operations ensure the continuity and integrity of the candidate region, reducing noise interference to subsequent recognition. Thirdly, through connected component analysis and geometric filtering, the real ID card region can be accurately extracted, avoiding misidentification caused by background noise or other object interference. Finally, rotation and translation correction ensure that the ID card image is centered and oriented uniformly, providing a reliable input image for subsequent printing or automatic recognition, thereby improving the accuracy, stability, and operational efficiency of the entire copying process.

[0041] Optional, see Figure 2In some embodiments of this application, obtaining the center position of the real ID card area and the angle information of the real ID card area in the original image includes:

[0042] For each contour in the candidate ID card contour set, perform minimum bounding rectangle fitting to obtain the center position, size parameters, and angle information of the corresponding rectangle in the original image;

[0043] The size parameters are verified to determine whether the length, width, and diagonal length of the corresponding rectangle are within the preset ID card size range;

[0044] If the length, width, and diagonal of the corresponding rectangle are within the preset ID card size range, internal feature detection is performed on the rectangle to extract its internal contour features. If the internal contour features meet the preset feature conditions, the region of the rectangle is determined to be the real ID card region, and the center position and angle information of the real ID card region in the original image are recorded.

[0045] The preset feature conditions specifically include the following: whether the pixel area of ​​the inner contour is greater than or equal to the first preset area threshold and less than or equal to the second preset area threshold, or whether the ratio of the inner contour area to the rectangular region area is between the first preset ratio value and the second preset ratio value.

[0046] Whether the width obtained after fitting the inner contour with an outer rectangle is between the first width threshold and the second width threshold, whether the height obtained after fitting the inner contour with an outer rectangle is between the first height threshold and the second height threshold, and whether the aspect ratio obtained after fitting the inner contour with an outer rectangle is between the first proportion threshold and the second proportion threshold.

[0047] Whether the ratio of the pixel area of ​​the inner contour to the area of ​​its outer rectangle is between the first fill rate threshold and the second fill rate threshold.

[0048] The internal contour features include: area features, size features, and fill rate features of the internal contour; the area feature is the pixel area of ​​the region enclosed by the internal contour, or the ratio between the area of ​​the internal contour and the area of ​​the rectangular region; the size feature is the width, height, and aspect ratio obtained after fitting the internal contour with a bounding rectangle; the fill rate feature is the ratio between the pixel area of ​​the internal contour and the area of ​​its bounding rectangle.

[0049] In this embodiment, the center position and rotation angle of the real ID card area are obtained by fitting the minimum bounding rectangle to each contour in the candidate ID card contour set. Specifically, the minimum bounding rectangle of each candidate contour is first calculated to obtain parameters such as the center coordinates, width, height, diagonal length, and rotation angle of the rectangle. For example, under a scanner with a resolution of 300 dpi, the size of a standard ID card is 85.6 mm × 54 mm, corresponding to a pixel value of approximately 1012 × 639 pixels. If the width of the candidate contour rectangle is less than 600 pixels or greater than 1100 pixels, and the height is less than 400 pixels or greater than 700 pixels, the contour will be directly excluded, thereby avoiding misjudging scanner edges, background clutter, or other non-ID card objects as the ID card area. After the size verification is passed, feature detection is further performed on the interior of the rectangle to ensure that the identified rectangle is indeed the real ID card area. The internal contour features include area features, size features, and fill rate features. Taking area features as an example, the area of ​​the inner contour pixels must occupy at least 10% and no more than 50% of the rectangular area. That is, in the aforementioned 1012×639 pixel rectangle, the area of ​​the inner contour should be between approximately 64,600 and 323,400 pixels. This can effectively eliminate noise pixels with too small an area or background interference with too large an area. For size features, after fitting the outer rectangle, the width of the inner contour is usually between 100 and 900 pixels, and the height is between 80 and 600 pixels, with the aspect ratio maintained between 0.8 and 1.2. For example, the outer rectangle of the portrait area on an ID card is approximately 200 pixels wide and 200 pixels high, with an aspect ratio close to 1. This feature can be used to verify the rationality of the internal structure. As for the fill rate feature, the ratio of the inner contour pixel area to the area of ​​its outer rectangle must be between 0.3 and 0.8. For example, if the area of ​​the inner contour is 20,000 pixels and the area of ​​its outer rectangle is 40,000 pixels, the fill rate is 0.5, which meets the preset threshold requirement. Only when the rectangle's dimensions and internal contour features meet preset conditions will it be identified as a genuine ID card area, and its center position and rotation angle will be recorded. This technical feature offers significant advantages. First, by using both size verification and internal feature analysis, interfering contours can be effectively eliminated, ensuring accurate identification of the ID card area. Second, obtaining precise center position and angle information provides a reliable basis for subsequent rotation and translation corrections, enabling the ID card image to be accurately centered and aligned with the reference direction even when the scanned area is slightly tilted. Third, through a comprehensive assessment of area, size, and fill rate, the algorithm exhibits high robustness to different scanning conditions, lighting variations, and background complexity, thus ensuring stable and efficient ID card copying even in high-frequency usage scenarios.

[0050] Optional, such as Figure 3As shown, in some other embodiments of this application, obtaining the center position of the real ID card area and the angle information of the real ID card area in the original image includes:

[0051] All contours in the candidate ID card contour set are sorted in descending order of contour area to obtain a candidate contour sequence. Specifically, contours with larger areas are usually more likely to correspond to the ID card area, while contours with smaller areas are mostly noise or background interference. Therefore, this sorting can effectively reduce the complexity of subsequent calculations and the false positive rate. For example, under a 300dpi scanner, the front and back areas of a standard ID card are approximately 1012×639 pixels. If the area of ​​a candidate contour is significantly less than half of this range, the contour is usually background clutter and will naturally be placed at the end of the sequence after sorting, without interfering with the main recognition process.

[0052] Following the sorting order, each candidate contour in the candidate contour sequence is fitted with a minimum bounding rectangle to obtain the length of the long side, the length of the short side, and the tilt angle of the minimum bounding rectangle. The aspect ratio feature, region fill rate feature, and contour compactness feature of the candidate contour are then calculated. Specifically, the aspect ratio feature is the ratio between the length of the long side and the length of the short side of the minimum bounding rectangle; the region fill rate feature is the ratio between the number of foreground pixels in the binary image corresponding to the candidate contour within its minimum bounding rectangle and the area of ​​the minimum bounding rectangle, where foreground pixels are pixels in the binary image with a preset foreground marker value that belong to the connected region of the candidate contour; and the contour compactness feature is the ratio between the area of ​​the candidate contour and the area of ​​the minimum bounding rectangle.

[0053] For example, when a standard ID card is slightly tilted in an image, its longer side is approximately 1012 pixels and its shorter side is approximately 639 pixels, resulting in an aspect ratio of approximately 1.58. Its region fill rate (the ratio of foreground pixels to the total area of ​​the rectangle) is likely between 0.4 and 0.6, while its contour compactness (the ratio of the actual area of ​​the contour to the area of ​​the rectangle) is close to 0.5. In contrast, the aspect ratio of cluttered or noisy contours may deviate from 1.2 to 1.8, its fill rate may be too low or too high, and its compactness may be below 0.2 or above 0.8. These numerical characteristics allow for a quantitative evaluation of each candidate contour.

[0054] The aspect ratio, region fill rate, and contour compactness features of each candidate contour are normalized and then weighted and summed according to preset weights to obtain a comprehensive score. Candidate contours with comprehensive scores greater than a preset score threshold are identified as initial ID card regions. In this embodiment, to comprehensively consider the importance of each feature, the aspect ratio, region fill rate, and contour compactness are normalized and weighted and summed according to preset weights to obtain a comprehensive score for each contour. For example, the aspect ratio weight can be set to 0.4, the region fill rate weight to 0.3, and the compactness weight to 0.3. If the aspect ratio of a candidate contour is close to the standard value and the region fill rate and compactness are both within a reasonable range, its comprehensive score may reach 0.85 (assuming a score range of 0~1), while the score of a clutter contour may only be 0.3~0.5. Candidate contours with comprehensive scores greater than a preset threshold (e.g., 0.7) are identified as initial ID card regions to ensure that the initially screened contours have high credibility.

[0055] According to the comprehensive score from high to low, the initial ID card area is sequentially subjected to edge line detection to obtain the four edge lines of the bounding rectangle of the initial ID card area, and the included angle between adjacent edge lines is calculated. If all four included angles are within the preset rectangle angle range, the initial ID card area is determined as the real ID card area. For example, only when all four included angles are within the preset rectangle angle range (e.g., 85°~95°) is the candidate contour finally determined as the real ID card area.

[0056] The center position of the real ID card area is determined based on the center point coordinates of the minimum bounding rectangle corresponding to the real ID card area, and the tilt angle of the minimum bounding rectangle is used as the angle information of the real ID card area in the original image.

[0057] Specifically, in this embodiment, obtaining the four edge lines of the bounding rectangle of the initial ID card area includes:

[0058] In the binarized image corresponding to the initial ID card area, for each foreground pixel, the Sobel operator is used to calculate its local gradient direction and gradient magnitude. The gradient direction is obtained by pixel difference in the horizontal and vertical directions, and the gradient magnitude is used to represent the edge intensity. For example, for a 1200×800 pixel scanned ID card image, the grayscale value of the pixel on the left edge of the ID card changes from 0 in the background to about 200 in the ID card. After calculation by the Sobel operator, the gradient magnitude might be 150, and the gradient direction is about 90°, accurately indicating the vertical direction of the edge.

[0059] Foreground pixels whose gradient direction difference is less than a preset angle threshold and are spatially adjacent are clustered to form a set of candidate line segments. For example, if the gradient directions of the pixels at the top edge of an ID card are all between 88° and 92° and the pixel spacing is no more than 3 pixels, these pixels will be clustered into a candidate line segment. This clustering step can integrate continuous edge pixel segments and avoid single isolated pixels or noise interfering with line fitting.

[0060] For each candidate line segment, weights are assigned based on the gradient magnitude of its pixels and the length of the line segment. Weighted least squares is then used to fit the final line. Specifically, candidate lines with higher pixel gradient magnitudes and longer segments have greater weights, thus having a more significant impact on the line fitting process. For example, the left edge of an ID card consists of 300 foreground pixels, each with a gradient magnitude between 100 and 200. After weighted fitting, a line from point (50, 100) to point (50, 900) is obtained, with a fitting error of less than 2 pixels, ensuring edge detection accuracy.

[0061] For each final straight line, a boundary fit score is calculated. This score is a weighted average of line coverage and gradient direction consistency. The four final straight lines with the highest boundary fit scores are selected as the outer rectangle edge lines of the initial ID card region. Line coverage is the proportion of foreground pixels among the uniformly selected sampling points along the final straight line. Gradient direction consistency is the proportion of foreground pixels whose gradient direction matches the line direction. For example, if 50 points are uniformly sampled along the left edge, and 48 points fall into the foreground, the line coverage is 96%. Gradient direction consistency represents the proportion of foreground pixels whose gradient direction matches the line direction. For instance, in the 50 sampling points, 47 pixels have a gradient direction that differs from the line direction by no more than 10°, resulting in a consistency of 94%. After combining coverage and direction consistency, the four highest-scoring straight lines are selected as the outer rectangle edge lines of the initial ID card region, corresponding to the top, bottom, left, and right edges of the ID card.

[0062] Optionally, in the practical application of this application embodiment, the process of obtaining the corrected ID card image includes:

[0063] Based on the angle information of the actual ID card area in the original image, the actual ID card area is rotated to align its long side with the preset reference direction. For example, if the ID card in the original scanned image is slightly tilted, with its long side forming a 7° angle with the horizontal reference direction, the entire ID card area will be rotated by 7° to make its long side completely parallel to the preset horizontal reference direction. This rotation operation can be achieved through affine transformation, which transforms the coordinates of each pixel in the image to ensure that the overall geometry of the ID card is not distorted, while correcting the tilt angle.

[0064] Based on the center position of the actual ID card area, the rotated ID card area is translated to move its center to a preset center position in the original image. For example, if the center coordinates of the rotated ID card area are (620, 450) in the image, and the preset center position of the original image is (600, 400), the horizontal and vertical offsets Δx = -20 and Δy = -50 are calculated, and the entire ID card area is translated by these offsets to align its center with the preset center position. This step ensures that the ID card is centered in the image during cropping or printing, avoiding incomplete cropping or misaligned printing caused by offset.

[0065] The rotated and translated area of ​​the ID card is cropped to obtain the corrected ID card image.

[0066] The cropping area typically uses a preset standard ID card size (e.g., 85.6mm x 54mm, converted to pixel values ​​based on scan resolution) to ensure the cropped image contains complete ID card information without unnecessary background. For example, if the scanned image resolution is 300 dpi, the cropping area corresponds to approximately 1010 x 638 pixels. During cropping, a precise rectangular area is generated based on the rotated and translated center of the ID card, and this area is extracted as the final corrected image.

[0067] The ID card copying method of this application firstly enhances the edge and contour information of the ID card by combining Laplacian sharpening with Gaussian smoothing and adaptive Gaussian threshold binarization. This allows for accurate differentiation between foreground and background in areas with insignificant grayscale differences or interference from reflections and shadows, thereby improving the completeness and accuracy of candidate region generation. Secondly, the combination of dilation and erosion operations balances edge connectivity and noise suppression, ensuring continuous candidate region structure and clear contours, providing reliable input for connected component analysis. Thirdly, by fitting the minimum bounding rectangle of the candidate contour, verifying its size, and detecting internal features, including comprehensive scoring of multi-dimensional features such as area, aspect ratio, and fill rate, background clutter, noise, or non-ID card objects can be effectively removed, ensuring accurate identification of the real ID card area. At the same time, accurate center position and tilt angle information are obtained, providing a reliable basis for subsequent rotation and translation operations. Finally, by rotating to align the long side with the preset reference direction, translating to center the center position, and cropping to obtain a standard-sized image, not only are scanning tilt, offset, and size inconsistencies corrected, but the integrity and standardized position of the ID card content are also ensured. In summary, this method, through layer-by-layer screening and correction, not only significantly improves the accuracy and stability of ID card recognition and copying, but also possesses strong robustness, adapting to different scanning conditions, lighting changes, background complexity, and scanning states with or without the cover open. This enables efficient and automated ID card copying operations, thereby significantly improving operational efficiency and output quality in practical applications.

[0068] On the other hand, see Figure 4 This embodiment also provides a scanner, including:

[0069] The scanning module is used to acquire the original image upon receiving a scanning instruction, and to sequentially perform Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization on the original image to obtain a binarized image. The original image is a color or grayscale image acquired by the scanner when the cover is open or closed.

[0070] The processing module is used to sequentially perform dilation and erosion operations on the binarized image to obtain candidate region images;

[0071] The contour analysis module is used to perform connected component analysis on the candidate region image, extract the contours of all connected regions, and filter out a set of candidate ID card contours.

[0072] The ID card recognition module is used to determine the real ID card region from the candidate ID card outline set, obtain the center position of the real ID card region and the angle information of the real ID card region in the original image, and rotate and translate the real ID card region according to the center position and the angle information so that the real ID card region is centered in the original image and aligned with a preset reference direction to obtain the corrected ID card image.

[0073] The scanner provided in this embodiment, through its modular design, achieves fully automated processing from original image acquisition to the output of corrected ID card images. Specifically, firstly, the scanning module combines Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization to effectively enhance the edge information of the ID card and suppress background noise. This ensures that the ID card outline is clearly distinguishable in color or grayscale images scanned in either an open or closed state. Even under uneven lighting or reflective interference, it can reliably distinguish the foreground from the background, thus providing a solid foundation for subsequent candidate region generation. Secondly, the processing module ensures the continuity and integrity of candidate regions in the binarized image through dilation and erosion operations, filling in edges. The process involves several steps: first, breaking down data and removing isolated noise points to create a well-structured and connected candidate region image, improving the accuracy of contour extraction; second, the contour analysis module, through connected component analysis combined with area, shape, and geometric feature filtering, effectively removes background clutter, noise, and non-ID card objects, accurately generating a set of candidate ID card contours to ensure accurate identification of the real ID card area in complex backgrounds; and third, the ID card recognition module, by acquiring the center position and tilt angle of the real ID card area, performs rotation and translation correction to center the ID card in the image and align it with a preset reference direction, ensuring the geometric integrity and orientation of the cropped ID card image, providing high-quality input for subsequent copying, printing, or automatic recognition. In summary, this scanner solution significantly improves the accuracy, stability, and automation level of ID card copying and processing, while also demonstrating robustness under different scanning conditions, lighting variations, and background complexity, thereby enhancing efficiency and reliability in practical applications.

[0074] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.

[0075] In this application, unless otherwise expressly specified and limited, "above" or "below" the second feature can mean that the first and second features are in direct contact, or that they are in indirect contact through an intermediate medium. Furthermore, "above," "on top of," and "over" the second feature can mean that the first feature is directly above or diagonally above the second feature, or simply that the first feature is at a higher horizontal level than the second feature. "Below," "below," and "under" the second feature can mean that the first feature is directly below or diagonally below the second feature, or simply that the first feature is at a lower horizontal level than the second feature.

[0076] In the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0077] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make modifications, alterations, substitutions and variations to the above embodiments within the scope of this application.

Claims

1. A method for photocopying an ID card, characterized in that, The method is applied to a scanner and includes: Upon receiving a scanning command, the original image is acquired, and the original image is sequentially processed by Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization to obtain a binarized image. The original image is a color or grayscale image acquired by the scanner when the cover is open or closed. The binarized image is subjected to dilation and erosion operations in sequence to obtain candidate region images; Connectivity component analysis is performed on the candidate region image to extract the contours of all connected regions, and a set of candidate ID card contours is selected. The actual ID card region is determined from the candidate ID card contour set, and the center position of the actual ID card region and the angle information of the actual ID card region in the original image are obtained. Based on the center position and the angle information, the real ID card area is rotated and translated so that the real ID card area is centered in the original image and aligned with the preset reference direction, thus obtaining the corrected ID card image.

2. The method for photocopying an ID card according to claim 1, characterized in that, The original image is subjected to Laplacian sharpening, including: The original image is subjected to Laplacian sharpening to obtain a Laplacian sharpened image. The Laplacian sharpened image is obtained by convolving each row of pixel data of the original image using a custom filter kernel, which is {-1, -2, -1, 0, 0, 1, 2, 1}.

3. The method for photocopying an ID card according to claim 2, characterized in that, The binarized image is subjected to dilation and erosion operations sequentially, including: A 3×3 rectangular structuring element is used to dilate the binarized image to obtain the dilated image. Then, an erosion operation is performed on the dilated image using the 3×3 rectangular structuring element to obtain the candidate region image.

4. The method for photocopying an ID card according to any one of claims 1-3, characterized in that, The candidate ID card outline set was filtered out, including: Traverse the contours of all connected regions and calculate the area of ​​each contour; The area of ​​each outline is filtered according to the preset area range of the ID card, and the outlines whose area is within the preset area range of the ID card are retained to form a set of candidate ID card outlines.

5. The method for photocopying an ID card according to claim 4, characterized in that, Obtain the center position of the real ID card area and the angle information of the real ID card area in the original image, including: For each contour in the candidate ID card contour set, perform minimum bounding rectangle fitting to obtain the center position, size parameters, and angle information of the corresponding rectangle in the original image; The size parameters are verified to determine whether the length, width, and diagonal length of the corresponding rectangle are within the preset ID card size range; If the length, width, and diagonal of the corresponding rectangle are within the preset ID card size range, internal feature detection is performed on the rectangle to extract its internal contour features. If the internal contour features meet the preset feature conditions, the region of the rectangle is determined to be the real ID card region, and the center position and angle information of the real ID card region in the original image are recorded. The internal contour features include: area features, size features, and fill rate features of the internal contour; the area feature is the pixel area of ​​the region enclosed by the internal contour, or the ratio between the area of ​​the internal contour and the area of ​​the rectangular region; the size feature is the width, height, and aspect ratio obtained after fitting the internal contour with a bounding rectangle; the fill rate feature is the ratio between the pixel area of ​​the internal contour and the area of ​​its bounding rectangle.

6. The method for photocopying an ID card according to claim 5, characterized in that, The preset feature conditions are specific Includes the following: Whether the pixel area of ​​the inner contour is greater than or equal to the first preset area threshold and less than or equal to the second preset area threshold, or whether the ratio of the inner contour area to the rectangular region area is between the first preset ratio value and the second preset ratio value; Whether the width obtained after fitting the inner contour with an outer rectangle is between the first width threshold and the second width threshold, whether the height obtained after fitting the inner contour with an outer rectangle is between the first height threshold and the second height threshold, and whether the aspect ratio obtained after fitting the inner contour with an outer rectangle is between the first proportion threshold and the second proportion threshold. Whether the ratio of the pixel area of ​​the inner contour to the area of ​​its outer rectangle is between the first fill rate threshold and the second fill rate threshold.

7. The method for photocopying an ID card according to claim 4, characterized in that, Obtain the center position of the real ID card area and the angle information of the real ID card area in the original image, including: All contours in the candidate ID card contour set are sorted in descending order of contour area to obtain a candidate contour sequence. Following the sorting order, each candidate contour in the candidate contour sequence is fitted with a minimum bounding rectangle to obtain the length of the long side, the length of the short side, and the tilt angle of the minimum bounding rectangle. The aspect ratio feature, region fill rate feature, and contour compactness feature of the candidate contour are then calculated. Specifically, the aspect ratio feature is the ratio between the length of the long side and the length of the short side of the minimum bounding rectangle; the region fill rate feature is the ratio between the number of foreground pixels in the binary image corresponding to the candidate contour within its minimum bounding rectangle and the area of ​​the minimum bounding rectangle, where foreground pixels are pixels in the binary image with a preset foreground marker value that belong to the connected region of the candidate contour; and the contour compactness feature is the ratio between the area of ​​the candidate contour and the area of ​​the minimum bounding rectangle. The aspect ratio feature value, region fill rate feature value, and contour compactness feature value of each candidate contour are normalized and then weighted and summed according to preset weights to obtain a comprehensive score value. Candidate contours with a comprehensive score value greater than a preset score threshold are determined as the initial ID card region. According to the comprehensive score from high to low, the initial ID card area is sequentially subjected to edge line detection to obtain the four edge lines of the bounding rectangle of the initial ID card area, and the included angle between adjacent edge lines is calculated. If all four included angles are within the preset rectangle angle range, the initial ID card area is determined as the real ID card area. The center position of the real ID card area is determined based on the center point coordinates of the minimum bounding rectangle corresponding to the real ID card area, and the tilt angle of the minimum bounding rectangle is used as the angle information of the real ID card area in the original image.

8. The method for photocopying an ID card according to claim 7, characterized in that, Obtain the four edge lines of the bounding rectangle of the initial ID card area, including: In the binarized image corresponding to the initial ID card area, for each foreground pixel, the Sobel operator is used to calculate its local gradient direction and gradient magnitude. The gradient direction is obtained by pixel difference in the horizontal and vertical directions, and the gradient magnitude is used to represent the edge intensity. Foreground pixels whose gradient direction difference is less than a preset angle threshold and are spatially adjacent are clustered to form a set of candidate line segments. For each candidate line segment, weights are set according to the gradient magnitude of its pixels and the length of the line segment, and the final line is obtained by fitting using the weighted least squares method. For each final straight line, a boundary fit score is calculated, where the boundary fit score is a weighted comprehensive value of the line coverage and the consistency of the gradient direction. The four final straight lines with the highest boundary fit scores are selected as the outer rectangle edge lines of the initial ID card area. Among them, the line coverage is the proportion of the number of sampling points that fall on the foreground pixels out of the total number of sampling points among the sampling points selected uniformly along the final line, and the gradient direction consistency is the proportion of pixels on the final line whose gradient direction is consistent with the line direction.

9. The method for photocopying an ID card according to claim 6 or 8, characterized in that, The process of obtaining the corrected ID card image includes: Based on the angle information of the real ID card area in the original image, the real ID card area is rotated and transformed so that the long side of the real ID card area is aligned with the preset reference direction. Based on the center position of the real ID card area, the rotated ID card area is translated so that the center position of the real ID card area is moved to the preset center position of the original image. The rotated and translated area of ​​the ID card is cropped to obtain the corrected ID card image.

10. A scanner, characterized in that, include: The scanning module is used to acquire the original image upon receiving a scanning instruction, and to sequentially perform Laplacian sharpening, Gaussian smoothing, and adaptive Gaussian threshold binarization on the original image to obtain a binarized image. The original image is a color or grayscale image acquired by the scanner when the cover is open or closed. The processing module is used to sequentially perform dilation and erosion operations on the binarized image to obtain candidate region images; The contour analysis module is used to perform connected component analysis on the candidate region image, extract the contours of all connected regions, and filter out a set of candidate ID card contours. The ID card recognition module is used to determine the real ID card region from the candidate ID card outline set, obtain the center position of the real ID card region and the angle information of the real ID card region in the original image, and rotate and translate the real ID card region according to the center position and the angle information so that the real ID card region is centered in the original image and aligned with a preset reference direction to obtain the corrected ID card image.