Card detection method and device, storage medium and equipment
By utilizing key point localization models and edge detection technology on mobile devices, combined with line segment merging methods, the problems of slow speed and low accuracy in card and document edge detection are solved, achieving efficient card and document edge detection under limited computing power.
Patent Information
- Application Number
- CN202411137739.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2026-03-03
AI Technical Summary
Mobile card recognition is limited by computing power, resulting in slow detection speed and low efficiency, and the detection accuracy decreases when the card edges are blurred or occluded.
The four corner points of the card are located using a key point localization model. Edge sub-regions are extracted for edge detection, and the card area is obtained by combining the line segment merging method.
It achieves accurate detection of card and document edges, improves detection efficiency, has good robustness to slight occlusion and blurring, reduces computational load, and is suitable for mobile devices with limited computing power.
Smart Images

Figure CN121600281A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing, and in particular to a card detection method, apparatus, storage medium and device. Background Technology
[0002] With the development of computer vision technology, ID cards, social security cards, bank cards, and other certificates are widely used, leading to the emergence and increasingly widespread application of related card and document recognition services. Card and document recognition uses image recognition and other technologies to identify information within the card or document. Card and document detection detects the size and position of the card or document on a given image, and it is a crucial part of card and document recognition, providing the foundation for it.
[0003] Mobile card and document recognition is a widely used application scenario. Mobile card and document recognition requires the deployment of a card and document front-end detection model on the mobile device. However, due to the limitations of computing power on mobile devices, the front-end detection model often runs slowly and has low detection efficiency, which limits the application of mobile card and document recognition.
[0004] In addition, when users perform card and document recognition, the edges of the card or document are often blurred or obscured, such as when the card or document is held in the hand and the finger is covering it. When the edges of the card or document are blurred or obscured, it will reduce the accuracy of card and document detection. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this application provides a card detection method, apparatus, storage medium, and device, which achieves accurate detection of card edges, improves detection efficiency, and exhibits good robustness against slight occlusion and blurring of card edges.
[0006] The technical solution provided in this application is as follows:
[0007] Firstly, this application provides a card detection method, the method comprising:
[0008] The image to be detected is input into a pre-trained key point localization model to obtain the top left, top right, bottom right and bottom left corners of the card.
[0009] Based on the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point, the upper edge sub-region, the right edge sub-region, the lower edge sub-region, and the left edge sub-region of the card are extracted from the image to be detected;
[0010] Edge detection is performed on the upper edge sub-region, the right edge sub-region, the lower edge sub-region, and the left edge sub-region respectively to obtain the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set respectively;
[0011] The line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments are merged respectively to obtain the upper edge, right edge, lower edge, and left edge of the card;
[0012] The card area is obtained based on the upper edge, the right edge, the lower edge, and the left edge.
[0013] Furthermore, the step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point, before further including:
[0014] Based on the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point and their confidence levels, determine whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements;
[0015] If all requirements are met, then the step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point is executed; otherwise, the step of inputting the image to be detected into the pre-trained key point localization model to obtain the upper left corner point, upper right corner point, lower right corner point, and lower left corner point of the card is executed.
[0016] Furthermore, the step of determining whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point and their confidence levels includes:
[0017] Determine whether the top left corner, the top right corner, the bottom right corner, and the bottom left corner are located in the areas of the top left, top right, bottom right, and bottom left, respectively. If so, the orientation of the card meets the requirements.
[0018] Determine the degree of similarity between the quadrilateral formed by connecting the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point in sequence and the standard rectangle. If the degree of similarity reaches a set level, then the perspective transformation angle of the card meets the requirements.
[0019] Determine whether the confidence levels of the top left corner point, top right corner point, bottom right corner point, and bottom left corner point output by the key point localization model reach the set confidence level threshold. If so, the confidence level meets the requirements.
[0020] Furthermore, the step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point includes:
[0021] Based on the upper left corner and the upper right corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated to obtain an upper edge sub-region that includes the upper edge of the card.
[0022] Based on the upper right corner and the lower right corner, the set area is expanded inward and outward respectively. The expanded area is then truncated and rotated by 90 degrees to obtain a right edge sub-region that includes the right edge of the card.
[0023] Based on the lower right corner and the lower left corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated to obtain a lower edge sub-region that includes the lower edge of the card.
[0024] Based on the lower left corner and the upper left corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated and rotated by 90 degrees to obtain a left edge sub-region that includes the left edge of the card.
[0025] Furthermore, the step of merging the line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments to obtain the upper edge, right edge, lower edge, and left edge of the card includes:
[0026] Determine whether two line segments in the set of upper edge line segments / the set of right edge line segments / the set of lower edge line segments / the set of left edge line segments satisfy the first merging condition or the second merging condition. If so, merge the two line segments to obtain a merged line segment.
[0027] After all mergeable line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments have been merged, the merged line segments corresponding to the set of upper edge line segments and the set of lower edge line segments are taken as the upper edge and the lower edge, and the merged line segments corresponding to the set of right edge line segments and the set of left edge line segments are rotated 90 degrees in the opposite direction to take as the right edge and the left edge.
[0028] Wherein, if the included angle between the two line segments is less than the set first angle threshold and the distance between the nearest endpoints of the two line segments is less than the set first distance threshold, then the first merging condition is satisfied.
[0029] If the included angle between the two line segments is less than the set second angle threshold and the distance between the nearest endpoints of the two line segments is less than the set second distance threshold, then the second merging condition is satisfied.
[0030] The first angle threshold is less than the second angle threshold, and the first distance threshold is greater than the second distance threshold.
[0031] Furthermore, the two line segments include a target line segment and a line segment to be merged. The step of determining whether two line segments in the upper edge line segment set / the right edge line segment set / the lower edge line segment set / the left edge line segment set satisfy the first merging condition or the second merging condition, and if so, merging the two line segments to obtain a merged line segment, includes:
[0032] Sort each line segment in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments according to its starting point, and take one of the sorted line segments as the target line segment;
[0033] After sorting the target line segments, the line segments within the set range are taken as the line segments to be merged. Each line segment to be merged is traversed, and it is determined whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition.
[0034] If the first merging condition or the second merging condition is met, the target line segment is merged with the line segment to be merged, and the target line segment is updated to the merged line segment. The process returns to the step of sorting the target line segment and selecting the line segments within the set range as the line segments to be merged, until the merging is completed and the merged line segment is obtained.
[0035] Furthermore, the step of obtaining the card area based on the upper edge, the right edge, the lower edge, and the left edge also includes:
[0036] The upper reference line, right reference line, lower reference line, and left reference line are determined based on the upper left corner point and the upper right corner point, the upper right corner point and the lower right corner point, the lower right corner point and the lower left corner point, and the lower left corner point and the upper left corner point, respectively.
[0037] Determine whether the parallelism between the upper reference line and the upper edge, the parallelism between the right reference line and the right edge, the parallelism between the lower reference line and the lower edge, and the parallelism between the left reference line and the lower edge meet the set parallelism requirements.
[0038] If all the set parallelism requirements are met, then the step of obtaining the card area based on the upper edge, the right edge, the lower edge, and the left edge is executed; otherwise, a new target line segment is selected, and the step of sorting the target line segments and selecting the line segments within the set range as the line segments to be merged is returned.
[0039] Secondly, this application provides a card detection device, the device comprising:
[0040] The key point localization module is used to input the image to be detected into a pre-trained key point localization model to obtain the top left, top right, bottom right, and bottom left corners of the card.
[0041] The sub-region cropping module is used to crop the upper edge sub-region, right edge sub-region, lower edge sub-region and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point and the lower left corner point;
[0042] The edge detection module is used to perform edge detection on the upper edge sub-region, the right edge sub-region, the lower edge sub-region and the left edge sub-region respectively, and obtain the upper edge line segment set, the right edge line segment set, the lower edge line segment set and the left edge line segment set respectively;
[0043] The line segment merging module is used to merge the line segments in the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set respectively to obtain the upper edge, right edge, lower edge, and left edge of the card;
[0044] The card / certificate area acquisition module is used to obtain the card / certificate area based on the upper edge, the right edge, the lower edge, and the left edge.
[0045] Furthermore, the device also includes:
[0046] The judgment module is used to determine whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point and their confidence levels.
[0047] The first selection execution module is used to execute the sub-region capture module if all requirements are met, otherwise the key point positioning module is executed.
[0048] Furthermore, the determination module includes:
[0049] The first judgment unit is used to determine whether the upper left corner, the upper right corner, the lower right corner and the lower left corner are located in the upper left, upper right, lower right and lower left areas respectively. If so, the orientation of the card meets the requirements.
[0050] The second judgment unit is used to judge the degree of similarity between the quadrilateral formed by connecting the upper left corner point, the upper right corner point, the lower right corner point and the lower left corner point in sequence and the standard rectangle. If the degree of similarity reaches a set level, the perspective transformation angle of the card meets the requirements.
[0051] The third judgment unit is used to determine whether the confidence levels of the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point output by the key point localization model reach the set confidence level threshold. If so, the confidence level meets the requirements.
[0052] Furthermore, the sub-region capture module includes:
[0053] The first interception unit is used to expand a set area inward and outward respectively based on the upper left corner point and the upper right corner point, and to intercept the expanded area to obtain an upper edge sub-region including the upper edge of the card;
[0054] The second interception unit is used to expand the set area inward and outward respectively based on the upper right corner point and the lower right corner point, intercept the expanded area and rotate it by 90 degrees to obtain the right edge sub-region including the right edge of the card;
[0055] The third interception unit is used to expand the set area inward and outward respectively based on the lower right corner point and the lower left corner point, and intercept the expanded area to obtain the lower edge sub-region including the lower edge of the card;
[0056] The fourth interception unit is used to expand the set area inward and outward respectively based on the lower left corner point and the upper left corner point, intercept the expanded area and rotate it by 90 degrees to obtain the left edge sub-region including the left edge of the card.
[0057] Furthermore, the line segment merging module includes:
[0058] The merging judgment unit is used to determine whether two line segments in the set of upper edge line segments / the set of right edge line segments / the set of lower edge line segments / the set of left edge line segments meet the first merging condition or the second merging condition. If so, the two line segments are merged to obtain a merged line segment.
[0059] An edge determination unit is used to, after all mergeable line segments in the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set have been merged, take the merged line segments corresponding to the upper edge line segment set and the lower edge line segment set as the upper edge and the lower edge, and rotate the merged line segments corresponding to the right edge line segment set and the left edge line segment set in the opposite direction by 90 degrees to take them as the right edge and the left edge.
[0060] Wherein, if the included angle between the two line segments is less than the set first angle threshold and the distance between the nearest endpoints of the two line segments is less than the set first distance threshold, then the first merging condition is satisfied.
[0061] If the included angle between the two line segments is less than the set second angle threshold and the distance between the nearest endpoints of the two line segments is less than the set second distance threshold, then the second merging condition is satisfied.
[0062] The first angle threshold is less than the second angle threshold, and the first distance threshold is greater than the second distance threshold.
[0063] Furthermore, the two line segments include a target line segment and a line segment to be merged, and the merging determination unit includes:
[0064] The sorting subunit is used to sort the line segments according to the starting point of each line segment in the set of upper edge line segments / the set of right edge line segments / the set of lower edge line segments / the set of left edge line segments, and take one of the sorted line segments as the target line segment.
[0065] The traversal sub-unit is used to take the line segments within a set range after the target line segment is sorted as the line segments to be merged, traverse each line segment to be merged, and determine whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition.
[0066] The merging subunit is used to merge the target line segment with the line segment to be merged if the first merging condition or the second merging condition is met, update the target line segment to the merged line segment, return to the traversal subunit, and continue until the merging is completed to obtain the merged line segment.
[0067] Furthermore, the device also includes:
[0068] The reference line determination module is used to determine the upper reference line, the right reference line, the lower reference line, and the left reference line based on the upper left corner point and the upper right corner point, the upper right corner point and the lower right corner point, the lower right corner point and the lower left corner point, and the lower left corner point and the upper left corner point, respectively.
[0069] The parallelism judgment module is used to determine whether the parallelism between the upper reference line and the upper edge, the parallelism between the right reference line and the right edge, the parallelism between the lower reference line and the lower edge, and the parallelism between the left reference line and the lower edge meet the set parallelism requirements.
[0070] The second selection execution module is used to execute the card area acquisition module if all the set parallelism requirements are met, otherwise select a new target line segment and return to the traversal subunit.
[0071] Thirdly, this application provides a computer-readable storage medium for card detection, including a memory for storing processor-executable instructions, which, when executed by the processor, implement the steps of the card detection method described in the first aspect.
[0072] Fourthly, this application provides a device for card detection, characterized in that it includes at least one processor and a memory storing computer-executable instructions, wherein the processor executes the instructions to implement the steps of the card detection method described in the first aspect.
[0073] This application has the following beneficial effects:
[0074] This application first locates the four corner points of the card to be detected, and then extracts sub-regions of each edge of the card based on the four corner points. Edge detection is then performed on these sub-regions, and the resulting line segments are merged to obtain the four edges of the card. Based on these four edges, the card region is determined. This application dynamically combines keypoint detection at the four corners of the card with edge detection methods, comprehensively utilizing the corner and edge information to obtain the four edges of the card. This results in high accuracy and precise edge detection. Furthermore, the line segment merging method provides good robustness to slight occlusion and blurring of the card edges. When performing edge detection, this application does not perform it on the entire image but utilizes the results of the keypoint localization model to accelerate the edge detection process. Edge detection is only performed on the extracted sub-images including each edge, reducing computational load and achieving good detection efficiency even on mobile devices with limited computing power. Attached Figure Description
[0075] Figure 1 This is a flowchart of the card detection method described in this application;
[0076] Figure 2 Example diagrams showing the top left, top right, bottom right, and bottom left corners of the card;
[0077] Figure 3 Example images showing the top, right, bottom, and left edge sub-regions of the captured card;
[0078] Figure 4 This is an example of a line segment breaking due to slight blurring;
[0079] Figure 5 This is an example diagram showing a break in the edge line segment due to slight occlusion.
[0080] Figure 6 This is a schematic diagram of the card detection device of this application. Detailed Implementation
[0081] To make the technical problems, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0082] This application provides a card detection method, such as... Figure 1 As shown, the method includes:
[0083] S100: Input the image to be detected into the pre-trained key point localization model to obtain the top left, top right, bottom right and bottom left corners of the card.
[0084] The keypoint localization model needs to be trained before use. During training, a series of card image samples are acquired as training data, and the four corner points of the card are marked on the card image samples. After training, for a given image to be detected, the keypoint localization model can output the coordinates of its four corner points.
[0085] For example, taking an ID card as an example, the top left corner of the card refers to the corner closest to the "name". Then, proceeding clockwise, the top right, bottom right, and bottom left corners are represented by numbers 1, 2, 3, and 4 respectively. Figure 2 As shown.
[0086] In some cases, the keypoint localization model outputs the confidence score of each corner point along with the positions of the four corner points, indicating the probability that the position is the corresponding corner point.
[0087] S200: Based on the top left corner, top right corner, bottom right corner, and bottom left corner, extract the top edge sub-region, right edge sub-region, bottom edge sub-region, and left edge sub-region of the card from the image to be detected.
[0088] In one example, according to Figure 2 In the example described, the extracted upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region are respectively as follows: Figure 3 As shown from top to bottom on the right side of the middle. Figure 2 In the image, the rectangular frame (defined by light gray lines) formed by the four corner points (1, 2, 3, 4) is for illustrative purposes and is not actually displayed in the image. Therefore, the light gray lines in the cropped top, right, bottom, and left edge sub-regions do not actually exist. Figure 3 It has been retained for ease of understanding.
[0089] S300: Perform edge detection on the upper edge sub-region, right edge sub-region, lower edge sub-region and left edge sub-region respectively, and obtain the upper edge line segment set, right edge line segment set, lower edge line segment set and left edge line segment set respectively.
[0090] This application does not limit the algorithm used for edge detection; for example, it can be the LSD line detection algorithm or other edge detection algorithms.
[0091] S400: Merge the line segments in the upper edge line segment set, right edge line segment set, lower edge line segment set, and left edge line segment set respectively to obtain the upper edge, right edge, lower edge, and left edge of the card.
[0092] Existing edge detection algorithms are quite sensitive to edge conditions; when the edges of the card are blurred or occluded, errors often occur. Figure 4 and Figure 5 The broken line segment shown leads to inaccurate edge detection. Figure 4 The edges are blurred, and the intervals between line segment breaks are small. Figure 5 The middle edge is slightly obscured, and the line segments are broken at large intervals.
[0093] for Figure 4 and Figure 5 The line segments shown are broken due to slight blurring or slight occlusion of the edge. This application merges the set of line segments of the same edge to obtain the line segments of the upper edge, right edge, lower edge and left edge of the card. It solves the problem of inaccurate edge detection caused by slight blurring or occlusion of the card edge and has good robustness to slight occlusion and blur.
[0094] S500: The card area is obtained based on the top edge, right edge, bottom edge, and left edge.
[0095] For example, the area enclosed by the straight lines containing the top, right, bottom, and left edges can be directly used as the card detection area. Alternatively, the top, right, bottom, and left edges can each be moved outward by a set number of pixels, and the area enclosed by the straight lines containing the moved top, right, bottom, and left edges can be used as the card detection area.
[0096] This application first locates the four corner points of the card to be detected, and then extracts sub-regions of each edge of the card based on the four corner points. Edge detection is then performed on these sub-regions, and the resulting line segments are merged to obtain the four edges of the card. Based on these four edges, the card region is determined. This application dynamically combines keypoint detection at the four corners of the card with edge detection methods, comprehensively utilizing the corner and edge information to obtain the four edges of the card. This results in high accuracy and precise edge detection. Furthermore, the line segment merging method provides good robustness to slight occlusion and blurring of the card edges. When performing edge detection, this application does not perform it on the entire image but utilizes the results of the keypoint localization model to accelerate the edge detection process. Edge detection is only performed on the extracted sub-images including each edge, reducing computational load and achieving good detection efficiency even on mobile devices with limited computing power.
[0097] As an improvement to the embodiments of this application, the preceding step S200 may further include:
[0098] S110: Based on the top left corner, top right corner, bottom right corner, and bottom left corner and their confidence levels, determine whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements.
[0099] Specifically, this step includes:
[0100] 1. Determine whether the top left corner, top right corner, bottom right corner, and bottom left corner are located in the areas of the top left, top right, bottom right, and bottom left, respectively. If so, the orientation of the card meets the requirements.
[0101] In other words, when the four corner points 1, 2, 3, and 4 are located in the designated areas of the upper left, upper right, lower right, and lower left respectively, the card is facing correctly.
[0102] 2. Determine the degree of similarity between the quadrilateral formed by connecting the top left, top right, bottom right, and bottom left corners and the standard rectangle. If the degree of similarity reaches the set level, the perspective transformation angle of the card meets the requirements.
[0103] In other words, when the quadrilateral formed by the four corner points 1, 2, 3, and 4 basically forms a rectangle, the perspective transformation angle of the card is relatively small, which meets the requirements.
[0104] 3. Determine whether the confidence scores of the top left, top right, bottom right, and bottom left corners output by the key point localization model reach the set confidence threshold. If so, the confidence score meets the requirements.
[0105] The confidence threshold can be set according to the key point localization model and actual needs. When the confidence reaches the confidence threshold, it indicates that the confidence of each corner point is high and meets the requirements.
[0106] S120: If all requirements are met, proceed with step S200; otherwise, proceed with step S100 until the result meets the requirements.
[0107] This application uses the corner location conditions (i.e., the aforementioned conditions 1 and 2) and the confidence condition to determine whether the four corner points output by the key point localization model meet the requirements. If they do, the next step is performed.
[0108] In this application, an example of the specific implementation of S200 capturing each sub-region may include the following process:
[0109] S210: Based on the top left and top right corners, expand the set area inward and outward respectively, and truncate the expanded area to obtain the top edge sub-region including the top edge of the card.
[0110] like Figure 3 The top-left corner can be extended upwards to the left, and the top-right corner can be extended downwards to the right. Using these two extended corners as diagonals, a rectangular area is extracted, which is the upper edge sub-region. This extension method is merely an example and should not be considered a limitation of this application. The same applies to subsequent examples of corner point extension methods.
[0111] S220: Based on the upper right corner and lower right corner, expand the set area inward and outward respectively, truncate the expanded area and rotate it by 90 degrees to obtain the right edge sub-region including the right edge of the card.
[0112] like Figure 3 The method described above involves extending the upper right corner to the upper left and extending the lower right corner to the lower right. Using these two extended corners as diagonals, a rectangular area is extracted. Then, it is rotated 90 degrees counterclockwise to obtain the right edge sub-region.
[0113] S230: Based on the lower right corner and the lower left corner, expand the set area inward and outward respectively, and truncate the expanded area to obtain the lower edge sub-region including the lower edge of the card.
[0114] like Figure 3 The lower left corner can be extended to the upper left, and the lower right corner can be extended to the lower right. Using these two extended corners as diagonals, a rectangular area can be extracted, which is the lower edge sub-region.
[0115] S240: Based on the lower left corner and the upper left corner, expand the set area inward and outward respectively, truncate the expanded area and rotate it by 90 degrees to obtain the left edge sub-region including the left edge of the card.
[0116] like Figure 3 The method described above involves expanding the upper left corner to the upper left and the lower left corner to the lower right. Using these two expanded corners as diagonals, a rectangular area is extracted. Then, it is rotated 90 degrees counterclockwise to obtain the left edge sub-region.
[0117] The existing method for merging line segments is as follows: a distance threshold and an angle threshold are set, and all line segments are judged whether to be merged based on these two thresholds. During the judgment, each line segment is checked pairwise to see if it simultaneously meets the distance threshold (the beginning and end of the two line segments must be close enough) and the angle threshold (the two line segments must be almost parallel). If both are met, they are merged into one line segment; otherwise, no processing is performed.
[0118] This line segment merging method cannot simultaneously satisfy both Case 1 and Case 2. Case 1 is when the edge of a near-straight line is slightly obscured or slightly blurred due to lighting. Case 2 is when the edge has a certain degree of curvature.
[0119] In scenario one, slight occlusion or blurring causes line segments along the same edge to break, resulting in segments that are almost parallel but far apart. In scenario two, due to the curvature of the edge, line segments along the same curved edge will appear close together but at a larger angle.
[0120] If a distance threshold and an angle threshold are used simultaneously for both of the above situations, so that broken line segments belonging to the same edge in both situations can be merged, the distance threshold and the angle threshold must be set large enough. This will lead to the situation where line segments that do not belong to the same edge are mistakenly merged.
[0121] To address the aforementioned problems, S400 of this application includes:
[0122] S410: Determine whether two line segments in the set of upper edge line segments / set of right edge line segments / set of lower edge line segments / set of left edge line segments satisfy the first merging condition or the second merging condition. If so, merge the two line segments to obtain the merged line segment.
[0123] Specifically, the first merging condition is met if the included angle between two line segments is less than a set first angle threshold and the distance between the nearest endpoints of the two line segments is less than a set first distance threshold. The included angle between two line segments can be calculated by the difference between the angles between the two line segments and the positive direction of the horizontal axis. The distance between the nearest endpoints of the two line segments is preferably the distance between the end point of the preceding line segment and the starting point of the following line segment.
[0124] If the included angle between two line segments is less than the set second angle threshold and the distance between the nearest endpoints of the two line segments is less than the set second distance threshold, then the second merging condition is met.
[0125] The first angle threshold is less than the second angle threshold, and the first distance threshold is greater than the second distance threshold.
[0126] This application employs a divide-and-conquer strategy, handling Case 1 and Case 2 separately by setting a first merging condition and a second merging condition, along with two sets of distance and angle thresholds. The first merging condition has a larger first distance threshold and a smaller first angle threshold, addressing the issue of missing line segments caused by slight occlusion or blurring of nearly straight edges in Case 1. The second merging condition has a smaller second distance threshold and a larger second angle threshold, addressing the issue of edges with a certain degree of curvature in Case 2.
[0127] This application employs a divide-and-conquer strategy by setting a first merging condition and a second merging condition, which improves the adaptability and stability of edge detection while ensuring accuracy. Practical testing demonstrates that this application achieves significantly better accuracy and adaptability compared to existing methods using only a distance threshold and an angle threshold.
[0128] The aforementioned first angle threshold, first distance threshold, second angle threshold, and second distance threshold are set according to the actual usage scenario, the size of the image to be detected, and interference factors, so as to ensure that line segments that are not on the same edge are not merged.
[0129] Generally, the values of the first angle threshold, the first distance threshold, the second angle threshold, and the second distance threshold are all within a very small range to prevent line segments that are not on the same edge from being merged. For example, the first angle threshold and the second angle threshold should generally not exceed 45°. Preferably, the value range of the first angle threshold can be 0-10°, and the value range of the second angle threshold can be 0-20°.
[0130] The first and second distance thresholds should generally not exceed 1 / n of the width or height of the image to be detected, to prevent line segments that are not on the same edge from being merged. The specific value of 1 / n should be set as needed, for example, 1 / 5.
[0131] Furthermore, the first angle threshold, the first distance threshold, the second angle threshold, and the second distance threshold can also be obtained based on statistical methods or by training a deep learning model, so that their values ensure that line segments that are not on the same edge are not merged. Preferably, the second angle threshold can also be calculated based on the statistical value of the angle between adjacent line segments of the arc edge.
[0132] Specifically, the second distance threshold can be the allowable length of line segment occlusion determined based on the actual situation. For example, ID cards and other documents are prone to finger occlusion, with the finger occlusion typically occupying more than 1 / 7 of the long side and more than 1 / 5 of the short side. Therefore, for the long side case (i.e., the top and bottom edges), the second distance threshold D2 can be taken as width1 / 7, and for the short side case (i.e., the left and right edges), the second distance threshold D2 can be taken as width2 / 5, where width1 and width2 are the side lengths of the long and short sides, respectively.
[0133] Furthermore, before executing S410, each line segment can be formatted. The parameters of each formatted line segment include the start point, end point, angle with the positive horizontal axis, and length. The start and end points can be represented in coordinate form, the length is the distance between the start and end points, and the angle with the positive horizontal axis is the angle between the line connecting the start and end points and the positive horizontal axis. This angle can be represented by the angle value between the connecting line and the positive horizontal axis, or by the slope of the connecting line.
[0134] More specifically, the two line segments involved in the aforementioned merging may include a target line segment and a line segment to be merged; correspondingly, S410 includes:
[0135] S411: Sort each line segment according to its starting point in the set of upper edge line segments / set of right edge line segments / set of lower edge line segments / set of left edge line segments, and take one of the sorted line segments as the target line segment.
[0136] During sorting, the line segments can be sorted according to the x-coordinate or y-coordinate of their starting point. After sorting, target line segments can be selected sequentially according to the sorting order for merging. Initially, the first sorted line segment can be selected as the target line segment. Of course, target line segments can also be selected according to a set strategy, rather than in order; this application does not impose any restrictions on this.
[0137] S412: After sorting the target line segments, take the line segments within the set range as the line segments to be merged, traverse each line segment to be merged, and determine whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition.
[0138] In this step, each time a target line segment is selected, the remaining line segments within the set range after the target line segment is sorted (the set range can be determined according to actual needs) are traversed as the line segments to be merged, and it is determined in turn whether the line segments to be merged and the target line segment meet the first merging condition or the second merging condition.
[0139] S413: If the first or second merging condition is met, merge the target line segment with the line segment to be merged, update the target line segment to the merged line segment, return to S412, and continue to traverse the remaining line segments until all line segments in the line segment set that can be merged have been merged, and the merged line segment is obtained.
[0140] The starting point of the merged line segment is the starting point of the target line segment, and the ending point is the ending point of the merged line segment. The length and angle with the positive horizontal axis of the merged line segment are calculated based on the starting and ending points of the merged line segment. The starting point, ending point, length, and angle with the positive horizontal axis of the target line segment are then updated to the starting point, ending point, length, and angle with the positive horizontal axis of the merged line segment.
[0141] S420: After all mergeable line segments in the upper edge line segment set / right edge line segment set / lower edge line segment set / left edge line segment set have been merged, the merged line segments corresponding to the upper edge line segment set and the lower edge line segment set are taken as the upper edge and the lower edge, and the merged line segments corresponding to the right edge line segment set and the left edge line segment set are rotated 90 degrees in the opposite direction to take as the right edge and the left edge.
[0142] As an improvement, after all mergeable line segments are merged, shorter lines can be discarded. This is achieved by setting a length threshold, which removes merged line segments shorter than the threshold. The length threshold can be set to width1-D2 or (for the top and bottom edges) width2-D2 (for the left and right edges).
[0143] As mentioned above, this application can achieve edge detection even for slight occlusion and blurring of the card / certificate edges, thus enabling card / certificate detection, and exhibits good robustness to slight occlusion and blurring. However, when the card / certificate edges are severely occluded, it may obscure the information within the card / certificate, meaning that such occlusion is unacceptable (e.g., Figure 2 This is because the lower finger partially obscures the ID number information. When the card or document is severely blurry, the information within it may be unclear. In cases of severe edge occlusion or blurriness, even if the card's location is determined through card detection, subsequent card recognition will fail to identify the information, resulting in recognition failure.
[0144] To address the aforementioned issues, this application provides a step for determining whether a card or document has severe edge occlusion or blurriness. This step is located after S400 and before S500, and specifically includes:
[0145] S430: Determine the upper reference line, right reference line, lower reference line, and left reference line based on the upper left and upper right corner points, the upper right and lower right corner points, the lower right and lower left corner points, and the lower left and upper left corner points, respectively.
[0146] S440: Determine whether the parallelism between the upper reference line and the upper edge, the right reference line and the right edge, the lower reference line and the lower edge, and the left reference line and the lower edge meet the set parallelism requirements.
[0147] During this step, the edges obtained by S400 need to be mapped onto the image to be detected and compared with the reference lines on the image to be detected.
[0148] S450: If all the set parallelism requirements are met, proceed with step S500; otherwise, select a new target line segment and return to step S412 to merge the line segments again.
[0149] In this application, meeting the set parallelism requirement means a high degree of parallelism, where the two straight lines are almost parallel. When the card has slight edge occlusion or blurriness, the edge detection line segments are more accurate, and the distance between the broken line segments is shorter. Therefore, the accuracy of the merged line segments is higher, and the deviation from the true edge is smaller, meaning the parallelism with the straight line determined by the corresponding corner point is better. When the card has severe edge occlusion or blurriness, this defect is intolerable. The accuracy of the edge detection line segments is lower, and the distance between the broken line segments is longer. Therefore, the accuracy of the merged line segments is lower, and the deviation from the true edge is larger, meaning the parallelism with the straight line determined by the corresponding corner point is poor.
[0150] Therefore, this application determines whether the card has serious edge occlusion or blur by comparing the parallelism of each edge obtained after merging with the reference line determined by the corresponding corner point. When the parallelism is poor, it is determined that there is serious edge occlusion or blur. At this time, a new target line segment is selected and the line segment is merged again until an edge that meets the parallelism requirement is obtained.
[0151] If edges that meet the parallelism requirements cannot be merged, it means that the image to be detected is too blurry or has intolerable occlusion. No card detection result will be output to ensure that the image for subsequent card recognition is only slightly blurry and occluded and can be recognized.
[0152] As can be seen, this application achieves accurate card and document detection, has good robustness to slight occlusion and blur, and can ensure that the degree of blur and occlusion of the detected card and document images is within an acceptable range, without any intolerable occlusion, thus laying the foundation for the extraction of key information for card and document recognition.
[0153] This application also provides a card detection device, such as... Figure 6 The device includes:
[0154] The key point localization module 100 is used to input the image to be detected into a pre-trained key point localization model to obtain the upper left corner, upper right corner, lower right corner and lower left corner of the card.
[0155] The sub-region cropping module 200 is used to crop the upper edge sub-region, right edge sub-region, lower edge sub-region and left edge sub-region of the card from the image to be detected based on the upper left corner, upper right corner, lower right corner and lower left corner.
[0156] The edge detection module 300 is used to perform edge detection on the upper edge sub-region, the right edge sub-region, the lower edge sub-region and the left edge sub-region respectively, and obtain the upper edge line segment set, the right edge line segment set, the lower edge line segment set and the left edge line segment set respectively.
[0157] The line segment merging module 400 is used to merge the line segments in the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set respectively to obtain the upper edge, right edge, lower edge, and left edge of the card.
[0158] The card area acquisition module 500 is used to obtain the card area based on the top edge, right edge, bottom edge and left edge.
[0159] This application first locates the four corner points of the card to be detected, and then extracts sub-regions of each edge of the card based on the four corner points. Edge detection is then performed on these sub-regions, and the resulting line segments are merged to obtain the four edges of the card. Based on these four edges, the card region is determined. This application dynamically combines keypoint detection at the four corners of the card with edge detection methods, comprehensively utilizing the corner and edge information to obtain the four edges of the card. This results in high accuracy and precise edge detection. Furthermore, the line segment merging method provides good robustness to slight occlusion and blurring of the card edges. When performing edge detection, this application does not perform it on the entire image but utilizes the results of the keypoint localization model to accelerate the edge detection process. Edge detection is only performed on the extracted sub-images including each edge, reducing computational load and achieving good detection efficiency even on mobile devices with limited computing power.
[0160] As an improvement to the embodiments of this application, the device further includes:
[0161] The judgment module is used to determine whether the orientation of the card meets the requirements, the perspective transformation angle of the card meets the requirements, and the confidence level meets the requirements based on the top left corner, top right corner, bottom right corner, and bottom left corner and their confidence levels.
[0162] The first selection execution module is used to execute the sub-region capture module if all requirements are met, otherwise the key point positioning module is executed.
[0163] Specifically, the judgment module includes:
[0164] The first judgment unit is used to determine whether the upper left corner, upper right corner, lower right corner and lower left corner are located in the upper left, upper right, lower right and lower left areas respectively. If so, the orientation of the card meets the requirements.
[0165] The second judgment unit is used to judge the degree of similarity between the quadrilateral formed by connecting the top left corner, top right corner, bottom right corner and bottom left corner in sequence and the standard rectangle. If the degree of similarity reaches the set degree, the perspective transformation angle of the card meets the requirements.
[0166] The third judgment unit is used to determine whether the confidence levels of the top left, top right, bottom right, and bottom left corners output by the key point localization model reach the set confidence threshold. If so, the confidence level meets the requirements.
[0167] As an example, the aforementioned sub-region capture module includes:
[0168] The first interception unit is used to expand the set area inward and outward based on the upper left and upper right corner points, respectively, and to intercept the expanded area to obtain the upper edge sub-region including the upper edge of the card.
[0169] The second interception unit is used to expand the set area inward and outward based on the upper right corner and lower right corner respectively, intercept the expanded area and rotate it by 90 degrees to obtain the right edge sub-region including the right edge of the card.
[0170] The third interception unit is used to expand the set area inward and outward based on the lower right corner and the lower left corner respectively, and to intercept the expanded area to obtain the lower edge sub-region including the lower edge of the card.
[0171] The fourth interception unit is used to expand the set area inward and outward based on the lower left corner and upper left corner respectively, intercept the expanded area and rotate it by 90 degrees to obtain the left edge sub-region including the left edge of the card.
[0172] The line segment merging module in this application includes:
[0173] The merging judgment unit is used to determine whether two line segments in the upper edge line segment set / right edge line segment set / lower edge line segment set / left edge line segment set meet the first merging condition or the second merging condition. If so, the two line segments are merged to obtain the merged line segment.
[0174] The edge determination unit is used to determine the upper and lower edges after all mergeable line segments in the upper edge line segment set, right edge line segment set, lower edge line segment set, and left edge line segment set have been merged. The merged line segments corresponding to the upper edge line segment set and the lower edge line segment set are used as the upper edge and the lower edge, and the merged line segments corresponding to the right edge line segment set and the left edge line segment set are rotated 90 degrees in the opposite direction to be used as the right edge and the left edge.
[0175] If the included angle between two line segments is less than a set first angle threshold and the distance between the nearest endpoints of the two line segments is less than a set first distance threshold, then the first merging condition is met.
[0176] If the included angle between two line segments is less than the set second angle threshold and the distance between the nearest endpoints of the two line segments is less than the set second distance threshold, then the second merging condition is met.
[0177] The first angle threshold is less than the second angle threshold, and the first distance threshold is greater than the second distance threshold.
[0178] Furthermore, the two line segments involved in the aforementioned merging include the target line segment and the line segment to be merged; correspondingly, the merging judgment unit includes:
[0179] The sorting sub-unit is used to sort each line segment in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments, and to take one of the sorted line segments as the target line segment.
[0180] The sub-cell traversal is used to sort the target line segments and then select the line segments within a set range as the line segments to be merged. Each line segment to be merged is traversed, and it is determined whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition.
[0181] Merge sub-units. If the first or second merging condition is met, merge the target line segment with the line segment to be merged, update the target line segment to the merged line segment, return to traverse sub-units until the merging is complete, and obtain the merged line segment.
[0182] To determine whether severe blurring and occlusion exist, the apparatus of this application further includes:
[0183] The baseline line determination module is used to determine the upper baseline line, right baseline line, lower baseline line, and left baseline line based on the upper left and upper right corner points, the upper right and lower right corner points, the lower right and lower left corner points, and the lower left and upper left corner points, respectively.
[0184] The parallelism judgment module is used to determine whether the parallelism between the upper reference line and the upper edge, the right reference line and the right edge, the lower reference line and the lower edge, and the left reference line and the lower edge meet the set parallelism requirements.
[0185] The second selection execution module is used to execute the card area acquisition module if all the set parallelism requirements are met; otherwise, a new target line segment is selected and the traversal sub-unit is returned.
[0186] The apparatus provided in the above embodiments corresponds one-to-one with the embodiments of the aforementioned methods in terms of its implementation principle and the resulting technical effects. For the sake of brevity, any parts of the apparatus not mentioned in the embodiments can be referred to the corresponding content in the embodiments of the aforementioned methods. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the modules and units described in this apparatus can all be referred to the corresponding processes in the embodiments of the aforementioned methods, and will not be repeated here.
[0187] The card detection method described in the above embodiments of this application can implement business logic through a computer program and record it on a storage medium. This storage medium can be read and executed by a computer, achieving the effects of the scheme described in the method embodiments of this specification. Therefore, this application also provides a computer-readable storage medium for card detection, including a memory for storing processor-executable instructions. When these instructions are executed by a processor, they implement the steps of the card detection method of the aforementioned embodiments.
[0188] The storage medium may include a physical device for storing information, typically digitizing the information and then storing it using electrical, magnetic, or optical methods. The storage medium may include: devices that store information using electrical energy, such as various types of memory, like RAM and ROM; devices that store information using magnetic energy, such as hard disks, floppy disks, magnetic tapes, magnetic core memory, bubble memory, and USB flash drives; and devices that store information using optical methods, such as CDs or DVDs. Of course, there are other readable storage media, such as quantum memories and graphene memories.
[0189] The storage medium described above may also include other implementation methods according to the description of the method embodiments. The implementation principle and technical effects of this embodiment are the same as those of the foregoing method embodiments. For details, please refer to the description of the relevant method embodiments, which will not be repeated here.
[0190] This application also provides a device for card detection. The device can be a standalone computer, or it can include an actual operating device that uses one or more of the methods or embodiments described in this specification. The card detection device may include at least one processor and a memory storing computer-executable instructions. When the processor executes the instructions, it implements the steps of any one or more of the card detection methods described above.
[0191] The device described above may also include other implementation methods according to the method embodiments. The implementation principle and technical effects of this embodiment are the same as those of the foregoing method embodiments. For details, please refer to the description of the relevant method embodiments, which will not be repeated here.
[0192] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the technical scope disclosed in this application; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application. All should be covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.
Claims
1. A card detection method, characterized in that, The method includes: The image to be detected is input into a pre-trained key point localization model to obtain the top left, top right, bottom right and bottom left corners of the card. Based on the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point, the upper edge sub-region, the right edge sub-region, the lower edge sub-region, and the left edge sub-region of the card are extracted from the image to be detected; Edge detection is performed on the upper edge sub-region, the right edge sub-region, the lower edge sub-region, and the left edge sub-region respectively, to obtain the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set respectively; The line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments are merged respectively to obtain the upper edge, right edge, lower edge, and left edge of the card; The card area is obtained based on the upper edge, the right edge, the lower edge, and the left edge.
2. The card detection method according to claim 1, characterized in that, The step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point, before the step of further including: Based on the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point and their confidence levels, determine whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements; If all requirements are met, then the step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point is executed; otherwise, the step of inputting the image to be detected into the pre-trained key point localization model to obtain the upper left corner point, upper right corner point, lower right corner point, and lower left corner point of the card is executed.
3. The card detection method according to claim 2, characterized in that, The step of determining whether the orientation of the card meets the requirements, whether the perspective transformation angle of the card meets the requirements, and whether the confidence level meets the requirements based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point and their confidence levels includes: Determine whether the top left corner, the top right corner, the bottom right corner, and the bottom left corner are located in the areas of the top left, top right, bottom right, and bottom left, respectively. If so, the orientation of the card meets the requirements. Determine the degree of similarity between the quadrilateral formed by connecting the top left corner point, the top right corner point, the bottom right corner point, and the bottom left corner point in sequence and the standard rectangle. If the degree of similarity reaches a set level, then the perspective transformation angle of the card meets the requirements. Determine whether the confidence levels of the top left corner point, top right corner point, bottom right corner point, and bottom left corner point output by the key point localization model reach the set confidence level threshold. If so, the confidence level meets the requirements.
4. The card detection method according to any one of claims 1-3, characterized in that, The step of extracting the upper edge sub-region, right edge sub-region, lower edge sub-region, and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point, and the lower left corner point includes: Based on the upper left corner and the upper right corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated to obtain an upper edge sub-region that includes the upper edge of the card. Based on the upper right corner and the lower right corner, the set area is expanded inward and outward respectively. The expanded area is then truncated and rotated by 90 degrees to obtain a right edge sub-region that includes the right edge of the card. Based on the lower right corner and the lower left corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated to obtain a lower edge sub-region that includes the lower edge of the card. Based on the lower left corner and the upper left corner, the defined areas are expanded inward and outward respectively. The expanded areas are then truncated and rotated by 90 degrees to obtain a left edge sub-region that includes the left edge of the card.
5. The card detection method according to claim 4, characterized in that, The step of merging the line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments to obtain the upper edge, right edge, lower edge, and left edge of the card includes: Determine whether two line segments in the set of upper edge line segments / the set of right edge line segments / the set of lower edge line segments / the set of left edge line segments satisfy the first merging condition or the second merging condition. If so, merge the two line segments to obtain a merged line segment. After all mergeable line segments in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments have been merged, the merged line segments corresponding to the set of upper edge line segments and the set of lower edge line segments are taken as the upper edge and the lower edge, and the merged line segments corresponding to the set of right edge line segments and the set of left edge line segments are rotated 90 degrees in the opposite direction to take as the right edge and the left edge. Wherein, if the included angle between the two line segments is less than the set first angle threshold and the distance between the nearest endpoints of the two line segments is less than the set first distance threshold, then the first merging condition is satisfied. If the included angle between the two line segments is less than the set second angle threshold and the distance between the nearest endpoints of the two line segments is less than the set second distance threshold, then the second merging condition is satisfied. The first angle threshold is less than the second angle threshold, and the first distance threshold is greater than the second distance threshold.
6. The card detection method according to claim 5, characterized in that, The two line segments include a target line segment and a line segment to be merged. The step of determining whether two line segments in the upper edge line segment set / the right edge line segment set / the lower edge line segment set / the left edge line segment set satisfy the first merging condition or the second merging condition, and if so, merging the two line segments to obtain a merged line segment, includes: Sort each line segment in the set of upper edge line segments, the set of right edge line segments, the set of lower edge line segments, and the set of left edge line segments according to its starting point, and take one of the sorted line segments as the target line segment; After sorting the target line segments, the line segments within the set range are taken as the line segments to be merged. Each line segment to be merged is traversed, and it is determined whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition. If the first merging condition or the second merging condition is met, the target line segment is merged with the line segment to be merged, and the target line segment is updated to the merged line segment. The process returns to the step of sorting the target line segment and selecting the line segments within the set range as the line segments to be merged, until the merging is completed and the merged line segment is obtained.
7. The card detection method according to claim 6, characterized in that, The process of obtaining the card area based on the upper edge, the right edge, the lower edge, and the left edge further includes: The upper reference line, right reference line, lower reference line, and left reference line are determined based on the upper left corner point and the upper right corner point, the upper right corner point and the lower right corner point, the lower right corner point and the lower left corner point, and the lower left corner point and the upper left corner point, respectively. Determine whether the parallelism between the upper reference line and the upper edge, the parallelism between the right reference line and the right edge, the parallelism between the lower reference line and the lower edge, and the parallelism between the left reference line and the lower edge meet the set parallelism requirements. If all the set parallelism requirements are met, then the step of obtaining the card area based on the upper edge, the right edge, the lower edge, and the left edge is executed; otherwise, a new target line segment is selected, and the step of sorting the target line segments and selecting the line segments within the set range as the line segments to be merged is returned.
8. A card detection device, characterized in that, The device includes: The key point localization module is used to input the image to be detected into a pre-trained key point localization model to obtain the top left, top right, bottom right, and bottom left corners of the card. The sub-region cropping module is used to crop the upper edge sub-region, right edge sub-region, lower edge sub-region and left edge sub-region of the card from the image to be detected based on the upper left corner point, the upper right corner point, the lower right corner point and the lower left corner point; The edge detection module is used to perform edge detection on the upper edge sub-region, the right edge sub-region, the lower edge sub-region and the left edge sub-region respectively, and obtain the upper edge line segment set, the right edge line segment set, the lower edge line segment set and the left edge line segment set respectively; The line segment merging module is used to merge the line segments in the upper edge line segment set, the right edge line segment set, the lower edge line segment set, and the left edge line segment set respectively to obtain the upper edge, right edge, lower edge, and left edge of the card; The card / certificate area acquisition module is used to obtain the card / certificate area based on the upper edge, the right edge, the lower edge, and the left edge.
9. A computer-readable storage medium for card and document detection, characterized in that, It includes a memory for storing processor-executable instructions, which, when executed by the processor, implement the steps of the card detection method according to any one of claims 1-7.
10. A device for card and document detection, characterized in that, It includes at least one processor and a memory storing computer-executable instructions, wherein the processor executes the instructions to implement the steps of the card detection method according to any one of claims 1-7.