A method for sorting characters by line

By obtaining the width, height and center point coordinates of characters, using random circle fitting evaluation and Hough linear fitting method to branch sort, the problem of difficulty in handling arc shapes and special characters in the existing technology is solved, and the accuracy of ink coding detection is improved Sex and stability.

CN114419615BActive Publication Date: 2024-12-20RETOO
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210212648.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-04
Publication Date
2024-12-20
Estimated Expiration
2042-03-04

AI Technical Summary

Technical Problem

Existing character recognition technology deals with problems such as wet or electrostatic surfaces, false triggers or ink exhaustion, and is difficult to accurately determine the problem of ink errors and low recognition, especially in food packaging bags, beverage boxes and drug packaging. There are flaws in handling branch and sorting, especially curved character lines and special Chinese characters.

Method used

By obtaining the width and height of the characters and the coordinates of the center point, counting the average width and height, dividing the characters into special Chinese and other characters, using random circle fitting evaluation to judge arc or straight line rows, and dividing them based on the Hough straight line fitting method Sort, and finally filter out false detection characters based on standard strings and positions to determine the line number and sequence number of special Chinese characters.

Benefits of technology

It improves the stability and reliability of character branch sorting, can effectively handle arcs and special characters, reduce mis-divided and mis-detected characters, and is suitable for complex food and drug packaging and coding environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114419615B_ABST
    Figure CN114419615B_ABST
Patent Text Reader

Abstract

The invention discloses a character line sorting method, firstly, the character width and height and center point coordinates of all characters are obtained to form a character set, the average width and average height of all characters are counted, and the corresponding characters are divided into special Chinese characters and other characters according to the character width and height, average width and average height of each character, and the special Chinese characters are processed, and then the random circle fitting evaluation method is used in the other characters to judge whether the distribution of the other characters is a straight line or an arc line, and for the arc line, the line is divided according to the result of the random circle fitting evaluation; for the straight line, the Hough straight line fitting method is used for line division, and then the characters of each line are sorted, and finally, according to the preset standard character string and the relative position of the standard character, the misdetected characters are filtered out, and the final line number and sequence number of the special Chinese character are determined. Various situations of actual production application are fully considered, and the stability and reliability of the character line sorting algorithm are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of character recognition, and in particular to a character line sorting method. Background Art

[0002] In the food, beverage, daily necessities, pharmaceutical and other industries, manufacturers must perform text labeling operations such as batch numbers, serial numbers, models, production dates, and shelf life on food packaging bags, beverage boxes (cans) and medicine packaging boxes, daily necessities packaging labels, and medicine box packaging. This operation usually uses ink jet printers or laser jet printers to spray codes at designated locations. During the coding process, defects such as missing codes, coding errors, and low coding recognition are often caused by factors such as wet surfaces or electrostatic surfaces, false triggering, or ink depletion. These printed contents must be detected quickly and reliably.

[0003] When designing relevant detection algorithms, a very important step is to divide and sort the detected characters. Existing methods usually use the projection method to divide characters. The basic principle is to determine the position of the line separation based on the vertical projection of the foreground pixel points of the character line, and then sort the characters after the line separation according to the horizontal x coordinate. This method has several defects. First, when there is a large error in the tilt correction of the character line, or the character line spacing is small, the projection method may obtain incorrect line branch information; second, there is no way to handle arc-shaped character lines, which are very common in the inkjet coding of bottled beverages, condiments and other products; third, special Chinese characters whose positions and sizes do not conform to the conventions will also make the projection method invalid. Summary of the invention

[0004] In view of the above technical problems, the present invention provides a method for sorting characters by line.

[0005] The technical solution adopted by the present invention to solve the technical problem is:

[0006] A method for sorting characters by line, the method comprising the following steps:

[0007] Step S100: Obtain the character width, height and center point coordinates of all characters to form a character set, calculate the average width and average height of all characters, divide the corresponding characters into special Chinese characters and other characters according to the character width, height, average width and average height of each character, and process the row number of the special Chinese characters;

[0008] Step S200: performing random circle fitting evaluation on the center points of the remaining characters to obtain evaluation results;

