Image recognition method and device, computer device and computer readable storage medium
By segmenting the image, converting its color, and matching its features, the problem of not being able to recognize dot matrix characters and needle-like characters in existing technologies has been solved, and accurate recognition of these characters has been achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHANGSHA XIONGDI XINAN TECH CO LTD
- Filing Date
- 2023-04-12
- Publication Date
- 2026-06-26
AI Technical Summary
Existing recognition devices cannot effectively recognize highly distinctive dot matrix characters or pin-shaped characters, especially pinhole-style ID photos such as passports, resulting in character recognition failure.
The first target image is obtained by recognizing the image to be processed, which is then divided into multiple second target images. The colors of these images are recognized and converted, and color mapping is performed using a preset feature table. Finally, feature matching is performed with a preset character template to determine the target character.
It achieves accurate recognition of dot matrix characters and needle-like characters, improving the accuracy and efficiency of character recognition.
Smart Images

Figure CN116469105B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to an image recognition method, apparatus, computer device, and computer-readable storage medium. Background Technology
[0002] With the rapid development of technology, image recognition has gradually become a key technology applied in many fields such as automatic control and automated production. It can not only accelerate the processing of tedious tasks, but also process images faster or more accurately than manual image inspection. For example, in the field of document production equipment, the equipment needs to efficiently and accurately identify document numbers.
[0003] Existing recognition devices mainly use text recognition technology, which is often based on font matching. They cannot recognize characters with strong uniqueness, such as dot matrix characters or pin-shaped characters, and therefore cannot recognize characters in pinhole-type ID photos such as passports. Summary of the Invention
[0004] In view of this, one of the objectives of this application is to provide an image recognition method, apparatus, computer device, and computer-readable storage medium that can at least solve some of the above-mentioned technical problems.
[0005] In a first aspect, embodiments of this application provide an image recognition method, the method comprising:
[0006] A first target image is obtained by recognizing the image to be processed. The first target image includes a character region to be recognized, and the character region to be recognized includes at least one character to be recognized.
[0007] The first target image is segmented to obtain at least two second target images, each of which includes the character to be identified;
[0008] The colors of all second target images are identified, and each second target image is color-converted based on its color and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes color, identifier, and the mapping relationship between the color and the identifier.
[0009] The matrix image corresponding to each second target image is matched with the preset character template to determine the target character of each second target image.
[0010] In one possible implementation, the step of identifying the image to be processed to obtain the first target image includes:
[0011] Obtain the first feature points of the image to be processed, and determine the region of characters to be recognized based on the first feature points;
[0012] Identify the central region of the character region to be identified;
[0013] The first feature point on the edge region of the character region to be identified is extended by a preset distance away from the center region to obtain the first intermediate image;
[0014] The first target image is obtained by tilting the first intermediate image based on the first feature point.
[0015] In one possible implementation, the step of obtaining the first target image by tilt correction of the first intermediate image based on the first feature point includes:
[0016] The first intermediate image is binarized and dilated sequentially to obtain the second intermediate image;
[0017] The target feature points are obtained by traversing the pixels of the second intermediate image in a first direction and / or a second direction, wherein the first direction and the second direction are perpendicular.
[0018] The first intermediate image is corrected based on the target feature points to obtain the corrected first intermediate image;
[0019] The first target image is obtained by performing a preset redundancy removal process on the corrected first intermediate image.
[0020] In one possible implementation, the step of performing a preset redundancy removal process on the corrected first intermediate image to obtain the first target image includes:
[0021] The corrected first intermediate image is sequentially binarized and dilated to obtain the third intermediate image;
[0022] Traverse the pixels of the third intermediate image in a third and / or fourth direction, and calculate the sum of pixels in each column or row;
[0023] Traverse the pixels of the third intermediate image in the fifth and / or sixth directions, and calculate the sum of pixels in each row or column;
[0024] The first and second boundaries are determined based on the sum of the pixels in each row, and the third and fourth boundaries are determined based on the sum of the pixels in each column.
[0025] The target character region of the first intermediate image is determined based on the first boundary, the second boundary, the third boundary, and the fourth boundary;
[0026] Identify the central region of the target character region, and extend the first boundary, second boundary, third boundary, and fourth boundary of the target character region on the corrected first intermediate image by a first preset number of pixels in a direction away from the central region of the target character region, thereby determining the first target image.
[0027] In one possible implementation, segmenting the first target image to obtain at least two second target images includes:
[0028] The first target image is divided into at least two fourth intermediate images by a preset interval;
[0029] The fourth intermediate image is sequentially binarized and eroded to obtain at least two second target images.
[0030] In one possible implementation, identifying the colors of the entire second target image includes:
[0031] The second target image is divided into a second preset number of target sub-images;
[0032] The colors of target sub-images that meet the preset conditions are modified to the first color, and the colors of target sub-images that do not meet the preset conditions are modified to the second color, thus obtaining the colors of all second target images.
[0033] In one possible implementation, the preset conditions include: the number of rows containing pixels of the target color is greater than or equal to a preset value, or the number of columns containing pixels of the target color is greater than or equal to the preset value.
[0034] Secondly, embodiments of this application provide an image recognition device, comprising:
[0035] A first recognition module is used to recognize an image to be processed to obtain a first target image, the first target image including a character region to be recognized, the character region to be recognized including at least one character to be recognized;
[0036] The segmentation module is used to segment the first target image to obtain at least two second target images, each of which includes the character to be identified;
[0037] The second recognition module is used to recognize the colors of all second target images, and to perform color conversion on each second target image based on the color of each second target image and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes color, identifier, and the mapping relationship between the color and the identifier.
[0038] The matching module is used to perform feature matching between the matrix image corresponding to each second target image and the preset character template to determine the target character of each second target image.
[0039] Thirdly, embodiments of this application provide a computer device, which includes a memory and a processor. The memory stores a computer program, and when the computer program is executed by the processor, it implements the image recognition method provided in the first aspect.
[0040] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by one or more processors, implements the image recognition method provided in the first aspect.
[0041] The image recognition method provided in this application obtains a first target image by recognizing an image to be processed. The first target image includes a character region to be recognized, which includes at least one character to be recognized. Then, the first target image is segmented to obtain at least two second target images, each of which includes a character to be recognized. Next, the colors of all the second target images are recognized, and the colors of each second target image are converted based on the colors of each second target image and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes colors, characters, and the mapping relationship between colors and characters. Finally, the matrix images corresponding to each second target image are matched with a preset character template to determine the target character of each second target image. This method can accurately recognize dot matrix characters or needle-like characters. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. It should be understood that the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 A flowchart of an image recognition method provided in this application embodiment;
[0044] Figure 2 The image to be processed is included in an image recognition method provided in this application embodiment;
[0045] Figure 3 A schematic diagram illustrating the correction process involved in an image recognition method provided in an embodiment of this application;
[0046] Figure 4This is a schematic diagram of a preset character template involved in an image recognition method provided in an embodiment of this application;
[0047] Figure 5 This is a schematic diagram of a second intermediate image included in an image recognition method provided in an embodiment of this application;
[0048] Figure 6 A schematic diagram of a Cartesian coordinate system involved in an image recognition method provided in an embodiment of this application;
[0049] Figure 7 A schematic diagram illustrating the preset redundancy removal process included in an image recognition method provided in an embodiment of this application;
[0050] Figure 8 This is a schematic diagram of image segmentation included in an image recognition method provided in an embodiment of this application;
[0051] Figure 9 This is a schematic diagram illustrating the color recognition process of a second target image included in an image recognition method provided in an embodiment of this application;
[0052] Figure 10 This is a schematic diagram illustrating the color conversion process of a second target image included in an image recognition method provided in an embodiment of this application;
[0053] Figure 11 This is a schematic diagram of the functional modules of an image recognition device provided in an embodiment of this application;
[0054] Figure 12 This is a diagram illustrating the internal structure of a computer device as provided in an embodiment of this application. Detailed Implementation
[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0057] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0058] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0059] In various embodiments of this application, the expression "or" or "at least one of A and / or B" includes any combination or all combinations of the words listed simultaneously. For example, the expression "A or B" or "at least one of A and / or B" may include A, may include B, or may include both A and B.
[0060] In the description of this application, it should be noted that if terms such as "upper," "lower," "inner," or "outer" are used to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of the invention is usually placed during use, they are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.
[0061] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0062] It should be noted that, where there is no conflict, the features in the embodiments of this application can be combined with each other.
[0063] Please see Figure 1 , Figure 1 This is a flowchart of an image recognition method provided in an embodiment of this application. The steps of the method will be described in detail below.
[0064] S110, identify the image to be processed to obtain a first target image, the first target image includes a character region to be identified, the character region to be identified includes at least one character to be identified.
[0065] In this embodiment, the image to be processed can be identified by a document production device, or it can be identified by a computer device as described in the following embodiments. The computer device includes the aforementioned document production device, smartphones, and laptops, among other intelligent devices capable of image recognition processing. The image to be identified can be an image initially acquired by an external image acquisition device such as a camera. This can be understood as an image that has not undergone any image processing steps such as detection, recognition, or cropping. However, the image to be identified includes a region of characters to be identified; in other words, the image acquisition device, such as a camera, can capture an image that includes the complete region of characters to be identified.
[0066] When an image acquisition device, such as a camera, can capture an image containing the complete region of the character to be recognized, further processing of the image is needed to determine a rough image containing the region of the character to be recognized, that is, to determine the first target image in this embodiment. In the subsequent character recognition process, this helps to reduce the image area that needs to be recognized and improve the efficiency of character recognition.
[0067] The character to be identified can be composed of multiple dots. It should be noted that the character to be identified in this embodiment is characterized by non-continuous dots with a certain interval. For example, the pinhole serial number on a passport can be used as a reference. This is different from using general recognition algorithms to identify characters composed of continuous dots, such as license plates and station screens.
[0068] In one possible implementation, identifying the image to be processed to obtain a first target image includes:
[0069] Obtain the first feature point of the image to be processed, and determine the region of characters to be recognized based on the first feature point;
[0070] Identify the central region of the area containing the character to be identified;
[0071] The first feature point on the edge region of the character region to be recognized is extended by a preset distance away from the center region to obtain the first intermediate image;
[0072] The first target image is obtained by tilting the first intermediate image based on the first feature point.
[0073] Specifically, the first feature point can be a point that makes up the character to be identified. Generally, the characters to be identified obtained through the above embodiments are usually pinhole-like characters, such as the number on a passport, which are characters arranged in a relatively standardized manner. The characters to be identified obtained through the above embodiments are usually one or more rows, one or more columns. After identifying the points of these characters to be identified, four first feature points with the greatest distance between them can be selected from each of two rows or two columns. The rectangular area formed by these four first feature points is the character area to be identified, which includes all the characters to be identified.
[0074] Next, by extending the four first feature points to the center area away from the region of the character to be recognized by a preset distance, the first intermediate image can be obtained. Extending the four first feature points by a preset distance can avoid the situation where the first intermediate image contains incomplete characters due to misidentification of the characters to be recognized, thus ensuring the integrity of the characters to be recognized and improving the effectiveness and accuracy of character recognition. The preset distance can be 1cm, 5cm or 10cm, which can be selected according to specific needs.
[0075] For example, please see Figure 2 , Figure 2 The image to be processed included in the image recognition method provided in this application embodiment, wherein points A1, A2, A3, and A4 correspond to the four first feature points mentioned above. Extending these four first feature points a preset distance away from the center region of the character to be recognized yields the following result: Figure 3 The first intermediate image shown in Figure (a) is... Figure 3 This is a schematic diagram of the correction process involved in an image recognition method provided in an embodiment of this application, wherein, Figure 3 Figure (b) is the second intermediate image. Figure 3 Figure (c) in the image is the first intermediate image after correction.
[0076] In some embodiments, when the above four first feature points are determined and there are two pairs of first feature points in the same row or column, the central region of the character region to be identified may not be identified. Instead, two feature points in a row or column containing the four first feature points are extended by a preset distance in their respective directions to obtain a first intermediate image. This reduces the process of determining the central region of the character region to be identified and further improves the character recognition efficiency.
[0077] Considering that the position of the image acquisition device is generally fixed during the process of acquiring the image to be recognized through the specific image acquisition device, the fixed position of the image acquisition device corresponds to a fixed placement area, where the placement area can be used to place the item to be photographed, such as a passport, a passport copy, or other documents containing pinhole characters.
[0078] In some embodiments, the orbital position of an image acquisition device, such as a camera, and the camera's shooting angle can be obtained, and a first intermediate image can be determined from the image to be identified based on the orbital position and the shooting angle.
[0079] Considering that the image to be recognized may be tilted due to the mechanical movement of the image acquisition device or the shooting angle of the camera of the image acquisition device, the above embodiments all need to perform tilt correction on the first intermediate image after obtaining the first intermediate image to obtain the first target image. Based on the tilt-corrected first target image, characters can be further recognized, which can significantly improve the accuracy of character recognition.
[0080] S120, the first target image is segmented to obtain at least two second target images, each of which includes the character to be identified.
[0081] In this embodiment, the first target image includes a character to be identified. The first target image needs to be segmented to facilitate character recognition of each segmented second target image. Generally, the segmented second target image contains only one character to be identified, which facilitates the identification of a single character and improves the accuracy of character recognition.
[0082] S130, identify the colors of all second target images, and perform color conversion on each second target image based on the color of each second target image and a preset feature table to obtain a matrix image corresponding to each second target image, wherein the preset feature table includes color, identifier, and the mapping relationship between the color and the identifier.
[0083] In this embodiment, each second target image contains a character to be identified, and the processed second target image includes two colors: black and white. Taking black and white as an example, the preset feature table includes black, white, and a symbol, as well as the mapping relationship between black, white, and the symbol. Here, the Arabic numerals 0 and 1 are used as symbols for example. There is a mapping relationship between black and the Arabic numeral 0, and a mapping relationship between white and the Arabic numeral 1. The Arabic numerals corresponding to each second target image can be determined by the preset feature table to obtain the matrix image corresponding to each second target image. If the Arabic numerals 0 and 1 are used as an example, the result in this embodiment is a matrix image of the numbers corresponding to the second target images.
[0084] It should be noted that the identifiers in the preset feature table include at least one of graphics, English letters and Arabic numerals. For ease of identification, Arabic numerals 0 and 1, English letters O and I, and triangles and squares in graphics can be used. The identifiers in this embodiment are examples that can be distinguished and are not limited to Arabic numerals in the above examples. Other combinations of English letters or images are within the protection scope of this application.
[0085] In addition, identifying the color of the second target image involves uniformly dividing the second target image into regions, then identifying the color of each region in each second target image, thereby determining the color of each second target image.
[0086] S140, perform feature matching between the matrix image corresponding to each second target image and the preset character template to determine the target character of each second target image.
[0087] The preset character template in this embodiment includes at least one of the pre-trained number template, English letter template, and graphic template. The template type of the preset character template can be specifically set according to the type of the identifier in the preset feature table in the above embodiment. For example, if the identifier is Arabic numeral 0 and 1, the preset character template is a number template including Arabic numeral 0 and 1. If the identifier is English letter O and I, the preset character template is an English letter template including English letter O and I.
[0088] Specifically, before character recognition, the above embodiments can convert the accurately recognized characters into a number matrix, an English letter matrix, and an image matrix. For example, if the identifiers in the preset feature table are Arabic numerals 0 and 1, then the accurately recognized characters are converted into a number matrix to obtain a preset character template. The converted preset character template is actually an image. For ease of description, feature matching is performed between the matrix image corresponding to the second target image and the preset character template. Feature matching primarily involves matching Arabic numerals 0 and 1.
[0089] Considering the importance of preset character templates in character recognition, in order to ensure the accuracy of preset character templates, in some embodiments, for the same preset character template, it is necessary to perform digital matrix conversion on at least ten characters that have been accurately identified and are the same character, and then compare them one by one, and take the digital template with the highest character comparison accuracy as the preset character template for that character.
[0090] For an example of a digital template, please see Figure 4 , Figure 4 This is a schematic diagram of a preset character template involved in an image recognition method provided in an embodiment of this application. It can be clearly seen that the diagram includes the characters 1, L, 2, and N. Figure 4 The image shown is only a partial representation of the preset character templates.
[0091] As can be seen from the above analysis, the image recognition method provided in this application embodiment obtains a first target image by recognizing the image to be processed, which includes the region of the character to be recognized. Then, the first target image is segmented to obtain a second target image including the character to be recognized. The second target image is color-converted to obtain a matrix image of the second target image. Finally, the target character of each second target image is determined by feature matching between the matrix image of the second target image and a preset character template, thus completing the character recognition. It can accurately recognize dot matrix characters or needle-like characters. Furthermore, the character recognition process also includes character correction operations, which further improves the accuracy of character recognition.
[0092] Considering that there may be redundant parts in the image during the tilt correction process, which will affect the accuracy of character recognition.
[0093] In one possible implementation, the first target image is obtained by tilt correction of the first intermediate image based on the first feature points, including:
[0094] The first intermediate image is binarized and dilated sequentially to obtain the second intermediate image;
[0095] The target feature points are obtained by traversing the pixels of the second intermediate image in the first direction and / or the second direction, wherein the first direction and the second direction are perpendicular.
[0096] The first intermediate image is corrected based on the target feature points to obtain the corrected first intermediate image;
[0097] The first target image is obtained by performing preset redundancy removal processing on the corrected first intermediate image.
[0098] This embodiment includes a specific image correction operation and an operation for removing redundancy from an image.
[0099] During the image correction process, binarization is performed on the first intermediate image. This highlights the first feature point mentioned in the above embodiments and removes interference from other colors. The first feature point is a point that can form dot matrix characters and / or needle-like characters. Dilation processing can be understood as dilating the first feature point highlighted by binarization, which helps to determine the overall character region and improve correction accuracy.
[0100] Specifically, a Cartesian coordinate system is established with one of the four vertices of the second intermediate image as the origin. If the first direction is the x-axis and the second direction is the y-axis, and vice versa, the pixels of the second intermediate image are traversed along the x-axis and y-axis according to the Cartesian coordinate system. The target feature point is a white pixel. The pixel value corresponding to the two endpoints of a row or column during the first traversal is set to 255, which means that the two endpoints of a row or column during the first traversal correspond to white pixels. The two endpoints of a row or column can be used as the target feature point. The rotation angle is calculated based on the target feature point and the first or second direction. The first intermediate image is then subjected to an affine transformation based on the obtained rotation angle to obtain the corrected first intermediate image.
[0101] In this affine transformation, the angle between the vertical axis (y-axis) and the row in a Cartesian coordinate system, representing the two endpoints of a row, is the rotation angle. Similarly, the angle between the horizontal axis (x-axis) and the column in a Cartesian coordinate system, representing the two endpoints of a column, is the rotation angle. The specific affine transformation process can be referenced from conventional affine transformation methods.
[0102] For example, please see Figure 5 , Figure 5 This is a schematic diagram of a second intermediate image included in an image recognition method provided in an embodiment of this application. O1 and O2 are the two endpoints of the image. A Cartesian coordinate system is established on these two endpoints to obtain coordinate system O1X1Y1 and coordinate system O2X2Y2. Schematic diagrams of the two coordinate systems can be found in [reference needed]. Figure 6 , Figure 6 This is a schematic diagram of a Cartesian coordinate system involved in an image recognition method provided in this application embodiment. In this embodiment, the second intermediate image can be traversed along the X1 and Y1 directions based on the origin O1 to determine target feature points P1 and P2. Connecting the two points yields line segment P1P2, and the angle between line segment P1P2 and Y1 is the rotation angle in this embodiment. Based on this rotation angle, the correction of the first intermediate image can be completed. If the determined rotation angle is 90 degrees, it indicates that P1 and point P2 are on the same horizontal line. In this case, there is no need to correct the first intermediate image.
[0103] In some embodiments, the target feature points P1 and P2 can be determined by traversing from both ends of the second intermediate image along a first direction and / or a second direction. Specifically, while traversing the second intermediate image along the X1 and Y1 directions based on the origin O1, the target feature points P1 and P2 can be determined based on... Figure 6 By traversing the second intermediate image along the X2 and Y2 directions from the origin O2, the target feature points P1 and P2 can be quickly determined, further improving the efficiency of character recognition.
[0104] In the process of redundancy removal from the image, that is, in the process of performing preset redundancy removal processing on the corrected first intermediate image, optionally, the first target image is obtained by performing preset redundancy removal processing on the corrected first intermediate image, including:
[0105] The corrected first intermediate image is binarized and dilated sequentially to obtain the third intermediate image;
[0106] Traverse the pixels of the third intermediate image in the third and / or fourth directions, and calculate the pixel sum of each column or row of pixels;
[0107] Traverse the pixels of the third intermediate image in the fifth and / or sixth directions, and calculate the sum of pixels in each row or column;
[0108] The first and second boundaries are determined based on the sum of the pixels in each row, and the third and fourth boundaries are determined based on the sum of the pixels in each column.
[0109] The target character region of the first intermediate image is determined based on the first boundary, the second boundary, the third boundary, and the fourth boundary;
[0110] Identify the central region of the target character region, and extend the first, second, third, and fourth boundaries of the target character region toward the central region of the target character region by a first preset number of pixels on the corrected first intermediate image to determine the first target image.
[0111] In this embodiment, the specific method for traversing the pixels of the third intermediate image according to the third, fourth, fifth, and sixth directions can refer to the method of establishing a Cartesian coordinate system in the above embodiment, and will not be repeated here.
[0112] Specifically, calculating the pixel sum of each column or row of pixels can determine the row or column where white pixels appear. The third intermediate image is obtained by binarizing and dilating the first intermediate image. The first feature point corresponding to the character in the above embodiment is white, and its color remains white after dilation. The pixel value of a white pixel is 255, the color of the area outside the white character is black, and the pixel value of a black pixel is 0. By traversing and calculating the pixel sum of each row or column of pixels, the first boundary, second boundary, third boundary, and fourth boundary can be determined. Based on these four boundaries, the target character region can be accurately determined. After determining the target character region, the above four directions are extended by a first preset number of pixels away from the center region of the target character region to obtain the first target image.
[0113] The first preset number of pixels can be 5 pixels or 10 pixels, depending on the specific situation. Expanding the first preset number of pixels can ensure that all characters are included.
[0114] In some embodiments, after binarizing and dilating the corrected first intermediate image to obtain the third intermediate image, the non-black border regions in the third intermediate image can be directly segmented.
[0115] In this embodiment, the method of identifying the central region of the target character region and extending the four boundaries in a direction away from the central region of the target character region on the corrected first intermediate image can refer to the process of identifying the central region of the character region to be identified and finally obtaining the first intermediate image in the above embodiment, and will not be repeated here.
[0116] To clearly demonstrate the detailed process of obtaining the first target image by performing preset redundancy removal processing on the corrected first intermediate image in this embodiment, please refer to the example provided. Figure 7 , Figure 7 This is a schematic diagram of the preset redundancy removal process included in an image recognition method provided in this application embodiment. The corrected first intermediate image is sequentially binarized and dilated to obtain the image as shown below. Figure 7 The third intermediate image shown in Figure (a) is then cropped to obtain the non-black border area. Figure 7 Figure (b) in the middle, and then based on Figure 7 Figure (b) defines the first, second, third, and fourth boundaries. After expansion, four new boundaries are obtained. Figure 7 In Figure (c), the first intermediate image after correction is segmented according to the new four boundaries, resulting in the following: Figure 8 The first target image shown in Figure (a).
[0117] The traversal method in this embodiment can be referred to Figure 5 The traversal method will not be elaborated here; this embodiment will use... Figure 5 The difference lies in calculating the pixel value of a certain row or column during traversal. In this embodiment, it is calculated from... Figure 7 The traversal begins from the four endpoints of graph (b) in the diagram.
[0118] Please see Figure 8 , Figure 8 This is a schematic diagram of image segmentation included in an image recognition method provided in an embodiment of this application, wherein... Figure 8 Figure (a) is the first target image obtained through the above embodiments. Figure 8 Image (b) in the figure is a collection of images of the second target obtained after segmentation, binarization and erosion.
[0119] In one possible implementation, the first target image is segmented to obtain at least two second target images, including:
[0120] The first target image is segmented at a preset interval to obtain at least two fourth intermediate images;
[0121] The fourth intermediate image is binarized and eroded sequentially to obtain at least two second target images.
[0122] Specifically, the preset spacing is generally set to be a few pixels wider than the width of the character to be recognized. This can avoid segmenting the same character during segmentation. Considering that the color of the second target image can be directly recognized, the fourth intermediate image in this embodiment is binarized and eroded. Binarization allows the image to include only black and white, which also makes it easier to recognize the first feature point mentioned in the above embodiment. The erosion process mainly targets the recognized first feature point, which can eliminate the boundary points of the first feature point and shrink the boundary inward, thus highlighting the first feature point and improving the accuracy of character recognition.
[0123] In one possible implementation, identifying the colors of the entire second target image includes:
[0124] The second target image is divided into a second preset number of target sub-images;
[0125] The colors of target sub-images that meet the preset conditions are changed to the first color, and the colors of target sub-images that do not meet the preset conditions are changed to the second color, thus obtaining the colors of all second target images.
[0126] In this embodiment, each second target image can be divided into a second preset number of target sub-images. If the second preset number of target sub-images cannot be obtained after division, for this type of second target image, the central region of the second target image can be divided into equal parts first, and the other regions can be segmented to obtain the second preset number of target sub-images. The first color is white and the second color is black.
[0127] Optionally, preset conditions include: the number of rows containing pixels of the target color is greater than or equal to a preset value, or the number of columns containing pixels of the target color is greater than a preset value.
[0128] In this embodiment, the preset value is 1, and the target color is white. This can be understood as follows: if the number of rows or columns of white pixels in a target sub-image is greater than or equal to 1, the color of that target sub-image can be changed to white. Regarding passport number recognition, multiple studies have found that in actual printed passport numbers, even-numbered rows are white. Therefore, when recognizing passport numbers, the preset conditions could include: the number of rows containing the target color pixels is not even, and the number of rows and / or columns containing the target color pixels is greater than or equal to a preset value.
[0129] To clearly demonstrate the process of identifying the colors of the entire second target image, please refer to [link / reference]. Figure 9 , Figure 9 This is a schematic diagram of the color recognition process of a second target image included in an image recognition method provided in an embodiment of this application.
[0130] Taking a second target image as an example, the second target image can be divided according to its width and height. The illustration shows that the second target image is divided into 63 target sub-images, each with a height of 7*9. Figure 9 In the diagram, ① represents the first target sub-image after the second target image is divided into equal parts, and ② represents the second target sub-image after the second target image is divided into equal parts. Then, the colors of a total of 63 target sub-images are determined in sequence, and then the color of the second target image in the figure is determined. By analogy, the colors of all second target images can be determined.
[0131] Please see Figure 10 , Figure 10 This is a schematic diagram illustrating the color conversion process of the second target image included in an image recognition method provided in an embodiment of this application. Figure 10 Figure (a) shows a second target image with its color already determined. Figure 10 Figure (b) shows the matrix image obtained by color conversion of the second target image, where... Figure 10 In Figure (a), the number 255 within the white box represents the pixel value of the color corresponding to the white box, while the number 0 within the black box represents the pixel value of the color corresponding to the black box. (Continuing with...) Figure 9 In the example of the second target image, after determining the color of the illustrated second target image, taking a digital matrix as an example, color conversion can be performed according to the preset feature table in the above embodiment to obtain, as shown below. Figure 10 The digital matrix shown in Figure (b) is the matrix image corresponding to the second target image. Then, feature matching with the preset character template can determine the target character in the second target image. Obviously, the target character shown in the figure is the uppercase English letter "B". The same method can be used to complete the recognition of all target characters in the second target image.
[0132] In summary, the image recognition method provided in this application obtains a first target image by recognizing an image containing a region of characters to be recognized, then segments the first target image to obtain a second target image containing characters to be recognized, performs color conversion on the second target image to obtain a matrix image of the second target image, and finally determines the target characters of each second target image by feature matching between the matrix image of the second target image and a preset character template, thus completing character recognition. This method can accurately recognize dot matrix characters or needle-like characters, and also performs character correction operations during the character recognition process, further improving the accuracy of character recognition.
[0133] Corresponding to the above method embodiments, this application also provides an image recognition device, please refer to [link to relevant documentation]. Figure 11 , Figure 11 This is a functional module diagram of an image recognition device 100 provided in an embodiment of this application.
[0134] The first recognition module 110 is used to recognize the image to be processed to obtain a first target image. The first target image includes a character region to be recognized, and the character region to be recognized includes at least one character to be recognized.
[0135] The segmentation module 120 is used to segment the first target image to obtain at least two second target images, each of which includes the character to be recognized;
[0136] The second recognition module 130 is used to recognize the colors of all second target images, and to perform color conversion on each second target image based on the color of each second target image and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes color, identifier, and the mapping relationship between color and identifier.
[0137] The matching module 140 is used to perform feature matching between the matrix image corresponding to each second target image and the preset character template to determine the target character of each second target image.
[0138] The image recognition device provided in this application identifies a first target image by a first recognition module, wherein the first target image includes a character region to be recognized, and the character region includes at least one character to be recognized. Then, the first target image is segmented by a segmentation module to obtain at least two second target images, wherein each second target image includes a character to be recognized. Then, the colors of all second target images are identified by a second recognition module, and the colors of each second target image are converted based on the colors of each second target image and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes colors, characters, and the mapping relationship between colors and characters. Finally, the matrix image corresponding to each second target image is matched with a preset character template by a matching module to determine the target character of each second target image, which can accurately recognize dot matrix characters or needle-like characters.
[0139] This application also provides a computer device; please refer to [link to relevant documentation]. Figure 12 , Figure 12 This is a diagram illustrating the internal structure of a computer device according to an embodiment of this application. The computer device includes a processor, a memory, and a network interface connected via a system bus. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and may also store a computer program. When executed by the processor, this computer program enables the processor to implement the image recognition method applied to the computer device in the above embodiments. The internal memory may also store a computer program, which, when executed by the processor, enables the processor to perform the image recognition method. Those skilled in the art will understand that… Figure 12 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0140] This application also discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the image recognition method as described in the method embodiments.
[0141] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0142] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. An image recognition method, characterized in that, The method for recognizing dot matrix characters or needle-like characters includes: A first target image is obtained by recognizing the image to be processed. The first target image includes a character region to be recognized, and the character region to be recognized includes at least one character to be recognized. The first target image is segmented to obtain at least two second target images, each of which includes the character to be identified; The colors of all second target images are identified, and each second target image is color-converted based on its color and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes color, identifier, and the mapping relationship between the color and the identifier. The identification of the colors of all second target images includes: The second target image is divided into a second preset number of target sub-images; The color of the target sub-image that meets the preset conditions is modified to the first color, and the color of the target sub-image that does not meet the preset conditions is modified to the second color, so as to obtain the color of all the second target images; the preset conditions include: the number of rows of pixels with the target color is not even and the number of rows and / or columns of pixels with the target color is greater than or equal to a preset value. The matrix image corresponding to each second target image is matched with the preset character template to determine the target character of each second target image.
2. The image recognition method as described in claim 1, characterized in that, The process of identifying the image to be processed to obtain the first target image includes: Obtain the first feature points of the image to be processed, and determine the region of characters to be recognized based on the first feature points; Identify the central region of the character region to be identified; The first feature point on the edge region of the character region to be identified is extended by a preset distance away from the center region to obtain a first intermediate image; The first target image is obtained by tilting the first intermediate image based on the first feature point.
3. The image recognition method as described in claim 2, characterized in that, The step of obtaining the first target image by tilt correction of the first intermediate image based on the first feature points includes: The first intermediate image is binarized and dilated sequentially to obtain the second intermediate image; The target feature points are obtained by traversing the pixels of the second intermediate image in a first direction and / or a second direction, wherein the first direction and the second direction are perpendicular. The first intermediate image is corrected based on the target feature points to obtain the corrected first intermediate image; The first target image is obtained by performing a preset redundancy removal process on the corrected first intermediate image.
4. The image recognition method as described in claim 3, characterized in that, The step of performing a preset redundancy removal process on the corrected first intermediate image to obtain the first target image includes: The corrected first intermediate image is sequentially binarized and dilated to obtain the third intermediate image; Traverse the pixels of the third intermediate image in a third and / or fourth direction, and calculate the sum of pixels in each column or row; Traverse the pixels of the third intermediate image in the fifth and / or sixth directions, and calculate the sum of pixels in each row or column; The first and second boundaries are determined based on the sum of the pixels in each row, and the third and fourth boundaries are determined based on the sum of the pixels in each column. The target character region of the first intermediate image is determined based on the first boundary, the second boundary, the third boundary, and the fourth boundary; Identify the central region of the target character region, and extend the first boundary, second boundary, third boundary, and fourth boundary of the target character region on the corrected first intermediate image by a first preset number of pixels in a direction away from the central region of the target character region, thereby determining the first target image.
5. The image recognition method as described in claim 1, characterized in that, The step of segmenting the first target image to obtain at least two second target images includes: The first target image is divided into at least two fourth intermediate images by a preset interval; The fourth intermediate image is sequentially binarized and eroded to obtain at least two second target images.
6. An image recognition device, characterized in that, The image recognition device is used to identify dot matrix characters or needle-like characters. A first recognition module is used to recognize an image to be processed to obtain a first target image, the first target image including a character region to be recognized, the character region to be recognized including at least one character to be recognized; The segmentation module is used to segment the first target image to obtain at least two second target images, each of which includes the character to be identified; The second recognition module is used to recognize the colors of all second target images, and to perform color conversion on each second target image based on its color and a preset feature table to obtain a matrix image corresponding to each second target image. The preset feature table includes colors, identifiers, and a mapping relationship between the colors and the identifiers. Recognizing the colors of all second target images includes: The second target image is divided into a second preset number of target sub-images; The color of the target sub-image that meets the preset conditions is modified to the first color, and the color of the target sub-image that does not meet the preset conditions is modified to the second color, so as to obtain the color of all the second target images; the preset conditions include: the number of rows of pixels with the target color is not even and the number of rows and / or columns of pixels with the target color is greater than or equal to a preset value. The matching module is used to perform feature matching between the matrix image corresponding to each second target image and the preset character template to determine the target character of each second target image.
7. A computer device, characterized in that, The computer device includes a memory and a processor. The memory stores a computer program, which, when executed by the processor, implements the image recognition method according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by one or more processors, implements the image recognition method according to any one of claims 1-5.