A method for detecting dashed lines in a document image
By combining image preprocessing and feature enhancement methods with line segment detection algorithms, the accuracy and adaptability issues of dashed line detection in document images are solved, achieving high-precision dashed line detection.
Patent Information
- Application Number
- CN202411857075.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2044-12-17
AI Technical Summary
Existing technologies struggle to accurately detect dashed lines in document images, especially in the presence of noise or dense text, and lack generalization ability and robustness.
Image preprocessing, feature enhancement, and denoising techniques are employed, combined with line segment detection algorithms. By extracting horizontal and vertical features, interfering line segments are removed, and horizontal and vertical line segments are spliced together to finally obtain a set of dashed line segments.
It achieves high-precision detection of dashed lines in document images, adapts to different dashed line styles and complex backgrounds, and improves the accuracy and adaptability of detection.
Smart Images

Figure CN119832560B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of document image processing, and specifically relates to a method for detecting dashed lines in a document image. BACKGROUND
[0002] With the rapid development of information digitization, the processing and analysis of document images have become increasingly important. Among the numerous document formats, dashed lines, as a common visual element, are widely used in tables, charts, and various documents to separate, label, or indicate relationships. However, in the image processing process, due to factors such as noise in the document image, background complexity (such as overlapping text, background interference, etc.), and different dashed line styles (such as line segment length, spacing, etc.), the recognition and extraction of dashed lines face great challenges.
[0003] Existing patent documents such as "A straight line segment detection method and system based on a predictive correction mechanism" (publication number: CN117994222A) use edge detection technology to detect straight line segments through multi-scale adaptive Canny edge detection, least squares fitting, and directional routing correction. However, when there is a large amount of noise or dense text in the image, this method cannot accurately detect the dashed lines in the image. For example, the patent document "A lightweight image line segment extraction and description method based on deep learning" (publication number: CN115690444A) constructs an end-to-end line segment detection model that can directly infer the start and end coordinates of all line segments in the image. However, the model's generalization ability is not strong, and its universality and accuracy are difficult to guarantee.
[0004] Therefore, it is particularly important to develop a new method that can accurately detect document image dashed lines while considering adaptability and robustness. The present patent technology arises in this context, aiming to achieve efficient and accurate detection of document image dashed lines through innovative image processing algorithms and strategies. SUMMARY
[0005] To solve the above technical problems, the present application proposes a method for detecting dashed lines in a document image, which can extract dashed line feature maps from a document image and accurately detect straight line segments therein.
[0006] The method for detecting dashed lines in a document image proposed by the present application mainly includes the following steps:
[0007] Step S1: Document image preprocessing; reading the document image I, performing image grayscale and image binarization on the document image I to obtain a binarized image I b ;
[0008] Step S2: Dashed line feature extraction; extracting the dashed line feature map from the binarized image I bLateral feature enhancement and denoising are performed to obtain the feature map I of the horizontal dashed line segment. h For binarized image I b Vertical feature enhancement and denoising are performed to obtain the vertical dashed line segment feature map I. v ;
[0009] Step S3; Line segment detection; Detect the feature map I of the horizontal dashed line segment. h Perform horizontal line detection. If a horizontal line segment is detected, store the detected horizontal line segment in the first horizontal line segment set Lh1. Then, analyze the feature map I of the vertical dashed line segment. v Vertical line detection is performed. If a vertical line segment is detected, it is stored in the first vertical line segment set Lv1. Interfering horizontal line segments in the first horizontal line segment set Lh1 are removed to obtain the second horizontal line segment set Lh2. Interfering vertical line segments in the first vertical line segment set Lv1 are also removed to obtain the second vertical line segment set Lv2. Adjacent horizontal line segments in the second horizontal line segment set Lh2 are concatenated to obtain the third horizontal line segment set Lh3. Adjacent vertical line segments in the second vertical line segment set Lv2 are also concatenated to obtain the third vertical line segment set Lv3. The third horizontal line segment set Lh3 and the third vertical line segment set Lv3 are merged to obtain the dashed line segment set Ld of document image I.
[0010] Further, in step S2, the binarized image I... b Lateral feature enhancement and denoising are performed to obtain the feature map I of the horizontal dashed line segment. h The specific steps are as follows:
[0011] Step S211: Set the lateral dilation threshold Tdh, set the longitudinal dilation threshold Tdv, set the lateral morphological opening operation threshold Toh, set the longitudinal morphological opening operation threshold Tov, and let wi b Represents the binarized image I b The width of hi b Represents the binarized image I b The height; generate a horizontal feature enhancement structuring element Ka with a height of 1 and a width of the horizontal expansion threshold Tdh, and a rectangular shape; generate a horizontal feature enhancement structuring element Ka with a height of 1 and a width of Toh×wi. b And it has a rectangular lateral denoising structure element K b ;
[0012] Step S212, enhance the structuring element K using lateral features. a For binarized image I b Perform dilation to obtain the lateral feature-enhanced image I. c Using the lateral denoising structuring element K b Image I with lateral feature enhancement c Perform an opening operation to obtain the feature map I of the horizontal dashed line segment. h .
[0013] Further, in step S2, the binarized image I b is subjected to vertical feature enhancement and denoising to obtain a vertical dashed line segment feature image I v , and the specific steps are as follows:
[0014] In step S221, a vertical feature enhancement structural element K c with a height of a vertical dilation threshold Tdv, a width of 1, and a rectangular shape is generated. b In step S222, a vertical denoising structural element K d with a height of Tovxhi c , a width of 1, and a rectangular shape is generated.
[0015] In step S222, the binarized image I b is subjected to dilation operation using the vertical feature enhancement structural element K d to obtain a vertical feature enhancement image I d , and the vertical feature enhancement image I d is subjected to opening operation using the vertical denoising structural element K v to obtain the vertical dashed line segment feature image I f .
[0016] Further, in step S3, the interference horizontal line segments in the first horizontal line segment set Lh1 are removed to obtain a second horizontal line segment set Lh2, and the specific steps are as follows:
[0017] In step S3101, a vertical expansion threshold Tev, a first trough span threshold Ts1, and a first tolerance threshold Tt1 are set, and lh d represents the fth horizontal line segment in the first horizontal line segment set Lh1, f = 1, 2, …, nf, and nf is the number of horizontal line segments in the first horizontal line segment set Lh1; a first variable d and a second variable e are set, and the initial value of the first variable d is set to 1.
[0018] In step S3102, the x-coordinate x d left of the left endpoint of the dth horizontal line segment lh d in the first horizontal line segment set Lh1 is obtained. d left The y-coordinate y d of the left endpoint of the dth horizontal line segment lh d in the first horizontal line segment set Lh1 is obtained. right The x-coordinate x d of the right endpoint of the dth horizontal line segment lh d in the first horizontal line segment set Lh1 is obtained. rightCalculate the d-th horizontal line segment lh in the first set of horizontal line segments Lh1. d The average y-coordinate d The calculation formula is shown in formula (1):
[0019]
[0020] Step S3103: Set the first rectangular clipping region Ar1, and initialize the coordinates of the upper left endpoint of the first rectangular clipping region Ar1 as (x... d left ,y d -Tev), initialize the lower right endpoint coordinates of the first rectangular clipping region Ar1 as (x d right ,y d +Tev); Binarize the image I b Cropping according to the first rectangular cropping region Ar1 yields the binarized image I of the horizontal line segment. lh (d) ;
[0021] Step S3104, binarize the horizontal line segment image I lh (d) Perform a horizontal projection to obtain the horizontal projection vector HP. (d) , let hp (d) h Represents the horizontal projection vector HP (d) The h-th element in the array, where h = 1, 2, ..., hi lh (d) hi lh (d) Binarized image of horizontal line segment I lh (d) Height, horizontal projection vector HP (d) The h-th element hp (d) h Represents the binarized image of the horizontal line segment I lh (d) The number of foreground points in the h-th row, where the foreground point is a pixel with a pixel value of 255;
[0022] Step S3105, calculate the horizontal projection vector HP (d) The maximum projection value hp (d) max The calculation formula is shown in formula (2):
[0023]
[0024] Step S3106, let hcr min Let hcr represent the minimum rate of change of the current horizontal projection. Initialize the minimum rate of change of the current horizontal projection. minfor hp (d) max xt1;
[0025] Step S3107, set upper side valley flag tf up and lower side valley flag tf down , initialize the value of upper side valley flag tf up to 0, initialize the value of lower side valley flag tf down to 0; set horizontal projection valley span hts, initialize the value of horizontal projection valley span hts to 0;
[0026] Step S3108, set the value of second variable e to 1;
[0027] Step S3109, if hp (d) max < hp (d) e < hcr min , set the value of horizontal projection valley span hts to 0, otherwise, increase the value of horizontal projection valley span hts by 1;
[0028] Step S3110, if hts≥Ts1, set the value of upper side valley flag tf up to 1, jump to step S3112;
[0029] Step S3111, increase the value of second variable e by 1, if e≤Tev, jump to step S3109;
[0030] Step S3112, set the value of horizontal projection valley span hts to 0, set the value of second variable e to Tev+1;
[0031] Step S3113, if hp (d) max < hp (d) e < hcr min , set the value of horizontal projection valley span hts to 0, otherwise, increase the value of horizontal projection valley span hts by 1;
[0032] Step S3114, if hts≥Ts1, set the value of lower side valley flag tf down to 1, jump to step S3116;
[0033] Step S3115, increase the value of second variable e by 1, if e≤hi lh (d) , jump to step S3113;
[0034] Step S3116, if tf up= 1, tf down = 1, then the dth horizontal line segment lh d is added into the second horizontal line segment set Lh2.
[0035] Step S3117, the value of the first variable d is increased by 1, and if d≤nf, then jump to step S3102.
[0036] Further, in step S3, the interference vertical line segments in the first vertical line segment set Lv1 are removed to obtain the second vertical line segment set Lv2, and the specific steps are as follows:
[0037] Step S3201, set the horizontal expansion threshold Teh, set the second trough span threshold Ts2, set the second fault tolerance threshold Tt2, and let lv g denote the gth vertical line segment in the first vertical line segment set Lv1, g = 1, 2, …, ng, ng is the number of vertical line segments in the first vertical line segment set Lv1; set the third variable t and the fourth variable v, and the initial value of the third variable t is set to 1;
[0038] Step S3202, get the x-coordinate x t of the upper end point of the tth vertical line segment lv t in the first vertical line segment set Lv1. up Step S3203, get the y-coordinate y t of the upper end point of the tth vertical line segment lv t in the first vertical line segment set Lv1. up Step S3204, get the x-coordinate x t of the lower end point of the tth vertical line segment lv t in the first vertical line segment set Lv1. down Step S3205, get the y-coordinate y t of the lower end point of the tth vertical line segment lv t in the first vertical line segment set Lv1. down Step S3206, calculate the average x-coordinate x t of the tth vertical line segment lv t in the first vertical line segment set Lv1, and the calculation formula is as shown in formula (3):
[0039]
[0040] Step S3203, set the second rectangular clipping region Ar2, and initialize the upper left end point coordinates of the second rectangular clipping region Ar2 as (x t -Teh, y t up ), and initialize the right lower end point coordinates of the second rectangular clipping region Ar2 as (x t -Teh, y t down) ; binarizing the image I b cropping according to the second rectangular clipping region Ar2, to obtain a vertical line segment binarization image I lv (t) ;
[0041] In step S3204, vertical projection is performed on the vertical line segment binarization image I lv (t) to obtain a vertical projection vector VP (t) , where vp (t) w represents the wth element in the vertical projection vector VP (t) , where w = 1, 2, …, wi lv (t) , wi lv (t) is the width of the vertical line segment binarization image I lv (t) , and vp (t) (t) w represents the number of foreground points in the wth column of the vertical line segment binarization image I lv (t) , where a foreground point is a pixel point with a pixel value of 255;
[0042] In step S3205, the maximum projection value vp (t) in the vertical projection vector VP (t) max is calculated, and the calculation formula is shown in formula (4):
[0043]
[0044] In step S3206, vcr min represents the minimum change rate of the current vertical projection, and the minimum change rate vcr min of the current vertical projection is initialized as vp (t) max × Tt2.
[0045] In step S3207, a left side trough flag tf left and a right side trough flag tf right are set, the value of the left side trough flag tf left is initialized as 0, the value of the right side trough flag tf right is initialized as 0, and a vertical projection trough span vts is set, and the value of the vertical projection trough span vts is initialized as 0.
[0046] In step S3208, the value of the fourth variable v is set as 1.
[0047] In step S3209, if vp(t) max -vp (t) v <vcr min , the value of the vertical projection valley span vts is set to 0, otherwise, the value of the vertical projection valley span vts is increased by 1;
[0048] Step S3210, if vts≥Ts2, the value of the left valley flag tf left is set to 1, and jump to step S3212;
[0049] Step S3211, the value of the fourth variable v is increased by 1, and if v≤Teh, jump to step S3209;
[0050] Step S3212, the value of the vertical projection valley span vts is set to 0, and the value of the fourth variable v is set to Teh+1;
[0051] Step S3213, if vp (t) max -vp (t) v <vcr min , the value of the vertical projection valley span vts is set to 0, otherwise, the value of the vertical projection valley span vts is increased by 1;
[0052] Step S3214, if vts≥Ts2, the value of the right valley flag tf right is set to 1, and jump to step S3216;
[0053] Step S3215, the value of the fourth variable v is increased by 1, and if v≤wi lv (t) , jump to step S3213;
[0054] Step S3216, if tf left =1, tf right =1, the t-th vertical line segment lv t in the first vertical line segment set Lv1 is added to the second vertical line segment set Lv2;
[0055] Step S3217, the value of the third variable t is increased by 1, and if t≤ng, jump to step S3202.
[0056] Further, in step S3, adjacent horizontal line segments in the second horizontal line segment set Lh2 are spliced to obtain a third horizontal line segment set Lh3, and the specific steps are as follows:
[0057] Step S3301, according to the y coordinate of the left end point of the horizontal line segment, all horizontal line segments in the second horizontal line segment set Lh2 are sorted in ascending order;
[0058] Step S3302, set the first distance threshold Td1, set the second distance threshold Td2, let lh i represents the i-th horizontal line segment of the second horizontal line segment set Lh2, i = 1, 2, …, ni, ni is the number of horizontal line segments in the second horizontal line segment set Lh2; define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th splicing mark variable fh i represents the splicing mark of the i-th horizontal line segment in the second horizontal line segment set, the splicing mark fh i The initial value is 0; set the fifth variable k and the sixth variable j; the initial value of the fifth variable k is 0;
[0059] Step S3303: increase the value of the fifth variable k by 1, if k> ni-1, jump to step S3311;
[0060] Step S3304, if fh k = 1, jump to step S3303, otherwise, set the value of the sixth variable j to the fifth variable k;
[0061] Step S3305, increase the value of the sixth variable j by 1, if j> ni, jump to step S3303;
[0062] Step S3306, if fh j = 1, jump to step S3305;
[0063] Step S3307, if x k right < x j left < x k right x j left x k j , if x j right < x k left , where x j right ’ represents the x - coordinate of the right - endpoint of the j - th horizontal line segment in the second set of horizontal line segments Lh2, x k left ’ represents the x - coordinate of the left - endpoint of the k - th horizontal line segment in the second set of horizontal line segments Lh2, then it is determined that the j - th horizontal line segment lh j ’ in the second set of horizontal line segments is located at the left of the k - th horizontal line segment lh k ’ in the second set of horizontal line segments Lh2;
[0064] Step S3308, if the k - th horizontal line segment lh k ’ in the second set of horizontal line segments Lh2 is located at the left of the j - th horizontal line segment lh j ’ in the second set of horizontal line segments, |x[[ID=k,2 , the jth horizontal line segment lh j ' in the second horizontal line segment set to the horizontal splice line segment lc k,j , the vertical distance dh j,3 of the jth horizontal line segment lh j ' in the second horizontal line segment set to the horizontal splice line segment lc k,j , the vertical distance dh j,4 ;
[0066] Step S3310, if dh k,1 <Td2, dh k,2 <Td2, dh j,3 <Td2, dh j,4 <Td2, the splice mark fh k of the kth horizontal line segment in the second horizontal line segment set and the splice mark fh j of the jth horizontal line segment in the second horizontal line segment set are both set to 1, and the horizontal splice line segment lc k,j is added to the third horizontal line segment set Lh3; jump to step S3303;
[0067] Step S3311, traverse each splice mark in the horizontal line segment splice mark set Fh, if the ith variable fh i in the horizontal line segment splice mark set Fh is 0, then the ith horizontal line segment lh i ' in the second horizontal line segment set Lh2 is added to the third horizontal line segment set Lh3.
[0068] Further, in step S3, adjacent vertical line segments in the second vertical line segment set Lv2 are spliced to obtain the third vertical line segment set Lv3, and the specific steps are as follows:
[0069] Step S3401, according to the x coordinates of the upper endpoints of the vertical line segments, each vertical line segment in the second vertical line segment set Lv2 is sorted in ascending order;
[0070] Step S3402, let lv j ' represent the jth vertical line segment in the second vertical line segment set Lv2, j = 1, 2, …, nj, nj is the number of vertical line segments in the second vertical line segment set Lv2; define a vertical line segment splice mark set Fv containing o splice mark variables, the jth splice mark variable fv j in the vertical line segment splice mark set Fv represents the splice mark of the jth vertical line segment in the second vertical line segment set, and the splice mark fv j of the jth vertical line segment in the second vertical line segment set is initially set to 0; set the seventh variable u and the eighth variable s; the seventh variable u is initially set to 0;
[0071] Step S3403, the value of the seventh variable u is increased by 1, if u>nj-1, then jump to step S3411;
[0072] Step S3404, if fv u =1, then jump to step S3403, otherwise, the value of the eighth variable s is set to the seventh variable u;
[0073] Step S3405, the value of the eighth variable s is increased by 1, if s>nj, then jump to step S3403;
[0074] Step S3406, if fv j =1, then jump to step S3405;
[0075] Step S3407, if y s down ’<y u up ’,wherein y s down ’ represents the y coordinate of the lower end point of the s-th vertical line segment in the second vertical line segment set Lv2, y u up ’ represents the y coordinate of the upper end point of the u-th vertical line segment in the second vertical line segment set Lv2, it is determined that the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2 is located on the upper side of the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2; if y u down ’<y s up ’,wherein y u down ’ represents the y coordinate of the lower end point of the u-th vertical line segment in the second vertical line segment set Lv2, y s up ’ represents the y coordinate of the upper end point of the s-th vertical line segment in the second vertical line segment set Lv2, it is determined that the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2 is located on the upper side of the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2;
[0076] Step S3408, if the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2 is located on the upper side of the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2, |x u down ’-x s up ’|<Td1, and |y u down’-y s up ’|<Td1, the upper end point of the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2 is connected with the lower end point of the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc u,s ; otherwise, if the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2 is located above the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2, |x s down ’-x u up ’|<Td1 and |y s down ’-y u up ’|<Td1, the upper end point of the s-th vertical line segment lv s ’ in the second vertical line segment set Lv2 is connected with the lower end point of the u-th vertical line segment lv u ’ in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc u,s ; otherwise, jump to step S3405;
[0077] Step S3409, the vertical distance dv u from the upper end point of the u-th vertical line segment lv u,s ’ in the second vertical line segment set Lv2 to the vertical splicing line segment lc u,1 , the vertical distance dv u from the lower end point of the u-th vertical line segment lv u,s ’ in the second vertical line segment set Lv2 to the vertical splicing line segment lc u,2 , the vertical distance dv s from the upper end point of the s-th vertical line segment lv u,s ’ in the second vertical line segment set Lv2 to the vertical splicing line segment lc s,3 , and the vertical distance dv s from the lower end point of the s-th vertical line segment lv u,s ’ in the second vertical line segment set Lv2 to the vertical splicing line segment lc s,4 are calculated.
[0078] Step S3410, if dv u,1 <Td2, dv u,2 <Td2, dv s,3 <Td2, dv s,4 <Td2, the splicing mark fv u of the u-th vertical line segment in the second vertical line segment set and the splicing mark fvs The values of all segments are set to 1, and the vertical splicing segment lc is set to 1. u,s Add the third vertical line segment set Lv3; jump to step S3403;
[0079] Step S3411: Traverse each splicing mark in the set of vertical line segment splicing marks Fv. If the j-th variable fv in the set of vertical line segment splicing marks Fv... j If the value is 0, then the j-th vertical line segment lv in the second vertical line segment set Lv2 will be... j 'Add to the third vertical line segment set Lv3.'
[0080] The beneficial effects of this invention are: This invention provides a method for detecting dashed lines in document images, which effectively utilizes the dashed line features in document images to ensure accurate acquisition of dashed line segments. It is applicable to the extraction and detection of dashed line features in various document images containing dashed line elements, and can achieve high-precision dashed line detection results. Attached Figure Description
[0081] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0082] Figure 1 This is a flowchart of a method according to an embodiment of the present invention;
[0083] Figure 2 This is the original drawing of Embodiment 1 of the present invention;
[0084] Figure 3 This is the binary image obtained in step S2 of embodiment 1 of the present invention;
[0085] Figure 4 This is the feature map of the horizontal dashed line segment obtained in step S2 of embodiment 1 of the present invention;
[0086] Figure 5 This is the feature image of the vertical dashed line segment obtained in step S2 of embodiment 1 of the present invention;
[0087] Figure 6 This is a diagram showing the detection result of the dashed line segment obtained in step S3 of embodiment 1 of the present invention. Detailed Implementation
[0088] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. It should be noted that the specific embodiments of a document image dashed line detection method according to the present invention are merely examples and are not intended to limit the scope of the invention.
[0089] This embodiment uses a document image I with a dashed line (width 857, height 1228) to illustrate the document image dashed line detection method proposed in this invention. Figure 1The method flow chart shows that the present application detects the dotted line in the document image by the following steps:
[0090] Step S1; document image preprocessing; reading the document image I, as shown in the formula (1), performing image graying and image binarization on the document image I to obtain the binarized image I b , as shown in the formula (2). Figure 2 Figure 3
[0091] The image binarization algorithm in the above steps is a common method for image binarization. For details, see Tensmeyer, Chris and Tony R. Martinez. “Historical Document Image Binarization: A Review.” SN Computer Science 1, 2020.
[0092] Step S2; dotted line feature extraction; performing horizontal feature enhancement and denoising on the binarized image I b to obtain the horizontal dotted line segment feature map I h , as shown in the formula (3). Figure 4 b Performing vertical feature enhancement and denoising on the binarized image I v to obtain the vertical dotted line segment feature map I h , as shown in the formula (4). Figure 5
[0093] Step S3; line segment detection; performing horizontal line detection on the horizontal dotted line segment feature map I v , detecting the horizontal line segment, and storing the detected horizontal line segment into the first horizontal line segment set Lh1; performing vertical line detection on the vertical dotted line segment feature map I, detecting the vertical line segment, and storing the detected vertical line segment into the first vertical line segment set Lv1; removing the interfering horizontal line segment in the first horizontal line segment set Lh1 to obtain the second horizontal line segment set Lh2, removing the interfering vertical line segment in the first vertical line segment set Lv1 to obtain the second vertical line segment set Lv2; splicing the adjacent horizontal line segments in the second horizontal line segment set Lh2 to obtain the third horizontal line segment set Lh3, splicing the adjacent vertical line segments in the second vertical line segment set Lv2 to obtain the third vertical line segment set Lv3; merging the third horizontal line segment set Lh3 and the third vertical line segment set Lv3 to obtain the dotted line segment set Ld of the document image I, and the dotted line segment detection result is shown in the formula (5). Figure 6
[0094] The line segment detection algorithm in the above step is a common method for line segment detection in images. For details, see Lin X, Zhou Y, Liu Y, et al. A Comprehensive Review of Image Line Segment Detection and Description: Taxonomies, Comparisons, and Challenges [J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2024;
[0095] Further, in step S2, the binary image I b is subjected to horizontal feature enhancement and denoising to obtain a horizontal dashed line segment feature map I h , and the specific steps are as follows:
[0096] In step S211, the horizontal dilation threshold Tdh is set to 5, the vertical dilation threshold Tdv is set to 5, the horizontal morphological opening operation threshold Toh is set to 0.167, the vertical morphological opening operation threshold Tov is set to 0.034, and wi b represents the width of the binary image I b , hi b represents the height of the binary image I b ; a horizontal feature enhancement structure element Ka with a height of 1, a width of the horizontal dilation threshold Tdh, and a rectangular shape is generated, and a horizontal denoising structure element K b with a height of 1, a width of Toh x wi b , and a rectangular shape is generated.
[0097] In step S212, the binary image I a is dilated using the horizontal feature enhancement structure element K b to obtain a horizontal feature enhancement image I c , and the horizontal feature enhancement image I b is opened using the horizontal denoising structure element K c to obtain a horizontal dashed line segment feature map I h .
[0098] Further, in step S2, the binary image I b is subjected to vertical feature enhancement and denoising to obtain a vertical dashed line segment feature map I v , and the specific steps are as follows:
[0099] In step S221, a vertical feature enhancement structure element K cGenerate a height of Tov×hi b A vertical denoising structuring element K with a width of 1 and a rectangular shape. d ;
[0100] Step S222, enhance the structural element K using vertical features. c For binarized image I b Perform dilation to obtain the vertically enhanced image I. d Using the vertical denoising structuring element K d Image I with enhanced vertical features d Perform an opening operation to obtain the feature map I of the vertical dashed line segment. v .
[0101] Further, in step S3, interfering horizontal line segments in the first set of horizontal line segments Lh1 are removed to obtain the second set of horizontal line segments Lh2. The specific steps are as follows:
[0102] Step S3101: Set the vertical expansion threshold Tev = 5, set the first trough span threshold Ts1 = 3, set the first fault tolerance threshold Tt1 = 0.7, and let lh f Let f represent the f-th horizontal line segment in the first set of horizontal line segments Lh1, where f = 1, 2, ..., nf, and nf is the number of horizontal line segments in the first set of horizontal line segments Lh1; set a first variable d and a second variable e, and set the initial value of the first variable d to 1;
[0103] Step S3102: Obtain the d-th horizontal line segment lh from the first set of horizontal line segments Lh1. d The x-coordinate of the left endpoint d left Get the d-th horizontal line segment lh from the first set of horizontal line segments Lh1. d The y-coordinate of the left endpoint d left Get the d-th horizontal line segment lh from the first set of horizontal line segments Lh1. d x-coordinate of the right endpoint d right Get the d-th horizontal line segment lh from the first set of horizontal line segments Lh1. d The y-coordinate of the right endpoint d right Calculate the d-th horizontal line segment lh in the first set of horizontal line segments Lh1. d The average y-coordinate d The calculation formula is shown in formula (1):
[0104]
[0105] Step S3103: Set the first rectangular clipping region Ar1, and initialize the coordinates of the upper left endpoint of the first rectangular clipping region Ar1 as (x... d left ,y d -Tev), initialize the lower right endpoint coordinates of the first rectangular clipping region Ar1 as (x d right ,y d +Tev); Binarize the image I b Cropping according to the first rectangular cropping region Ar1 yields the binarized image I of the horizontal line segment. lh (d) ;
[0106] Step S3104, binarize the horizontal line segment image I lh (d) Perform a horizontal projection to obtain the horizontal projection vector HP. (d) , let hp (d) h Represents the horizontal projection vector HP (d) The h-th element in the array, where h = 1, 2, ..., hi lh (d) ,hi lh (d) Binarized image of horizontal line segment I lh (d) Height, horizontal projection vector HP (d) The h-th element hp (d) h Represents the binarized image of the horizontal line segment I lh (d) The number of foreground points in the h-th row, where the foreground point is a pixel with a pixel value of 255;
[0107] Step S3105, calculate the horizontal projection vector HP (d) The maximum projection value hp (d) max The calculation formula is shown in formula (2):
[0108]
[0109] Step S3106, let hcr min Let hcr represent the minimum rate of change of the current horizontal projection. Initialize the minimum rate of change of the current horizontal projection. min For HP (d) max ×Tt1;
[0110] Step S3107, set the upper trough marker tf up and the lower trough mark tf down Initialize the upper trough flag tfup The value is 0, initializing the lower trough flag tf. down The value is 0; set the horizontal projection valley span hts, and initialize the value of the horizontal projection valley span hts to 0;
[0111] Step S3108: Set the value of the second variable e to 1;
[0112] Step S3109, if hp (d) max -hp (d) e <hcr min If the value is 0, then set the horizontal projection valley span hts value to 0; otherwise, increase the horizontal projection valley span hts value by 1.
[0113] Step S3110: If hts ≥ Ts1, then set the upper trough marker tf. up Set the value to 1 and jump to step S3112;
[0114] Step S3111: Increment the value of the second variable e by 1. If e ≤ Tev, then jump to step S3109.
[0115] Step S3112: Set the value of the horizontal projection valley span hts to 0, and set the value of the second variable e to Tev+1;
[0116] Step S3113, if hp (d) max -hp (d) e <hcr min If the value is 0, then set the horizontal projection valley span hts value to 0; otherwise, increase the horizontal projection valley span hts value by 1.
[0117] Step S3114: If hts ≥ Ts1, then set the lower trough marker tf. down Set the value to 1 and proceed to step S3116;
[0118] Step S3115: Increment the value of the second variable e by 1 if e ≤ hi lh (d) Then proceed to step S3113;
[0119] Step S3116, if tf up =1,tf down =1, then the d-th horizontal line segment lh in the first horizontal line segment set Lh1 will be... d Add the second horizontal line segment set Lh2;
[0120] Step S3117, the value of the first variable d is increased by 1, if d≤nf, jump to step S3102.
[0121] Further, in step S3, the interference vertical line segments in the first vertical line segment set Lv1 are removed to obtain the second vertical line segment set Lv2, and the specific steps are as follows:
[0122] Step S3201, set the horizontal expansion threshold Teh=5, set the second trough span threshold Ts2=3, set the second fault tolerance threshold Tt2=0.8, and let lv g The gth vertical line segment of the first vertical line segment set Lv1 is represented, g=1, 2,…, ng, ng is the number of vertical line segments in the first vertical line segment set Lv1; set the third variable t and the fourth variable v, the initial value of the third variable t is set to 1;
[0123] Step S3202, get the tth vertical line segment lv t of the first vertical line segment set Lv1; t up , get the y-coordinate y t of the upper end point of the tth vertical line segment lv t of the first vertical line segment set Lv1; up t , get the x-coordinate x t of the lower end point of the tth vertical line segment lv down of the first vertical line segment set Lv1; t t down , calculate the average x-coordinate x t of the tth vertical line segment lv t of the first vertical line segment set Lv1, and the formula is as shown in formula (3):
[0124]
[0125] Step S3203, set the second rectangular clipping region Ar2, initialize the upper left end point coordinates of the second rectangular clipping region Ar2 as (x t -Teh,y t up ), initialize the right lower end point coordinates of the second rectangular clipping region Ar2 as (x t -Teh,y t down ), and clip the binary image I b according to the second rectangular clipping region Ar2 to obtain the vertical line segment binary image I lv (t) ;
[0126] Step S3204, binarizing the vertical line segment image I lv (t) vertical projection to obtain a vertical projection vector VP (t) , let vp (t) w denote the wth element in the vertical projection vector VP (t) , where w = 1, 2, …, wi lv (t) , wi lv (t) denote the width of the vertical line segment binarization image I lv (t) , the wth element vp (t) in the vertical projection vector VP (t) w denote the number of foreground points in the wth column of the vertical line segment binarization image I lv (t) , and the foreground point is a pixel point with a pixel value of 255;
[0127] Step S3205, calculating the maximum projection value vp (t) in the vertical projection vector VP (t) max , and the calculation formula is shown in formula (4):
[0128]
[0129] Step S3206, let vcr min denote the minimum change rate of the current vertical projection, and initialize the minimum change rate vcr min of the current vertical projection as vp (t) max × Tt2;
[0130] Step S3207, setting a left side trough flag tf left and a right side trough flag tf right , initializing the value of the left side trough flag tf left as 0, initializing the value of the right side trough flag tf right as 0, and setting a vertical projection trough span vts, and initializing the value of the vertical projection trough span vts as 0;
[0131] Step S3208, setting the value of the fourth variable v as 1;
[0132] Step S3209, if vp (t) max < vcr (t) v < vcr minIf vts
[0133] Step S3210, if vts left = 1, jump to step S3212;
[0134] Step S3211, increase the value of the fourth variable v by 1, and jump to step S3209 if v
[0135] Step S3212, set the value of the vertical projection valley span vts to 0, and set the value of the fourth variable v to Teh+1;
[0136] Step S3213, if vpr (t) max < vpr (t) v < vcr min , set the value of the vertical projection valley span vts to 0, otherwise, increase the value of the vertical projection valley span vts by 1;
[0137] Step S3214, if vts right = 1, jump to step S3216;
[0138] Step S3215, increase the value of the fourth variable v by 1, and jump to step S3213 if v lv (t) < wi
[0139] Step S3216, if tf left = 1, tf right = 1, add the t-th vertical line segment lv t in the first vertical line segment set Lv1 to the second vertical line segment set Lv2;
[0140] Step S3217, increase the value of the third variable t by 1, and jump to step S3202 if t
[0141] Further, in step S3, adjacent horizontal line segments in the second horizontal line segment set Lh2 are spliced to obtain a third horizontal line segment set Lh3, and the specific steps are as follows:
[0142] Step S3301, sort all horizontal line segments in the second horizontal line segment set Lh2 in ascending order according to the y coordinates of the left endpoints of the horizontal line segments;
[0143] Step S3302, set a first distance threshold Td1 = 5, set a second distance threshold Td2 = 5, and let lhi represents the i-th horizontal line segment of the second horizontal line segment set Lh2, i = 1, 2, …, ni, ni is the number of horizontal line segments in the second horizontal line segment set Lh2; define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th splicing mark variable fh i represents the splicing mark of the i-th horizontal line segment in the second horizontal line segment set, and the splicing mark fh i The initial value is 0; set the fifth variable k and the sixth variable j; the initial value of the fifth variable k is 0;
[0144] Step S3303: increase the value of the fifth variable k by 1, and if k > ni-1, jump to step S3311;
[0145] Step S3304: if fh k = 1, jump to step S3303, otherwise, set the value of the sixth variable j to the fifth variable k;
[0146] Step S3305: increase the value of the sixth variable j by 1, and if j > ni, jump to step S3303;
[0147] Step S3306: if fh j = 1, jump to step S3305;
[0148] Step S3307: if x k right < x j left < x k right represents the x-coordinate of the right end point of the k-th horizontal line segment of the second horizontal line segment set Lh2, x j left represents the x-coordinate of the left end point of the j-th horizontal line segment of the second horizontal line segment set Lh2, then it is determined that the k-th horizontal line segment lh k of the second horizontal line segment set Lh2 is located to the left of the j-th horizontal line segment lh j of the second horizontal line segment set; if x j right < x k left < x j right represents the x-coordinate of the right end point of the j-th horizontal line segment of the second horizontal line segment set Lh2, x k left represents the x-coordinate of the left end point of the k-th horizontal line segment of the second horizontal line segment set Lh2, then it is determined that the j-th horizontal line segment lh j' is to the left of the k-th horizontal line segment lh in the second set of horizontal line segments Lh2 k ';
[0149] Step S3308, if the k-th horizontal line segment lh in the second set of horizontal line segments Lh2 k ' is to the left of the j-th horizontal line segment lh in the second set of horizontal line segments, |x j ' - x k right ' | < Td1, and |y j left ' - y <the right end point of the horizontal line segment lc k,j to the horizontal distance dh j,4 ;
[0151] Step S3310, if dh k,1 <Td2, dh k,2 <Td2, dh j,3 <Td2, dh j,4 <Td2, the splice mark fh k and the splice mark fh j of the jth horizontal line segment in the second horizontal line segment set Lh2 are both set to 1, and the horizontal splice line segment lc k,j is added to the third horizontal line segment set Lh3; jump to step S3303;
[0152] Step S3311, traverse each splice mark in the horizontal line segment splice mark set Fh, if the ith variable fh i in the horizontal line segment splice mark set Fh is 0, then the ith horizontal line segment lh i in the second horizontal line segment set Lh2 is added to the third horizontal line segment set Lh3.
[0153] Further, in step S3, adjacent vertical line segments in the second vertical line segment set Lv2 are spliced to obtain the third vertical line segment set Lv3, and the specific steps are as follows:
[0154] Step S3401, according to the x coordinates of the upper end points of the vertical line segments, each vertical line segment in the second vertical line segment set Lv2 is sorted in ascending order;
[0155] Step S3402, let lv j represent the jth vertical line segment in the second vertical line segment set Lv2, j = 1, 2, …, nj, nj is the number of vertical line segments in the second vertical line segment set Lv2; define a vertical line segment splice mark set Fv containing o splice mark variables, the jth splice mark variable fv j in the vertical line segment splice mark set Fv represents the splice mark of the jth vertical line segment in the second vertical line segment set, and the splice mark fv j of the jth vertical line segment in the second vertical line segment set is initially set to 0; set the seventh variable u and the eighth variable s; the initial value of the seventh variable u is set to 0;
[0156] Step S3403, increase the value of the seventh variable u by 1, if u > nj-1, jump to step S3411;
[0157] Step S3404, if fv uIf it is equal to 1, jump to step S3403; otherwise, set the value of the eighth variable s to the seventh variable u;
[0158] Step S3405, increment the value of the eighth variable s by 1. If s > nj, jump to step S3403;
[0159] Step S3406, if fv j is equal to 1, jump to step S3405;
[0160] Step S3407, if y s down ’ < y u up ’, where y s down ’ represents the y - coordinate of the lower endpoint of the s - th vertical line segment in the second vertical line segment set Lv2, and y u up ’ represents the y - coordinate of the upper endpoint of the u - th vertical line segment in the second vertical line segment set Lv2, then determine that the s - th vertical line segment lv s ’ in the second vertical line segment set Lv2 is above the u - th vertical line segment lv u ’; if y u down ’ < y s up ’, where y u down ’ represents the y - coordinate of the lower endpoint of the u - th vertical line segment in the second vertical line segment set Lv2, and y s up ’ represents the y - coordinate of the upper endpoint of the s - th vertical line segment in the second vertical line segment set Lv2, then determine that the u - th vertical line segment lv u ’ in the second vertical line segment set Lv2 is above the s - th vertical line segment lv s ’;
[0161] Step S3408, if the u - th vertical line segment lv u ’ in the second vertical line segment set Lv2 is above the s - th vertical line segment lv s ’, |x u down ’ - x s up ’| < Td1, and |y u down ’ - y s up ’| < Td1, then the u - th vertical line segment lv uthe upper end point of the s-th vertical line segment lv s is connected with the lower end point of the u-th vertical line segment lv u,s in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc s ; otherwise, if the s-th vertical line segment lv u is located above the u-th vertical line segment lv s in the second vertical line segment set Lv2, |x down u up | < Td1 and |y s down u up | < Td1, the upper end point of the s-th vertical line segment lv s in the second vertical line segment set Lv2 is connected with the lower end point of the u-th vertical line segment lv u in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc u,s ; otherwise, jump to step S3405;
[0162] Step S3409, the vertical distance dv u from the upper end point of the u-th vertical line segment lv u,s in the second vertical line segment set Lv2 to the vertical splicing line segment lc u,1 , the vertical distance dv u from the lower end point of the u-th vertical line segment lv u,s in the second vertical line segment set Lv2 to the vertical splicing line segment lc u,2 , the vertical distance dv s from the upper end point of the s-th vertical line segment lv u,s in the second vertical line segment set Lv2 to the vertical splicing line segment lc s,3 , and the vertical distance dv s from the lower end point of the s-th vertical line segment lv u,s in the second vertical line segment set Lv2 to the vertical splicing line segment lc s,4 are calculated.
[0163] Step S3410, if dv u,1 <Td2, dv u,2 <Td2, dv s,3 <Td2, dv s,4 <Td2, the splicing marks fv u of the u-th vertical line segment in the second vertical line segment set and the splicing marks fv s of the s-th vertical line segment in the second vertical line segment set are both set as 1, and the vertical splicing line segment lc u,s is added to the third vertical line segment set Lv3; jump to step S3403;
[0164] Step S3411, each splicing mark in the vertical line segment splicing mark set Fv is traversed, if the jth variable fv in the vertical line segment splicing mark set Fv is 0, the jth vertical line segment lv in the second vertical line segment set Lv2 is added to the third vertical line segment set Lv3. j j
[0165] The present application has the advantages that the present application provides a document image dotted line detection method, which effectively utilizes the dotted line features in the document image, thereby ensuring accurate acquisition of the dotted line segments, is suitable for dotted line feature extraction and detection of various document images containing dotted line elements, and can realize high-precision dotted line detection effect.
[0166] The above describes the preferred embodiments of the present application, and is not intended to limit the present application, and any equivalent or modification made without departing from the disclosed spirit of the present application shall be included in the scope of protection of the present application.
Claims
1. A method of detecting dashed lines in a document image, characterized by: Mainly includes the following steps: Step S1; document image preprocessing; Read the document image I, the document image I carries on the image gray scale and the image binarization, obtains the binarization image I b ; Step S2; Dotted line feature extraction; to the binarized image I b performing horizontal feature enhancement and de-noising to obtain a horizontal dashed line segment feature map I h to the binarized image I b performing vertical feature enhancement and de-noising to obtain a vertical dashed line segment feature map I v ; Step S3; Line segment detection; for horizontal dashed line segment feature map I h horizontal line detection, if a horizontal line segment is detected, the detected horizontal line segment is stored in a first horizontal line segment set Lh1, for vertical dashed line segment feature map I v vertical line detection, if a vertical line segment is detected, the detected vertical line segment is stored in a first vertical line segment set Lv1; interference horizontal line segments in the first horizontal line segment set Lh1 are removed to obtain a second horizontal line segment set Lh2, interference vertical line segments in the first vertical line segment set Lv1 are removed to obtain a second vertical line segment set Lv2; adjacent horizontal line segments in the second horizontal line segment set Lh2 are spliced to obtain a third horizontal line segment set Lh3, adjacent vertical line segments in the second vertical line segment set Lv2 are spliced to obtain a third vertical line segment set Lv3; the third horizontal line segment set Lh3 and the third vertical line segment set Lv3 are merged to obtain a dashed line segment set Ld of the document image I; In step S2, the binary image I b is subjected to horizontal feature enhancement and denoising to obtain a horizontal dashed line segment feature map I h , and the specific steps are as follows: Step S211, set the lateral expansion threshold Tdh, set the longitudinal expansion threshold Tdv, set the lateral morphological open operation threshold Toh, set the longitudinal morphological open operation threshold Tov, let wi b denote the width of the binarized image I b , let hi b denote the height of the binarized image I b ; generate a lateral feature enhancement structural element Ka with a height of 1, a width of the lateral expansion threshold Tdh, and a rectangular shape, generate a lateral noise removal structural element K b with a height of 1, a width of Toh×wi b , and a rectangular shape; Step S212, using a transverse feature enhancement structure element K a to the binary image I b , an expansion operation is performed to obtain a transverse feature enhancement image I c , using a transverse denoising structure element K b to the transverse feature enhancement image I c , an opening operation is performed to obtain a transverse line segment feature image I h ; In step S2, the binary image I b is subjected to vertical feature enhancement and denoising to obtain a vertical dashed line segment feature image I v , and the specific steps are as follows: Step S221, a longitudinal feature enhancement structure element K with a height of a longitudinal expansion threshold Tdv, a width of 1 and a rectangular shape is generated c Step S222, a longitudinal denoising structure element K with a height of Tovxhi b , a width of 1 and a rectangular shape is generated d ; Step S222, using a vertical feature enhancement structuring element K c to the binary image I b , and performing an expansion operation to obtain a vertical feature enhancement image I d , using a vertical denoising structuring element K d to the vertical feature enhancement image I d , and performing an opening operation to obtain a vertical dashed line segment feature image I v ; In step S3, the interference horizontal line segments in the first horizontal line segment set Lh1 are removed to obtain a second horizontal line segment set Lh2, and the specific steps are as follows: Step S3101, set a longitudinal expansion threshold Tev, set a first trough span threshold Ts1, set a first fault tolerance threshold Tt1, and let lh f representing the fth horizontal line segment of the first horizontal line segment set Lh1, f = 1, 2, …, nf, nf being the number of horizontal line segments in the first horizontal line segment set Lh1; set a first variable d and a second variable e, the initial value of the first variable d being set as 1; Step S3102, obtaining the x coordinate x of the left end point of the dth horizontal line segment lh in the first horizontal line segment set Lh1 d d left obtaining the y coordinate y of the left end point of the dth horizontal line segment lh in the first horizontal line segment set Lh1 d d left obtaining the x coordinate x of the right end point of the dth horizontal line segment lh in the first horizontal line segment set Lh1 d d right obtaining the y coordinate y of the right end point of the dth horizontal line segment lh in the first horizontal line segment set Lh1 d d right calculating the average y coordinate y of the dth horizontal line segment lh in the first horizontal line segment set Lh1 d d The calculation formula is shown in formula (1): (1); Step S3103, set the first rectangular clipping region Ar1, initialize the top-left endpoint coordinates of the first rectangular clipping region Ar1 as (x d left , y d -Tev), initialize the bottom-right endpoint coordinates of the first rectangular clipping region Ar1 as (x d right , y d +Tev); clip the binary image I b according to the first rectangular clipping region Ar1 to obtain the horizontal line segment binary image I lh (d) ; Step S3104, binarizing the horizontal line segment image I lh (d) horizontal projection to obtain a horizontal projection vector HP (d) , let hp (d) h denote the hth element in the horizontal projection vector HP (d) , where h = 1, 2, …, hi lh (d) , hi lh (d) is the height of the horizontal line segment binarization image I lh (d) , the hth element hp (d) in the horizontal projection vector HP (d) h denotes the number of foreground points in the hth row of the horizontal line segment binarization image I lh (d) , and the foreground point is a pixel point with a pixel value of 255. Step S3105, calculating the horizontal projection vector HP (d) in the maximum projection value hp (d) max The calculation formula is shown in formula (2): (2); Step S3106, let hcr min represents the minimum change rate of the current horizontal projection, and the minimum change rate of the current horizontal projection hcr min is hp (d) max × Tt1; Step S3107, set the upper side valley flag tf up and the lower side valley flag tf down , initialize the value of the upper side valley flag tf up to 0, initialize the value of the lower side valley flag tf down to 0; set the horizontal projection valley span hts, initialize the value of the horizontal projection valley span hts to 0; Step S3108, set the value of the second variable e to 1; Step S3109, if hp (d) max -hp (d) e <hcr min the value of the horizontal projection valley span hts is set to 0, otherwise the value of the horizontal projection valley span hts is increased by 1; Step S3110, if hts≥Ts1, the value of the upper side valley flag tf up is set to 1, and the process jumps to step S3112. Step S3111, increase the value of the second variable e by 1, and if e≤Tev, jump to step S3109; Step S3112, set the value of the horizontal projection valley span hts to 0, and set the value of the second variable e to Tev+1; Step S3113, if hp (d) max -hp (d) e <hcr min the value of the horizontal projection valley span hts is set to 0, otherwise the value of the horizontal projection valley span hts is increased by 1; Step S3114, if hts≥Ts1, the value of the lower side valley flag tf down is set to 1, and jump to step S3116; Step S3115, the value of the second variable e is increased by 1, if e < hi lh (d) then jump to step S3113; Step S3116, if tf up = 1, tf down = 1, the dth horizontal line segment lh d in the first horizontal line segment set Lh1 is added to the second horizontal line segment set Lh2; Step S3117, increase the value of the first variable d by 1, and if d≤nf, jump to step S3102.
2. The method of claim 1, wherein: In step S3, the interference vertical line segments in the first vertical line segment set Lv1 are removed to obtain a second vertical line segment set Lv2, and the specific steps are as follows: Step S3201, set a horizontal expansion threshold value Teh, set a second trough span threshold value Ts2, set a second fault tolerance threshold value Tt2, and let lv g denotes the gth vertical line segment of the first vertical line segment set Lv1, g = 1, 2, …, ng, ng is the number of vertical line segments in the first vertical line segment set Lv1; set a third variable t and a fourth variable v, and the initial value of the third variable t is set to 1; Step S3202, obtaining the x-coordinate x of the upper end point of the t-th vertical line segment lv in the first vertical line segment set Lv1 t t up obtaining the y-coordinate y of the upper end point of the t-th vertical line segment lv in the first vertical line segment set Lv1 t t up obtaining the x-coordinate x of the lower end point of the t-th vertical line segment lv in the first vertical line segment set Lv1 t t down obtaining the y-coordinate y of the lower end point of the t-th vertical line segment lv in the first vertical line segment set Lv1 t t down calculating the average x-coordinate x of the t-th vertical line segment lv in the first vertical line segment set Lv1 t t The calculation formula is shown in formula (3): (3); Step S3203, set the second rectangular clipping region Ar2, initialize the top-left endpoint coordinate of the second rectangular clipping region Ar2 as (x t -Teh, y t up ), initialize the bottom-right endpoint coordinate of the second rectangular clipping region Ar2 as (x t -Teh, y t down ); clip the binary image I b according to the second rectangular clipping region Ar2, to obtain the vertical line segment binary image I lv (t) ; Step S3204, binarizing the vertical line segment image I lv (t) Performing vertical projection to obtain a vertical projection vector VP (t) , let vp (t) w denote the wth element in the vertical projection vector VP (t) , where w = 1, 2, …, wi lv (t) , wi lv (t) is the width of the vertical line segment binarization image I lv (t) , the wth element vp (t) in the vertical projection vector VP (t) w denotes the number of foreground points in the wth column of the vertical line segment binarization image I lv (t) , and the foreground point is a pixel point with a pixel value of 255. Step S3205, calculating the maximum projection value vp in the vertical projection vector VP (t) (t) max The calculation formula is shown in formula (4): (4); Step S3206, let vcr min represents the minimum change rate of the current vertical projection, and the minimum change rate of the current vertical projection vcr min is vp (t) max x Tt2; Step S3207, set left side trough flag tf left and right side trough flag tf right , initialize the value of left side trough flag tf left to 0, initialize the value of right side trough flag tf right to 0; set vertical projection trough span vts, initialize the value of vertical projection trough span vts to 0; Step S3208, set the value of the fourth variable v to 1; Step S3209, if vp (t) max -vp (t) v <vcr min the value of the vertical projection valley span vts is set to 0, otherwise the value of the vertical projection valley span vts is increased by 1; Step S3210, if vts≥ Ts2, the value of left trough flag tf left is set to 1, and jump to step S3212; Step S3211, increase the value of the fourth variable v by 1, and if v≤Teh, jump to step S3209; Step S3212, set the value of the vertical projection valley span vts to 0, and set the value of the fourth variable v to Teh+1; Step S3213, if vp (t) max -vp (t) v <vcr min the value of the vertical projection valley span vts is set to 0, otherwise the value of the vertical projection valley span vts is increased by 1; Step S3214, if vts≥ Ts2, the value of right side trough flag tf right is set to 1, and jump to step S3216; Step S3215, increase the value of the fourth variable v by 1, if v≤wi lv (t) then jump to step S3213; Step S3216, if tf left = 1, tf right = 1, the tth vertical line segment lv t in the first vertical line segment set Lv1 is added into the second vertical line segment set Lv2. Step S3217, increase the value of the third variable t by 1, and if t≤ng, jump to step S3202.
3. The method of claim 2, wherein: In step S3, adjacent horizontal line segments in the second horizontal line segment set Lh2 are spliced to obtain a third horizontal line segment set Lh3, and the specific steps are as follows: Step S3301, according to the y coordinate of the left end point of the horizontal line segment, sort all horizontal line segments in the second horizontal line segment set Lh2 in ascending order; Step S3302, setting a first distance threshold Td1, setting a second distance threshold Td2, let lh i represents the i-th horizontal line segment of the second horizontal line segment set Lh2, i = 1, 2, …, ni, ni is the number of horizontal line segments in the second horizontal line segment set Lh2; define a horizontal line segment splicing mark set Fh containing n splicing mark variables, the i-th splicing mark variable fh i represents the splicing mark of the i-th horizontal line segment in the second horizontal line segment set, the splicing mark fh i The initial value is 0; Set the fifth variable k and the sixth variable j; the initial value of the fifth variable k is set to 0; Step S3303: increase the value of the fifth variable k by 1, and if k>ni-1, jump to step S3311; Step S3304, if fh k = 1, then jump to step S3303, otherwise, set the value of the sixth variable j to the fifth variable k; Step S3305, increase the value of the sixth variable j by 1, and if j>ni, jump to step S3303; Step S3306, if fh j = 1, jump to step S3305; Step S3307, if x k right ’ < x j left ’, where x k right ’ denotes the x-coordinate of the right end point of the kth horizontal line segment of the second horizontal line segment set Lh2, x j left ’ denotes the x-coordinate of the left end point of the jth horizontal line segment of the second horizontal line segment set Lh2, it is determined that the kth horizontal line segment lh k ’ of the second horizontal line segment set Lh2 is located left of the jth horizontal line segment lh j ’ of the second horizontal line segment set; if x j right ’ > x k left ’, where x j right ’ denotes the x-coordinate of the right end point of the jth horizontal line segment of the second horizontal line segment set Lh2, x k left ’ denotes the x-coordinate of the left end point of the kth horizontal line segment of the second horizontal line segment set Lh2, it is determined that the jth horizontal line segment of the second horizontal line segment set is located left of the kth horizontal line segment lh j ’ of the second horizontal line segment set Lh2; if x k ’ = x < / s> If the kth horizontal line segment lh k in the second horizontal line segment set Lh2 is located on the left of the jth horizontal line segment lh j , |x k right -x j left |<Td1, and |y k right -y j left |<Td1, the left end point of the kth horizontal line segment lh k in the second horizontal line segment set Lh2 is connected with the right end point of the jth horizontal line segment lh j in the second horizontal line segment set, to obtain a horizontal splicing line segment lc k,j ; otherwise, if the jth horizontal line segment lh j in the second horizontal line segment set is located on the right of the kth horizontal line segment lh k in the second horizontal line segment set Lh2, |x j right -x k left |<Td1, and |y j right -y k left |<Td1, the left end point of the jth horizontal line segment lh j in the second horizontal line segment set is connected with the right end point of the kth horizontal line segment lh k in the second horizontal line segment set Lh2, to obtain a horizontal splicing line segment lc k,j ; otherwise, jump to step S3305. Step S3309: Calculate the kth horizontal line segment lh of the second horizontal line segment set Lh2. k The left end point of ' to the horizontal splicing segment lc k,j vertical distance dh k,1 The kth horizontal line segment lh in the second set of horizontal line segments Lh2 k The right end point of ' to the horizontal splicing segment lc k,j vertical distance dh k,2 The j-th horizontal line segment lh in the second set of horizontal line segments j The left end point of ' to the horizontal splicing segment lc k,j vertical distance dh j,3 The j-th horizontal line segment lh in the second set of horizontal line segments j The right end point of ' to the horizontal splicing segment lc k,j vertical distance dh j,4 ; Step S3310, if dh k,1 <Td2, dh k,2 <Td2, dh j,3 <Td2, dh j,4 If the value of the splicing mark fh k of the kth horizontal line segment in the second horizontal line segment set and the value of the splicing mark fh j of the jth horizontal line segment in the second horizontal line segment set are both 1, and the horizontal splicing line segment lc k,j is added to the third horizontal line segment set Lh3; jump to step S3303; Step S3311, traverse each splicing mark in the horizontal line segment splicing mark set Fh, if the i-th variable fh i in the horizontal line segment splicing mark set Fh is 0, then the i-th horizontal line segment lh i in the second horizontal line segment set Lh2 is added into the third horizontal line segment set Lh3.
4. The method of claim 3, wherein: In step S3, adjacent vertical line segments in the second vertical line segment set Lv2 are spliced to obtain a third vertical line segment set Lv3, and the specific steps are as follows: Step S3401, according to the x coordinate of the upper end point of the vertical line segment, sort each vertical line segment in the second vertical line segment set Lv2 in ascending order; Step S3402, let lv j represents the jth vertical line segment of the second vertical line segment set Lv2, j = 1, 2, …, nj, and nj is the number of vertical line segments in the second vertical line segment set Lv2; define a vertical line segment splicing mark set Fv containing o splicing mark variables, and the jth splicing mark variable fv j represents the splicing mark of the jth vertical line segment in the second vertical line segment set, and the splicing mark fv j is initially set to 0; Set the seventh variable u and the eighth variable s; the initial value of the seventh variable u is set to 0; Step S3403, increase the value of the seventh variable u by 1, and if u>nj-1, jump to step S3411; Step S3404, if fv u = 1, then jump to step S3403, otherwise, set the value of the eighth variable s to the seventh variable u; Step S3405, increase the value of the eighth variable s by 1, and if s>nj, jump to step S3403; Step S3406, if fv j = 1, jump to step S3405; Step S3407, if y s down y u up y s down y u up y s u y u down y s up y u down y s up y u s y If the u-th vertical line segment lv u in the second vertical line segment set Lv2 is located above the s-th vertical line segment lv s , |x u down -x s up | < Td1, and |y u down -y s up | < Td1, the upper end point of the u-th vertical line segment lv u in the second vertical line segment set Lv2 is connected with the lower end point of the s-th vertical line segment lv s in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc u,s ; otherwise, if the s-th vertical line segment lv s in the second vertical line segment set Lv2 is located above the u-th vertical line segment lv u in the second vertical line segment set Lv2, |x s down -x u up | < Td1, and |y s down -y u up | < Td1, the upper end point of the s-th vertical line segment lv s in the second vertical line segment set Lv2 is connected with the lower end point of the u-th vertical line segment lv u in the second vertical line segment set Lv2, to obtain a vertical splicing line segment lc u,s ; otherwise, jump to step S3405. Step S3409, calculating the vertical distance dv of the upper end point of the u-th vertical line segment lv in the second vertical line segment set Lv2 to the vertical splicing line segment lc u ’ to the vertical splicing line segment lc u,s ’ to the vertical splicing line segment lc u,1 ’ to the vertical splicing line segment lc u ’ to the vertical splicing line segment lc u,s ’ to the vertical splicing line segment lc u,2 ’ to the vertical splicing line segment lc s ’ to the vertical splicing line segment lc u,s ’ to the vertical splicing line segment lc s,3 ’ to the vertical splicing line segment lc s ’ to the vertical splicing line segment lc u,s ’ to the vertical splicing line segment lc s,4 ; Step S3410, if dv u,1 <Td2, dv u,2 <Td2, dv s,3 <Td2, dv s,4 <Td2, then set the splicing flag fv of the u-th vertical line segment in the second set of vertical line segments u and the splicing flag fv of the s-th vertical line segment in the second set of vertical line segments s to 1, and add the vertical splicing line segment lc u,s to the third set of vertical line segments Lv3; Jump to step S3403; Step S3411, traverse each splicing mark in the vertical line segment splicing mark set Fv, if the jth variable fv j in the vertical line segment splicing mark set Fv is 0, then the jth vertical line segment lv j in the second vertical line segment set Lv2 is added into the third vertical line segment set Lv3.
Citation Information
Patent Citations
Lightweight image line segment extraction and description method based on deep learning
CN115690444A
Straight line segment detection method and system based on prediction correction mechanism
CN117994222A
Table interference line removal algorithm
CN112016557A