[0009] Step S300: determine whether the remaining characters are distributed in straight lines or curved lines. If they are curved lines, divide them into lines according to the evaluation result of step S200. If they are straight lines, divide them into lines based on the Hough straight line fitting method.

[0010] Step S400: sorting the characters in each line after the line division to obtain sorted characters in each line;

[0011] Step S500: According to the preset standard character string and the relative position of the standard characters, the misdetected characters in each row of characters after sorting are filtered out, and the final row number and sequence number of the special Chinese character are determined.

[0012] Preferably, step S100 includes:

[0013] Step S110: For the detected character set P (x, y, w, h), calculate the average width w of all characters using formula (1): a and the average height h a , specifically:

[0014]

[0015] Where (x, y) is the coordinate of the center point of the character, w and h are the width and height of the character respectively, i is the sequence number of the character, and N is the number of all characters;

[0016] Step S120: traverse the character set P. If the i-th (0≤i≤N) character satisfies formula (2), it is a special Chinese character. All special Chinese characters form a set P', and the remaining characters form a set P', which is specifically:

[0017] w i >2*w a or i >2*h a or i *h i >3*w a *h a (2)

[0018] Step S130: Set the row numbers of all special Chinese characters in set P" to -1.

[0019] Preferably, step S200 includes:

[0020] Step S210: Randomly select three characters P' from the set P' s1 (x s1 ,y s1 ,w s1 ,h s1 ), P' s2 (x s2 ,y s2 ,ws2 ,h s2 ), P' s3 (x s3 ,y s3 ,w s3 ,h s3 ) Fitting circle C s , radius R s Calculated by equation (3) to equation (5), specifically:

[0021]

[0022]

[0023]

[0024] Among them, (x s1 ,y s1 ,w s1 ,h s1 )、(x s2 ,y s2 ,w s2 ,h s2 )、(x s3 ,y s3 ,w s3 ,h s3 ) represent P' s1 , P' s2 and P' s3 The center point coordinates and width and height, (C xs ,C ys ) are the fitting circles C s The center point coordinates of , the subscript s represents the sth random sampling operation;

[0025] Step S220: Calculate the distance from the center point of all characters in the remaining character set P' to the fitting circle C by using equation (6) s The distance d, statistics d <T d The number of characters n s ;

[0026]

