Image character segmentation method, system, electronic device and storage medium
By using black and white binary processing and traversal kernel detection technology in image character cutting, the cutting boundary is determined and verified, which solves the problem of poor complex image processing in the existing technology and achieves efficient and accurate image character cutting and Identify.
Patent Information
- Application Number
- CN202411068401.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-08-06
AI Technical Summary
Existing image character cutting methods are not effective when processing complex images. Especially in resource-constrained environments and when facing targets of different scales and shapes, it is difficult to achieve efficient and accurate target detection, positioning and cutting.
By acquiring the image and performing black-and-white binary processing, a grid coordinate system is constructed, and the traversal kernel is used to detect along the Y-axis and X-axis directions to form connectivity analysis points and inflection points, determine the cutting boundary, and verify and adjust until the verification is passed.
It achieves effective cutting of target image characters, improves the accuracy and detection efficiency of subsequent character recognition and text recognition, adapts to targets of different sizes and shapes, and is suitable for resource-constrained environments.
Smart Images

Figure CN118587717B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image character processing, and in particular to an image character segmentation method, system, electronic equipment and storage medium. Background Art
[0002] With the rapid development of computer vision technology, image target detection, positioning and cutting technology has become one of the key technologies in this field. In many application scenarios such as autonomous driving, medical diagnosis, and security identification, accurate and efficient target detection, positioning and cutting technology are essential to improving the performance and accuracy of the system. In the text recognition system, image character cutting is an important link that directly affects the accuracy of subsequent character recognition and text recognition. Traditional image character cutting methods have limitations and are difficult to adapt to various complex image environments.
[0003] In the early days, target detection, positioning and cutting mainly relied on manual feature extraction and traditional image processing algorithms. These algorithms usually perform target recognition and positioning based on image features such as color, texture, and shape. However, due to the limitations of manual feature extraction and poor adaptability to complex environments, these methods often do not work well when processing complex images.
[0004] In recent years, with the rise of deep learning technology, the target detection, positioning and cutting technology based on convolutional neural network (CNN) has developed rapidly. CNN can automatically learn the feature representation in the image and optimize the model parameters through a large amount of data training, so as to achieve accurate detection, positioning and cutting of the target. Although deep learning technology has brought significant performance improvements to image target detection, positioning and cutting, it still faces some challenges: Model complexity and computing resources: Deep learning models are usually highly complex and require a lot of computing resources for training and reasoning. This limits its application in resource-constrained environments (such as mobile devices, embedded systems, etc.). Target scale and shape changes: Targets in real scenes often have different scales and shapes, which puts higher requirements on target detection, positioning and cutting algorithms. How to design an algorithm that can adaptively process targets of different scales and shapes is the focus of current research. Real-time and accuracy: In many application scenarios, target detection, positioning and cutting algorithms need to have both real-time and accuracy. How to improve the running speed of the algorithm while ensuring accuracy is the difficulty of current research. Therefore, it is of great significance to develop an efficient and accurate image character cutting method. Summary of the invention
[0005] In view of the shortcomings existing in the above problems, the present invention provides an image character segmentation method, system, electronic device and storage medium.
[0006] To achieve the above object, the present invention provides an image character segmentation method, comprising:
[0007] Acquire an image, and perform black-and-white binarization processing on the image to obtain a black-and-white thresholded image;
[0008] A grid coordinate system is constructed on the black-and-white thresholded image, a traversal kernel size is set, an initial pixel point is selected on the grid coordinate system, and the traversal kernel traverses and detects along the Y-axis direction from the initial pixel point until the first white pixel point is detected;
[0009] The traversal core traverses and detects along the X-axis and Y-axis directions respectively from the first white pixel until the first black pixel and the second black pixel are detected respectively;
[0010] The point formed by adding 1 pixel to the X-axis and subtracting 1 pixel from the Y-axis of the first white pixel is used as a first connectivity analysis point;
[0011] Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel point is detected along the X-axis direction. If no white pixel point is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel point is the first inflection point;
[0012] When the first connectivity analysis point fails, a point formed by subtracting 1 pixel from the Y axis is used as a second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found;
[0013] Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is traversed and detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point;
[0014] Starting from the second inflection point, traverse and detect in the reverse direction of the X-axis. If no white pixel is encountered during the detection process, the rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as the cutting boundary; if a white pixel is encountered during the detection process, stop and the second inflection point is not passed;
[0015] When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
[0016] Preferably, after the image character data is obtained by cutting along the cutting boundary, the image character data is verified. If the verification passes, it is successful; if the verification fails, the traversal kernel size is adjusted to repeatedly traverse to obtain the cutting boundary until the verification passes.
[0017] Preferably, the verification method comprises:
[0018] Comparing the size and area of the image character data with the model character library, and rejecting the cut characters with an area less than 50%;
[0019] When the area exceeds 50%, a black and white pixel matching comparison is performed, and if the model font exceeds the threshold of 80%, the verification is passed.
[0020] Preferably, when the image character data is verified, the white pixels within the verified cutting boundary are changed to black pixels, and the traversal detection is restarted.
[0021] Preferably, performing black-and-white binarization processing on the image includes: adding the RGB component values of each color and averaging to obtain the mean value of the color, and then using a threshold to determine whether the color is black, marked as 0, or white, marked as 1.
[0022] The present invention also provides an image character segmentation system, comprising:
[0023] A processing module, used for acquiring an image, and performing black-and-white binary processing on the image to obtain a black-and-white thresholded image;
[0024] A traversal module is used to construct a grid coordinate system in the black and white thresholded image, set a traversal kernel size, select an initial pixel point on the grid coordinate system, and the traversal kernel traverses and detects along the Y axis direction from the initial pixel point until the first white pixel point is detected;
[0025] The traversal core traverses and detects along the X-axis and Y-axis directions respectively from the first white pixel until the first black pixel and the second black pixel are detected respectively;
[0026] The point formed by adding 1 pixel to the X-axis and subtracting 1 pixel from the Y-axis of the first white pixel is used as a first connectivity analysis point;
[0027] Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel point is detected along the X-axis direction. If no white pixel point is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel point is the first inflection point;
[0028] When the first connectivity analysis point fails, a point formed by subtracting 1 pixel from the Y axis is used as a second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found;
[0029] Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is traversed and detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point;
[0030] Starting from the second inflection point, traverse and detect in the reverse direction of the X-axis. If no white pixel is encountered during the detection process, the rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as the cutting boundary; if a white pixel is encountered during the detection process, stop and the second inflection point is not passed;
[0031] When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
[0032] The present invention also provides an electronic device, comprising at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the above method.
[0033] The present invention also provides a storage medium storing a computer program executable by an electronic device, and when the program runs on the electronic device, the electronic device executes the above method.
[0034] Compared with the prior art, the present invention has the following beneficial effects:
[0035] The present invention can realize effective cutting of target image characters, and can improve the accuracy of subsequent image character recognition and text recognition and the detection efficiency of target positioning. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flow chart of the image character segmentation method of the present invention;
[0037] Figure 2 is an embodiment of the present invention;
[0038] Figure 3 is an embodiment of the present invention;
[0039] Figure 4 This is an embodiment of the present invention. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] Reference Figure 1 The present invention provides an image character segmentation method, comprising:
[0042] Acquire an image, and perform black-and-white binary processing on the image to obtain a black-and-white thresholded image;
[0043] A grid coordinate system is constructed on the black and white thresholded image, the traversal kernel size is set, an initial pixel point is selected on the grid coordinate system, and the traversal kernel traverses and detects along the Y axis from the initial pixel point until the first white pixel point is detected;
[0044] The traversal kernel starts from the first white pixel and traverses along the X-axis and Y-axis directions respectively until the first black pixel and the second black pixel are detected respectively;
[0045] The point formed by adding 1 pixel to the first white pixel on the X axis and subtracting 1 pixel on the Y axis is used as the first connectivity analysis point;
[0046] Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel is detected along the X-axis direction. If no white pixel is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel is the first inflection point;
[0047] If the first connectivity analysis point fails, the point formed by minus 1 pixel on the Y axis is used as the second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found;
[0048] Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point;
[0049] The detection starts from the second inflection point and traverses in the opposite direction of the X axis. If no white pixel is encountered during the detection process, the rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as the cutting boundary; if a white pixel is encountered during the detection process, the detection stops and the second inflection point is not passed;
[0050] When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
[0051] In this embodiment, after the image character data is obtained by cutting along the cutting boundary, the image character data is verified. If the verification passes, it is successful; if the verification fails, the traversal kernel size is adjusted to repeatedly traverse the cutting boundary until the verification passes.
[0052] Specifically, the verification methods include:
[0053] Compare the size and area of the image character data with the model font library. Cut characters with less than 50% area will not pass.
[0054] When the area exceeds 50%, a black and white pixel matching comparison is performed, and if the model font exceeds the threshold of 80%, the verification is passed.
[0055] In this embodiment, after the cut character data is obtained, the character data has two application scenarios: the first is to store the character data as the recognition model data; the second is to use the character data for similarity comparison and matching verification with the recognition model data;
[0056] The purpose of similarity comparison and matching verification is to make the recognition result more accurate by judging the similarity value. It is known that there is no such method on the market to verify whether the recognition result is correct. In the field of recognition, it is very important to verify the accuracy of the recognition result. The rules are as follows: first, the size of the cut characters is compared with the model font. The cut characters with an area of less than 50% are not suitable for pixel comparison with the current model font. In other words, no matter how the comparison is made, the similarity with the current model font is only 50% at most, and there is no need to perform pixel comparison. When the area exceeds 50%, black and white pixel matching can be performed. Assuming that the preset similarity threshold is 80%, after the black and white pixel comparison is completed, the model font that exceeds the threshold of 80% means that the recognition result is accurate. If you want a more accurate result, you can set the threshold above 95%. Through a large number of practical applications, it has been verified that the similarity threshold should be 85% as the best, which ensures the efficiency of pixel comparison and reduces the number of model fonts to reach a balance.
[0057] Furthermore, when the image character data is verified, the white pixels within the verified cutting boundary are changed to black pixels, and the traversal detection is restarted.
[0058] In this embodiment, the traversal kernel size can be adjusted from 1x1 pixel point, and can be flexibly adjusted according to the path size of the actual target area, and can be expanded to any size of pixels without limit. This traversal kernel can better adapt to target paths of different sizes and improve the detection precision and accuracy of the target area. Using the traversal kernel of custom size, this technology realizes the grouped cutting of the target area. By grouping the target area and merging scattered characters or targets into a whole, the target can be processed more conveniently as a whole, which improves the integrity and recognizability of the target area; at the same time, through the cutting operation, the target area can be separated from the background, which is convenient for subsequent analysis and recognition.
[0059] In this embodiment, the input image is subjected to black and white binary processing, that is, the color image is converted into a black and white binary image, that is, the RGB component values of each color are added and then averaged to obtain the mean value of the color, and then a threshold value (such as the default preset: 128) is used to determine whether the color is black (marked as 0) or white (marked as 1), thereby ensuring that the image characters can be effectively separated from the background. Example 1
[0060] Take the following "Multi-target image identification segmentation, and output image identification and coordinate range" process as an example, the cutting effect when the custom traversal kernel is 1*1 pixel size, such as Figure 2 shown. Example 2
[0061] Take the following process of "grouping and cutting words in multi-target images according to gap size, and outputting word characters and coordinate ranges" as an example, the cutting effect when the custom traversal kernel exceeds 1*1 pixel size, such as Figure 3 shown. Example 3
[0062] Take the following process of "segmenting characters with background interference, outputting characters and coordinate ranges, and retaining characters of a specified size" as an example, the effect of cutting when the custom traversal kernel is 1*1 pixel size and performing targeted size filtering on the resulting characters is as follows: Figure 4 shown.
[0063] The present invention also provides an image character segmentation system, comprising:
[0064] A processing module is used to acquire an image and perform black-and-white binary processing on the image to obtain a black-and-white thresholded image;
[0065] A traversal module is used to construct a grid coordinate system in the black and white threshold image, set the traversal kernel size, select an initial pixel point on the grid coordinate system, and the traversal kernel traverses and detects along the Y axis from the initial pixel point until the first white pixel point is detected;
[0066] The traversal kernel starts from the first white pixel and traverses along the X-axis and Y-axis directions respectively until the first black pixel and the second black pixel are detected respectively;
[0067] The point formed by adding 1 pixel to the first white pixel on the X axis and subtracting 1 pixel on the Y axis is used as the first connectivity analysis point;
[0068] Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel is detected along the X-axis direction. If no white pixel is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel is the first inflection point;
[0069] If the first connectivity analysis point fails, the point formed by minus 1 pixel on the Y axis is used as the second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found;
[0070] Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point;
[0071] The detection starts from the second inflection point and traverses in the opposite direction of the X axis. If no white pixel is encountered during the detection process, the rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as the cutting boundary; if a white pixel is encountered during the detection process, the detection stops and the second inflection point is not passed;
[0072] When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
[0073] The present invention also provides an electronic device, comprising at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the above method.
[0074] The present invention also provides a storage medium storing a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the above method.
[0075] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for image character segmentation, It is characterized in that include: Acquire an image, and perform black-and-white binarization processing on the image to obtain a black-and-white thresholded image; A grid coordinate system is constructed on the black-and-white thresholded image, a traversal kernel size is set, an initial pixel point is selected on the grid coordinate system, and the traversal kernel traverses and detects along the Y-axis direction from the initial pixel point until the first white pixel point is detected; The traversal core traverses and detects along the X-axis and Y-axis directions respectively from the first white pixel until the first black pixel and the second black pixel are detected respectively; The point formed by adding 1 pixel to the X-axis and subtracting 1 pixel from the Y-axis of the first white pixel is used as a first connectivity analysis point; Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel point is detected along the X-axis direction. If no white pixel point is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel point is the first inflection point; When the first connectivity analysis point fails, a point formed by subtracting 1 pixel from the Y axis is used as a second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found; Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is traversed and detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point; Starting from the second inflection point, traverse and detect in the reverse direction of the X axis. If no white pixel is encountered during the detection process, a rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as a cutting boundary; If a white pixel is encountered during the detection process, the detection stops and the second inflection point is not passed; When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
2. The image character segmentation method according to claim 1, It is characterized in that After cutting along the cutting boundary to obtain the image character data, the image character data is verified. If the verification passes, it is successful; if the verification fails, the traversal kernel size is adjusted to repeatedly traverse to obtain the cutting boundary until the verification passes.
3. The image character segmentation method according to claim 2, It is characterized in that Verification methods include: Comparing the size and area of the image character data with the model character library, and rejecting the cut characters with an area less than 50%; When the area exceeds 50%, a black and white pixel matching comparison is performed, and if the model font exceeds the threshold of 80%, the verification is passed.
4. The image character segmentation method according to claim 3, It is characterized in that When the image character data is verified, the white pixels within the verified cutting boundary are changed to black pixels, and the traversal detection is restarted.
5. The image character segmentation method according to claim 1, It is characterized in that The black-and-white binary processing of the image includes: adding the RGB component values of each color and averaging to obtain the mean value of the color, and then using a threshold to determine whether the color is black, marked as 0, or white, marked as 1.
6. An image character segmentation system, It is characterized in that include: A processing module, used for acquiring an image, and performing black-and-white binary processing on the image to obtain a black-and-white thresholded image; A traversal module is used to construct a grid coordinate system in the black and white thresholded image, set a traversal kernel size, select an initial pixel point on the grid coordinate system, and the traversal kernel traverses and detects along the Y axis direction from the initial pixel point until the first white pixel point is detected; The traversal core traverses and detects along the X-axis and Y-axis directions respectively from the first white pixel until the first black pixel and the second black pixel are detected respectively; The point formed by adding 1 pixel to the X-axis and subtracting 1 pixel from the Y-axis of the first white pixel is used as a first connectivity analysis point; Starting from the first connectivity analysis point, the X-axis coordinate value of the first black pixel point is detected along the X-axis direction. If no white pixel point is encountered during the detection process, the point formed by the Y-axis coordinate value of the first connectivity analysis point and the X-axis coordinate value of the first black pixel point is the first inflection point; When the first connectivity analysis point fails, a point formed by subtracting 1 pixel from the Y axis is used as a second connectivity analysis point, and the iterative judgment is repeated until no white pixel is encountered during the detection process and the first inflection point is found; Starting from the first inflection point, the Y-axis coordinate value of the second black pixel point is traversed and detected along the Y-axis direction. If no white pixel point is encountered during the detection process, the point formed by the X-axis coordinate value of the first inflection point and the Y-axis coordinate value of the second black pixel point is the second inflection point; Starting from the second inflection point, traverse and detect in the reverse direction of the X axis. If no white pixel is encountered during the detection process, a rectangle formed by the first inflection point, the second inflection point and the second black pixel is used as a cutting boundary; If a white pixel is encountered during the detection process, the detection stops and the second inflection point is not passed; When the second inflection point is not passed, the point formed by adding 1 pixel on the Y axis is used as the third inflection point. At the same time, the second black pixel point is added 1 pixel on the Y axis to form a boundary point corresponding to the third inflection point. Repeat the iterative judgment until no white pixel point is encountered during the detection process and the cutting boundary is found.
7. An electronic device, It is characterized in that The method comprises at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the method according to any one of claims 1 to 5.
8. A storage medium, It is characterized in that It stores a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the method described in any one of claims 1 to 5.