[0027] Where Td is the preset distance threshold, (x i ,y i ) is the coordinate of the center point of the i-th (0≤i≤N') character, d i is the distance from the center point of the i-th character to the fitting circle Cs;

[0028] Step S230: Calculate the fitting value g by formula (7) s ;

[0029]

[0030] Wherein, N' is the number of the remaining characters, and ns is the number of characters with d < Td;

[0031] Step S240: Let s = s + 1, and set T g as the threshold value of the fitting degree value. If g s > T g , then the candidate fitting circle is found, and the center point coordinates (C xs , C ys ), radius R s , and the number of characters n s of the candidate fitting circle are cached into the array A, and at the same time, the number of successful times m = m + 1 (the initial value of m is 0);

[0032] Step S250: Repeat steps S210 to S240. Set T s as the threshold value of the termination iteration times, and T m as the threshold value of the number of successfully fitted circles. If s > T s or m > T m , end the iteration.

[0033] Preferably, in step S300, it is judged whether the distribution of the remaining characters is a straight line or an arc line. Specifically:

[0034] If m > T m in step S250, then it is an arc line, otherwise it is a straight line.

[0035] Preferably, in step S300, if the distribution of the remaining characters is an arc line, line breaking is performed according to the evaluation result of step S200, including:

[0036] Step S310: Sort the array A in descending order according to the number of characters n s , and select the first L rows in the sorted array A according to the preset number of character lines L to obtain the candidate array A';

[0037] Step S320: Sort the candidate array A' in descending order according to the radius R s ;

[0038] Step S330: For each character in the remaining character set P', calculate the distance set d i from P' A’ (i ≤ N') to all candidate fitting circles in A' in sequence, take the minimum value d A’ in d A’min , if d A’min < T d , then the index I A’min of d min in A' is the line number of the character P' i ;

[0039] Step S340: sort each character in the set P' in ascending order according to the row number corresponding to each character.

[0040] Preferably, if the line is a straight line in step S300, dividing the line based on the Hough straight line fitting method includes:

[0041] Step S350: Perform Hough line detection on all remaining character center points to obtain a candidate line set B(v,θ,r), where the parameters v,θ,r represent the number of votes for the line, the angle between the vertical line of the line and the horizontal axis, and the distance from the line to the image origin, respectively;

[0042] Step S360: Select the line B with the largest number of votes v in the candidate line set B. e (v e ,θ e ,r e ) as a reference straight line;

[0043] Step S370: traverse the candidate line set B, and for the lth line in B, if its parameters satisfy formula (8), store it in the preset set B';

[0044]

[0045] Among them, θ l is the angle between the perpendicular line of the lth line and the horizontal axis, θ e is the angle between the vertical line Be with the largest vote value v and the horizontal axis, r l is the distance from the lth line to the origin of the image, r B',φ is the distance from the φth line in B' to the origin of the image, T θ is the angle threshold between two adjacent rows, T r is the distance threshold between two adjacent rows;

[0046] Step S380: For each character in the remaining character set P', calculate P' in turn according to formula (9) i The distance set d from (i≤N) to all lines in B' B’ , take d B’ Minimum value d B’min , if d B’min <T d , then d B’min At index I of B' min That is the character P' i The row number of

[0047]

[0048] Step S390: sort each character in the set P' in ascending order according to the row number corresponding to each character.

[0049] Preferably, step S400 is: sorting the characters in each row in ascending order according to the x-coordinate.

[0050] Preferably, filtering out misdetected characters according to a preset standard character string and relative positions of standard characters in step S500 includes:

[0051] Step S510: Determine the reference character row: for the hth (0≤h≤L)th row of characters processed in step S300, the number of characters n h , the number of characters in the hth row of the standard string is n h ', determine whether it can be used as a reference row by formula (10);

[0052]

[0053] Among them, x h,ν With x' h,ν represents the nth character in the hth line of the character string to be processed and the standard character string respectively, μ is the character spacing threshold parameter, and n represents the total number of characters;

[0054] If the lth row can be used as a reference row, execute step S520; if not, then h=h+1, continue traversing, and if no reference row is found after traversing all rows, end step S500;

[0055] Step S520: For the j-th (0≤j≤L, j≠i) row other than the reference row, compare the number of characters n in the j-th row j The number of characters n in the jth line of the standard string j 'Are they equal? ​​If they are equal, j=j+1, continue traversing, otherwise execute step S530;

[0056] Step S530: traverse the j-th row, and for the character to be processed and the character in the standard string, the j-th row and the v-th character, respectively, calculate the minimum horizontal distance d between this character and all the characters in the reference row. σ , d σs And the corresponding character number I σ , I σs , if it satisfies formula (11), then the character is a false positive character and is deleted from the jth row of characters to be processed;

[0057]

[0058] Among them, T σ1 is the first threshold parameter, T σ2 is the second threshold parameter.

[0059] Preferably, determining the final line number and sequence number of the special Chinese character in step S500 includes:

[0060] Step S540: Assume that after the processing of steps S200 to S400, the remaining character set in set P' is P z ', calculate the following values:

[0061] P z 'Minimum and maximum values ​​of the x and y coordinates of the characters in the text box: x' min , y' min , x' max , y' max

[0062] The minimum and maximum values ​​of the x and y coordinates of the characters in the special Chinese character set P": x min ,y" min , x” max ,y" max

[0063] Step S550: There are five situations in which the positions of characters in the set P are:

[0064] (1) If y” min +y" max <y’ min +y' max , then it is the first row, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters;

[0065] (2) If y” min +y" max >y' min +y' max , then it is the last row, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters;

[0066] (3) If x” min <x’ min And x" max >x' max , then distributed in the set P z 'The left and right sides of the character, at this time, the characters in set P" are split into two lines, and the center point is in set P z 'The characters on the left, the row number is still marked as -1, for the center point in the set P z 'The characters on the right are marked with row number L-1, and the character numbers in the same row are sorted from small to large according to the x-coordinate of the corresponding character;

[0067] (4) If x” min +x” max>x' min +x' max , then distributed in the set P z 'On the left side of the character, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character;

[0068] (5) If x” min +x” max >x' min +x' max , then distributed in the set P z ' character, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character.

[0069] The above method first obtains the character width and height and center point coordinates of all characters to form a character set, counts the average width and average height of all characters, divides the corresponding characters into special Chinese characters and other characters according to the character width and height, average width and average height of each character, and processes the special Chinese characters, and then uses the random circle fitting evaluation method in the remaining characters to determine whether the remaining characters are distributed in straight lines or arc lines. For arc lines, the lines are divided according to the results of the random circle fitting evaluation; for straight lines, the Hough straight line fitting method is used for line division, and then the characters in each line are sorted, and finally, according to the relative positions of the preset standard character string and the standard characters, the misdetected characters are filtered out, and the final line number and sequence number of the special Chinese characters are determined. The character line sorting method provided by the present invention fully considers various situations of actual production applications, and adopts different algorithm strategies for processing, which can greatly improve the stability and reliability of the character line sorting algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] Figure 1 A flow chart of a character line sorting method provided by one embodiment of the present invention. DETAILED DESCRIPTION

[0071] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.

[0072] In one embodiment, Figure 1 As shown, a method for sorting characters by line, the method comprising the following steps:

[0073] Step S100: Obtain the character width, height and center point coordinates of all characters to form a character set, count the average width and average height of all characters, divide the corresponding characters into special Chinese characters and other characters according to the character width, height, average width and average height of each character, and process the row number of the special Chinese characters.

[0074] Specifically, in this embodiment, special Chinese characters with larger width and height, such as "qualified" and "qualified quality", are processed.

[0075] In one embodiment, step S100 includes:

[0076] Step S110: For the detected character set P (x, y, w, h), calculate the average width w of all characters using formula (1): a and the average height h a , specifically:

[0077]

[0078] Where (x, y) is the coordinate of the center point of the character, w and h are the width and height of the character respectively, i is the sequence number of the character, and N is the number of all characters;

[0079] Step S120: traverse the character set P. If the i-th (0≤i≤N) character satisfies formula (2), it is a special Chinese character. All special Chinese characters form a set P', and the remaining characters form a set P', which is specifically:

[0080] w i >2*w a or i >2*h a or i *h i >3*w a *h a (2)

[0081] Step S130: Set the row numbers of all special Chinese characters in set P" to -1.

[0082] Specifically, firstly, according to the detected single character position information, it is searched whether there are special Chinese characters such as "Qualified" with larger width and height, and it is first defaulted to the first row.

[0083] Step S200: performing random circle fitting evaluation on the remaining character center points.

[0084] In one embodiment, step S200 includes:

[0085] Step S210: Randomly select three characters P' from the set P' s1 (x s1 ,y s1 ,w s1 ,h s1 ), P' s2 (x s2 ,y s2 ,w s2 ,h s2), P' s3 (x s3 ,y s3 ,w s3 ,h s3 ) Fitting circle C s , radius R s Calculated by equation (3) to equation (5), specifically:

[0086]

[0087]

[0088]

[0089] Among them, (x s1 ,y s1 ,w s1 ,h s1 )、(x s2 ,y s2 ,w s2 ,h s2 )、(x s3 ,y s3 ,w s3 ,h s3 ) represent P' s1 , P' s2 and P' s3 The center point coordinates and width and height, (C xs ,C ys ) are the fitting circles C s The center point coordinates of , the subscript s represents the sth random sampling operation;

[0090] Step S220: Calculate the distance from the center point of all characters in the remaining character set P' to the fitting circle C by using equation (6) s The distance d, statistics d <T d The number of characters n s ;

[0091]

[0092] Where Td is the preset distance threshold, (x i ,y i ) is the coordinate of the center point of the i-th (0≤i≤N') character, d i is the distance from the center point of the i-th character to the fitting circle Cs;

[0093] Step S230: Calculate the fitting value g by formula (7) s ;

[0094]

[0095] Where N' is the number of the remaining characters, and ns is the number of characters with d < Td;

[0096] Step S240: Let s = s + 1, and set T g as the threshold value of the fitting degree. If g s > T g , then find the candidate fitting circle, and cache the center point coordinates (C xs , C ys ), radius R s , and the number of characters n s into the array A. Meanwhile, the number of successful times m = m + 1 (the initial value of m is 0);

[0097] Step S250: Repeat steps S210 - S240. Set T s as the threshold value of the termination iteration times, and T m as the threshold value of the number of successfully fitted circles. If s > T s or m > T m , end the iteration.

[0098] Specifically, the value of T d can be set as T d = 0.5 * h a according to experience; the value of T g can be set as T g = 0.5 * N / L according to experience; the threshold value of the termination iteration times T s is set to 1000 according to experience; the threshold value of the number of successfully fitted circles T m is set to 10 according to experience.

[0099] Step S300: Determine whether the distribution of the remaining characters is a straight line or an arc. If it is an arc, perform line division according to the evaluation result of step S200. If it is a straight line, perform line division based on the Hough line fitting method.

[0100] In one embodiment, in step S300, determining whether the distribution of the remaining characters is a straight line or an arc is specifically:

[0101] If m > T m in step S250, then it is an arc, otherwise it is a straight line.

[0102] In one embodiment, in step S300, if the distribution of the remaining characters is an arc, performing line division according to the evaluation result of step S200 includes:

[0103] Step S310: Sort the array A in descending order according to the number of characters n s . According to the preset number of character lines L, select the first L rows in the sorted array A to obtain the candidate array A';

[0104] Step S320: Calculate the candidate array A' according to the radius R s Sort in descending order;

[0105] Step S330: For each character in the remaining character set P', calculate P' in turn according to formula (6) i The distance set d from (i≤N') to all candidate fitting circles in A' A’ , take d A’ Minimum value d A’min , if d A’min <T d , then d A’min At index I of A' min That is the character P' i The row number of

[0106] Step S340: sort each character in the set P' in ascending order according to the row number corresponding to each character.

[0107] In one embodiment, if the row is a straight line in step S300, dividing the row based on the Hough straight line fitting method includes:

[0108] Step S350: Perform Hough line detection (Hough transform-line detection) on the center points of all other characters to obtain a candidate line set B (v, θ, r), where the parameters v, θ, and r represent the number of votes for the line, the angle between the vertical line of the line and the horizontal axis, and the distance from the line to the origin of the image.

[0109] Step S360: Select the line B with the largest number of votes v in the candidate line set B. e (v e ,θ e ,r e ) as a reference straight line;

[0110] Step S370: traverse the candidate line set B, and for the lth line in B, if its parameters satisfy formula (8), store it in the preset set B';

[0111]

[0112] Among them, θ l is the angle between the perpendicular line of the lth line and the horizontal axis, θ e is the angle between the vertical line Be with the largest vote value v and the horizontal axis, r l is the distance from the lth line to the origin of the image, r B',φ is the distance from the φth line in B' to the origin of the image, T θ is the angle threshold between two adjacent rows, T r is the distance threshold between two adjacent rows.

[0113] Step S380: For each character in the remaining character set P', calculate P' in turn according to formula (9) i The distance set d from (i≤N) to all lines in B' B’ , take d B’ Minimum value d B’min , if d B’min <T d , then d B’min At index I of B' min That is the character P' i The row number of

[0114]

[0115] Step S390: sort each character in the set P' in ascending order according to the row number corresponding to each character.

[0116] Specifically, the reference line must be a complete character line, T θ Based on experience, the value of can be set to 3, in degrees; T r The value of T can be set based on experience. r =0.8*h a .

[0117] Step S400: sorting the characters in each line after the line division.

[0118] In one embodiment, step S400 is: sorting the characters in each row in ascending order according to the x-coordinate.

[0119] Step S500: According to the preset standard character string and the relative position of the standard characters, the misdetected characters are filtered out, and the final line number and sequence number of the special Chinese characters are determined.

[0120] Specifically, the standard character string in step S500 can be manually set by software or obtained in real time through communication with other devices; the relative position information of the standard character string refers to a standard image prepared in advance for detection without false detection, and the row number, sequence number and position information of each character are obtained after the characters in the image are sorted by line according to steps S100-S400. This information is cached for use in step S500 to filter out possible falsely detected characters when processing other images.

[0121] In one embodiment, filtering out misdetected characters according to a preset standard character string and relative positions of standard characters in step S500 includes:

[0122] Step S510: Determine the reference character row: for the hth (0≤h≤L)th row of characters processed in step S300, the number of characters n h, the number of characters in the hth row of the standard string is n h ', determine whether it can be used as a reference row by formula (10);

[0123]

[0124] Among them, x h,ν With x' h,ν represents the nth character in the hth line of the character string to be processed and the standard character string respectively, μ is the character spacing threshold parameter, and n represents the total number of characters;

[0125] If the lth row can be used as a reference row, execute step S520; if not, then h=h+1, continue traversing, and if no reference row is found after traversing all rows, end step S500;

[0126] Step S520: For the j-th (0≤j≤L, j≠i) row other than the reference row, compare the number of characters n in the j-th row j The number of characters n in the jth line of the standard string j 'Are they equal? ​​If they are equal, j=j+1, continue traversing, otherwise execute step S530;

[0127] Step S530: traverse the j-th row, and for the character to be processed and the character in the standard string, the j-th row and the v-th character, respectively, calculate the minimum horizontal distance d between this character and all the characters in the reference row. σ , d σs And the corresponding character number I σ , I σs , if it satisfies formula (11), then the character is a false positive character and is deleted from the jth row of characters to be processed;

[0128]

[0129] Among them, T σ1 is the first threshold parameter, T σ2 is the second threshold parameter.

[0130] Specifically, the value of μ can be set to 0.25 based on experience; T m The value of can be set to 0.5 based on experience.

[0131] In one embodiment, determining the final line number and sequence number of the special Chinese character in step S500 includes:

[0132] Step S540: Assume that after the processing of steps S200 to S400, the remaining character set in set P' is P z ', calculate the following values:

[0133] P z 'Minimum and maximum values ​​of the x and y coordinates of the characters in the text box: x'min , y' min , x' max , y' max

[0134] The minimum and maximum values ​​of the x and y coordinates of the characters in the special Chinese character set P": x min ,y" min , x” max ,y" max

[0135] Step S550: There are five situations in which the positions of characters in the set P are:

[0136] (1) If y” min +y" max <y’ min +y' max , then it is the first row, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters;

[0137] (2) If y” min +y" max >y' min +y' max , then it is the last row, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters;

[0138] (3) If x” min <x’ min And x" max >x' max , then distributed in the set P z 'The left and right sides of the character, at this time, the characters in set P" are split into two lines, and the center point is in set P z 'The characters on the left, the row number is still marked as -1, for the center point in the set P z 'The characters on the right are marked with row number L-1, and the character numbers in the same row are sorted from small to large according to the x-coordinate of the corresponding character;

[0139] (4) If x” min +x” max >x' min +x' max , then distributed in the set P z 'On the left side of the character, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character;

[0140] (5) If x” min +x” max >x' min+x' max , then distributed in the set P z ' character, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character.

[0141] The above method first obtains the character width and height and center point coordinates of all characters to form a character set, counts the average width and average height of all characters, divides the corresponding characters into special Chinese characters and other characters according to the character width and height, average width and average height of each character, and processes the special Chinese characters, and then uses the random circle fitting evaluation method in the remaining characters to determine whether the remaining characters are distributed in straight lines or arc lines. For arc lines, the lines are divided according to the results of the random circle fitting evaluation; for straight lines, the Hough straight line fitting method is used for line division, and then the characters in each line are sorted, and finally, according to the relative positions of the preset standard character string and the standard characters, the misdetected characters are filtered out, and the final line number and sequence number of the special Chinese characters are determined. The character line sorting method provided by the present invention fully considers various situations of actual production applications, and adopts different algorithm strategies for processing, which can greatly improve the stability and reliability of the character line sorting algorithm.

[0142] The above is a detailed introduction to a character line sorting method provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of ​​the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A character line sorting method, characterized in that: The method comprises the following steps: Step S100: Obtain the character width and height and center point coordinates of all characters to form a character set, calculate the average width and average height of all characters, divide the corresponding characters into special Chinese characters and other characters according to the character width and height of each character, the average width and the average height, and process the row number of the special Chinese characters; Step S200: performing random circle fitting evaluation on the remaining character center points to obtain evaluation results; Step S300: determining whether the remaining characters are distributed in straight lines or curved lines, if they are curved lines, dividing the lines according to the evaluation result of step S200, and if they are straight lines, dividing the lines based on the Hough straight line fitting method; Step S400: sorting the characters in each line after the line division to obtain sorted characters in each line; Step S500: According to the preset standard character string and the relative position of the standard characters, the misdetected characters in each row of characters after the sorting are filtered out, and the final row number and sequence number of the special Chinese character are determined.

2. The method according to claim 1, characterized in that Step S100 includes: Step S110: For the detected character set P (x, y, w, h), calculate the average width w of all characters using formula (1): a and the average height h a , specifically: Where (x, y) is the coordinate of the center point of the character, w and h are the width and height of the character respectively, i is the sequence number of the character, and N is the number of all characters; Step S120: traverse the character set P. If the i-th (0≤i≤N) character satisfies formula (2), it is a special Chinese character. All special Chinese characters form a set P', and the remaining characters form a set P', which is specifically: w i >2*w a or i >2*h a or i *h i >3*w a *h a (2) Step S130: Set the row numbers of all special Chinese characters in the set P" to -1.

3. The method according to claim 2, characterized in that Step S200 includes: Step S210: Randomly select three characters P' from the set P' s1 (x s1 ,y s1 ,w s1 ,h s1 ), P' s2 (x s2 ,y s2 ,w s2 ,h s2 ), P' s3 (x s3 ,y s3 ,w s3 ,h s3 ) Fitting circle C s , radius R s Calculated by equation (3) to equation (5), specifically: Among them, (x s1 ,y s1 ,w s1 ,h s1 )、(x s2 ,y s2 ,w s2 ,h s2 )、(x s3 ,y s3 ,w s3 ,h s3 ) represent P' s1 , P' s2 and P' s3 The center point coordinates and width and height, (C xs ,C ys ) are the fitting circles C s The center point coordinates of , the subscript s represents the sth random sampling operation; Step S220: Calculate the distance from the center point of all characters in the remaining character set P' to the fitting circle C by using formula (6) s The distance d, statistics d <T d The number of characters n s ; Where Td is the preset distance threshold, (x i ,y i ) is the coordinate of the center point of the i-th (0≤i≤N') character, d i is the distance from the center point of the i-th character to the fitting circle Cs; Step S230: Calculate the fitting value g by formula (7) s ; where N' is the number of the remaining characters, and n s is the number of characters with d < Td; Step S240: Let s=s+1, set T g is the fitting value threshold, if g s >T g , then find the candidate fitting circle and set the center point coordinates (C xs ,C ys ), radius R s , and the number of characters n s Cache into array A, and the number of successes m = m + 1 (the initial value of m is 0); Step S250: Repeat steps S210 to S240, and set T s is the termination iteration threshold, T m is the threshold of the number of successful circle fitting, if s>T s or m>T m , ending the iteration.

4. The method according to claim 3, characterized in that In step S300, it is determined whether the remaining characters are distributed in a straight line or an arc line, specifically: If m>T in step S250 m , then it is an arc line, otherwise it is a straight line.

5. The method according to claim 4, characterized in that In step S300, if the remaining characters are distributed in arc-shaped lines, dividing the lines according to the evaluation result of step S200 includes: Step S310: Array A is sorted by the number of characters n s Sort in descending order, and select the first L rows in the sorted array A according to the preset number of character rows L, to obtain the candidate array A'; Step S320: Calculate the candidate array A' according to the radius R s Sort in descending order; Step S330: for each character in the remaining character set P', calculate P' in turn according to formula (6) i The distance set d from (i≤N') to all candidate fitting circles in A' A’ , take d A’ Minimum value d A’min , if d A’min <T d , then d A’min At index I of A' min That is the character P' i The row number of Step S340: sort each character in the set P' in ascending order according to the row number corresponding to each character.

6. The character line sorting method according to claim 5, characterized in that: If it is a straight line in step S300, the line is divided based on the Hough straight line fitting method, including: Step S350: Perform Hough line detection on the center points of all the remaining characters to obtain a candidate line set B(v,θ,r), where the parameters v,θ,r represent the number of votes for the line, the angle between the vertical line of the line and the horizontal axis, and the distance from the line to the origin of the image. Step S360: Select the line B with the largest number of votes v in the candidate line set B. e (v e ,θ e ,r e ) as a reference straight line; Step S370: traverse the candidate line set B, and for the lth line in B, if its parameters satisfy formula (8), store it into the preset set B'; Among them, θ l is the angle between the perpendicular line of the lth line and the horizontal axis, θ e is the angle between the vertical line Be with the largest vote value v and the horizontal axis, r l is the distance from the lth line to the origin of the image, r B',φ is the distance from the φth line in B' to the origin of the image, T θ is the angle threshold between two adjacent rows, T r is the distance threshold between two adjacent rows. Step S380: For each character in the remaining character set P', calculate P' in turn according to formula (9) i The distance set d from (i≤N) to all lines in B' B’ , take d B’ Minimum value d B’min , if d B’min <T d , then d B’min At index I of B' min That is the character P' i The row number of Step S390: sort each character in the set P' in ascending order according to the row number corresponding to each character.

7. The character line sorting method according to claim 6, characterized in that: Step S400 is: sorting the characters in each row in ascending order according to the x coordinate.

8. The character line sorting method according to claim 7, characterized in that: In step S500, according to the preset standard character string and the relative position of the standard characters, the false detection characters are filtered out, including: Step S510: Determine the reference character row: for the hth (0≤h≤L)th row of characters processed in step S300, the number of characters n h , the number of characters in the hth row of the standard string is n h ', determine whether it can be used as a reference row by formula (10); Among them, x h,ν With x' h,ν represents the nth character in the hth line of the character string to be processed and the standard character string respectively, μ is the character spacing threshold parameter, and n represents the total number of characters; If the lth row can be used as a reference row, execute step S520; if not, then h=h+1, continue traversing, and if no reference row is found after traversing all rows, end step S500; Step S520: For the j-th (0≤j≤L, j≠i) row other than the reference row, compare the number of characters n in the j-th row j The number of characters n in the jth row of the standard string j 'Are they equal? ​​If they are equal, j=j+1, continue traversing, otherwise execute step S530; Step S530: traverse the j-th row, and for the character to be processed and the character in the standard string, the j-th row and the v-th character, respectively, calculate the minimum horizontal distance d between this character and all the characters in the reference row. σ , d σs And the corresponding character number I σ , I σs , if it satisfies formula (11), then the character is a false positive character and is deleted from the jth row of characters to be processed; Among them, T σ1 is the first threshold parameter, T σ2 is the second threshold parameter.

9. The method according to claim 8, characterized in that Determining the final line number and sequence number of the special Chinese character in step S500 includes: Step S540: Assume that after the processing of steps S200 to S400, the remaining character set in the set P' is P z ', calculate the following values: The P z 'Minimum and maximum values ​​of the x and y coordinates of the characters in the text box: x' min , y' min , x' max , y' max The minimum and maximum values ​​of the x and y coordinates of the characters in the special Chinese character set P": x min ,y" min , x” max ,y" max Step S550: There are five situations in which the positions of characters in the set P” exist: 1) If y” min +y" max <y’ min +y' max , then it is the first row, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters; 2) If y” min +y" max >y' min +y' max , then it is the last row, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinates of the corresponding characters; 3) If x” min <x’ min And x" max >x' max , then distributed in the set P z 'The left and right sides of the character, at this time, the characters in set P" are split into two lines, and the center point is in set P z 'The characters on the left, the row number is still marked as -1, for the center point in the set P z 'The characters on the right are marked with row number L-1, and the character numbers in the same row are sorted from small to large according to the x-coordinate of the corresponding character; 4) If x” min +x” max >x' min +x' max , then distributed in the set P z 'On the left side of the character, the character row number in set P" is still marked as -1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character; 5) If x” min +x” max >x' min +x' max , then distributed in the set P z ' character, the character row number in set P" is marked as L-1, and the character numbers in the same row are sorted from small to large according to the x coordinate of the corresponding character.