Text direction recognition method, device and equipment and storage medium
By enhancing the training grayscale images and adjusting the detection network parameters, combined with the rotation angle of the target region, the accuracy problem of text direction recognition was solved, and efficient text direction recognition was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-18
- Publication Date
- 2026-03-20
AI Technical Summary
Existing text orientation recognition methods cannot accurately identify text orientation due to image transformations.
By performing image enhancement processing on the training grayscale image, adjusting the preset detection network parameters, generating a text detection model, and performing grayscale processing and segmentation on the text image to be detected, the text direction is generated by combining the rotation angles of multiple target regions.
It improves the generalization ability of the text detection model, avoids elastic deformation of text regions, and ensures accurate identification of text direction.
Smart Images

Figure CN115359490B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a text direction recognition method and device, equipment and a storage medium. BACKGROUND
[0002] In the current scheme for recognizing the direction of text, the text area is usually transformed into an image of a certain size limit so as to be recognized by a detection model. However, this transformation of the text area causes certain elastic deformation, which makes the detection model unable to accurately recognize the direction of text. SUMMARY
[0003] In view of the above, it is necessary to provide a text direction recognition method, device, equipment and storage medium, which can solve the technical problem of being unable to accurately recognize the direction of text.
[0004] In one aspect, the present application provides a text direction recognition method, which comprises:
[0005] performing image enhancement processing on the obtained training grayscale image to obtain a target training image;
[0006] adjusting network parameters in a preset detection network based on the target training image to obtain a text detection model;
[0007] obtaining a to-be-detected text image according to a received text direction recognition request;
[0008] performing grayscale processing on the to-be-detected text image to obtain a grayscale image;
[0009] locating a text area in the grayscale image based on the text detection model;
[0010] segmenting the text area to obtain a plurality of target areas;
[0011] generating a text direction of the to-be-detected text image based on rotation angles of the plurality of target areas.
[0012] According to the preferred embodiment of the present application, the image enhancement processing on the obtained training grayscale image to obtain a target training image comprises:
[0013] obtaining a scene text image from a plurality of preset application scenarios;
[0014] performing grayscale processing on the scene text image to obtain the training grayscale image;
[0015] performing rotation processing on the training grayscale image to obtain an initial training image;
[0016] If the number of the initial training images is less than a preset number, any two images are extracted from the initial training images, the any two images including a first image and a second image;
[0017] The image pixel value in the first image is adjusted according to a preset ratio, and a third image is obtained;
[0018] The second image and the third image are synthesized to obtain the target training image.
[0019] According to the preferred embodiment of the present application, the adjusting the network parameters in the preset detection network based on the target training image to obtain a text detection model comprises:
[0020] The training pixel information of the target training image is obtained;
[0021] The target training image is encoded based on the training pixel information to obtain an image vector;
[0022] The image vector is input into a text position recognition layer in the preset detection network to obtain a text pixel position;
[0023] The text pixel position is input into an output layer in the preset detection network for position continuity analysis to obtain a predicted region position;
[0024] The network parameters are adjusted based on the position difference between the labeled region position of the target training image and the predicted region position until the position difference no longer decreases, and the text detection model is obtained.
[0025] According to the preferred embodiment of the present application, the gray-scale processing of the to-be-detected text image to obtain a gray-scale image comprises:
[0026] The channel values of the to-be-detected text image on multiple color channels are obtained;
[0027] The gray-scale values of each image pixel point in the to-be-detected text image are calculated based on multiple channel values;
[0028] The gray-scale image is constructed based on the gray-scale values of each image pixel point.
[0029] According to the preferred embodiment of the present application, the splitting the text region to obtain multiple target regions comprises:
[0030] The region shape of the text region is identified based on the region size of the text region;
[0031] If the region shape is not a preset shape, the text region is expanded in the gray-scale image to obtain a test region;
[0032] acquire a shape size threshold corresponding to the preset shape;
[0033] perform segmentation on the test region according to the shape size threshold, to obtain the plurality of target regions.
[0034] According to a preferred embodiment of the present application, the generating of the text direction of the text image to be detected based on the rotation angles of the plurality of target regions comprises:
[0035] parallel recognition of the plurality of target regions based on a pre-trained angle recognition network, to obtain a plurality of rotation angles;
[0036] statistical of the number of angles in each angle interval of the plurality of rotation angles;
[0037] determination of the direction corresponding to the angle interval with the largest number of angles as the text direction.
[0038] According to a preferred embodiment of the present application, after the generating of the text direction of the text image to be detected based on the rotation angles of the plurality of target regions, the method further comprises:
[0039] rotation of the text region based on the text direction, to obtain a corrected region;
[0040] acquisition of region pixel information of the corrected region;
[0041] extraction of feature information of the region pixel information;
[0042] mapping processing of the feature information based on a preset text mapping table, to obtain target text in the text image to be detected.
[0043] On the other hand, the present application further proposes a text direction recognition device, which comprises:
[0044] an enhancement unit configured to perform image enhancement processing on the acquired training gray image, to obtain a target training image;
[0045] an adjustment unit configured to adjust network parameters in a preset detection network based on the target training image, to obtain a text detection model;
[0046] an acquisition unit configured to acquire a text image to be detected according to a received text direction recognition request;
[0047] a processing unit configured to perform gray processing on the text image to be detected, to obtain a gray image;
[0048] a positioning unit configured to position a text region in the gray image based on the text detection model;
[0049] a segmentation unit configured to segment the text region to obtain a plurality of target regions;
[0050] a generation unit configured to generate a text direction of the text image to be detected based on rotation angles of the plurality of target regions.
[0051] In another aspect, the present application also provides an electronic device, which comprises:
[0052] a memory configured to store computer-readable instructions; and
[0053] a processor configured to execute the computer-readable instructions stored in the memory to implement the text direction recognition method.
[0054] In another aspect, the present application also provides a computer-readable storage medium having computer-readable instructions stored therein, the computer-readable instructions being executed by a processor in an electronic device to implement the text direction recognition method.
[0055] As can be seen from the above technical solutions, the present application adjusts the preset detection network based on the target training image obtained after image enhancement processing. Since the image training amount is expanded, and the target training image of the preset detection network is adjusted to a grayscale image, the generalization ability of the text detection model can be improved. Furthermore, by segmenting the text region, the elastic deformation of the text information caused by compression of the text region can be avoided, thereby improving the recognition accuracy of the text direction. In addition, since the same document has the same text direction, the text direction can be accurately recognized by combining the rotation angles of the plurality of target regions. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 is a flowchart of a preferred embodiment of the text direction recognition method of the present application.
[0057] Figure 2 is a functional module diagram of a preferred embodiment of the text direction recognition device of the present application.
[0058] Figure 3 is a structural schematic diagram of an electronic device of a preferred embodiment of the present application for implementing the text direction recognition method. DETAILED DESCRIPTION
[0059] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be described in detail below with reference to the drawings and specific embodiments.
[0060] As Figure 1 shown, is a flowchart of a preferred embodiment of the text direction recognition method of the present application. The order of steps in the flowchart can be changed according to different needs, and some steps can be omitted.
[0061] The text direction recognition method can acquire and process related data based on artificial intelligence technology. Artificial intelligence (AI) is the use of digital computers or computer-controlled machines to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0062] The basic technology of artificial intelligence generally includes technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics, etc. The software technology of artificial intelligence mainly includes computer vision technology, robot technology, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning, etc.
[0063] The text direction recognition method is applied to one or more electronic devices. The electronic device is a device that can automatically perform numerical calculation and / or information processing according to pre-set or stored computer readable instructions. The hardware thereof includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0064] The electronic device can be any electronic product that can interact with the user, such as a personal computer, a tablet computer, a smartphone, a personal digital assistant (PDA), a game console, an interactive Internet Protocol Television (IPTV), a smart wearable device, etc.
[0065] The electronic device can include a network device and / or a user device. The network device includes, but is not limited to, a single network electronic device, a group of electronic devices composed of multiple network electronic devices, or a cloud composed of a large number of hosts or network electronic devices based on cloud computing.
[0066] The network in which the electronic device is located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.
[0067] 101. performing image enhancement processing on the obtained training grayscale image to obtain a target training image.
[0068] In at least one embodiment of the present application, the training grayscale image refers to an image generated after grayscale processing of a scene text image obtained from a plurality of different preset application scenarios. The plurality of different preset application scenarios can include, but are not limited to, the invoice field, the picture book field, etc.
[0069] The target training image refers to an image obtained after data enhancement of the training grayscale image. The number of images of the target training image is greater than or equal to a preset number, wherein the preset number can be set according to actual requirements. For example, the preset number can be determined according to the training accuracy and training time of the text detection model.
[0070] In at least one embodiment of the present application, the electronic device performs image enhancement processing on the obtained training grayscale image to obtain a target training image, comprising:
[0071] obtaining a scene text image from a plurality of preset application scenarios;
[0072] performing grayscale processing on the scene text image to obtain the training grayscale image;
[0073] performing rotation processing on the training grayscale image to obtain an initial training image;
[0074] if the number of images of the initial training image is less than a preset number, extracting any two images from the initial training image, wherein the any two images include a first image and a second image;
[0075] adjusting image pixel values in the first image according to a preset ratio to obtain a third image;
[0076] performing synthesis processing on the second image and the third image to obtain the target training image.
[0077] The preset ratio can be set according to requirements.
[0078] By obtaining the scene text image from the plurality of preset application scenarios, the adaptability of the text detection model trained using the target training image corresponding to the scene text image to the plurality of preset application scenarios can be improved, and then the scene text image is subjected to grayscale processing, which can avoid the interference of colors on multiple channels of the image, thereby improving the generalization ability of the text detection model. Further, by first rotating the training grayscale image, the generation efficiency of the initial training image can be improved, and then when the number of images of the initial training image is less than a preset number, the image pixel value in the first image is adjusted by the preset ratio, which can ensure that there is a certain pixel difference between the second image and the third image, thereby facilitating the synthesis of the second image and the third image. By synthesizing the second image and the third image, the number of images of the target training image can be ensured.
[0079] Specifically, the electronic device performs grayscale processing on the scene text image to obtain the training grayscale image in a similar manner to that of the electronic device performing grayscale processing on the to-be-detected text image to obtain a grayscale image. The following has been refined, and the present application will not be described again.
[0080] 102, adjusting network parameters in a preset detection network based on the target training image to obtain a text detection model.
[0081] In at least one embodiment of the present application, the preset detection network includes a text position recognition layer and an output layer. The text position recognition layer is used to identify the pixel position of the text in the image. The output layer is used to identify the region position formed by the position output by the text position recognition layer. The text position recognition layer includes a plurality of convolution layers, and the number of the plurality of convolution layers is related to the network parameters. The output layer includes a pooling layer and a fully connected layer.
[0082] The network parameters generally include parameters pre-configured in the text position recognition layer and the output layer.
[0083] The text detection model refers to the preset detection network corresponding to the position difference no longer reduced when the preset detection network is adjusted by the target training image. The text detection model is used to predict the region where the text in the image is located.
[0084] In at least one embodiment of the present application, the electronic device adjusts the network parameters in the preset detection network based on the target training image to obtain a text detection model, which includes:
[0085] Obtaining training pixel information of the target training image;
[0086] encoding processing on the target training image based on the training pixel information, to obtain an image vector;
[0087] inputting the image vector into a text position recognition layer in the preset detection network, to obtain a text pixel position;
[0088] inputting the text pixel position into an output layer in the preset detection network for position continuity analysis, to obtain a predicted region position;
[0089] adjusting the network parameters based on a position difference between the labeled region position of the target training image and the predicted region position, until the position difference no longer decreases, to obtain the text detection model.
[0090] The training pixel information comprises a pixel position and a pixel value at the pixel position.
[0091] The text pixel position refers to a position corresponding to a pixel of text in an image.
[0092] The predicted region position refers to a position corresponding to a region of text in an image.
[0093] The encoding of the target training image based on the training pixel information can improve the representation ability of the image vector, the pixel-level analysis and prediction of the image vector based on the text position recognition can improve the accuracy of the text pixel position, thereby improving the accuracy of the predicted region position, and then the network parameters can be accurately adjusted in combination of the predicted region position and the labeled region position, thereby improving the prediction ability of the text detection model.
[0094] 103. Acquire a text image to be detected according to the received text direction recognition request.
[0095] In at least one embodiment of the present application, the text direction recognition request can be triggered to be generated when a recognition demand is received. The text image to be detected refers to an image that needs to be subjected to text direction recognition.
[0096] In at least one embodiment of the present application, the electronic device acquires a text image to be detected according to the received text direction recognition request, which comprises:
[0097] Parse a message of the text direction recognition request, to obtain data information carried by the message;
[0098] Extract a storage path and an image identifier from the data information;
[0099] Write the storage path and the image identifier into a query template, to obtain a query statement;
[0100] Running the query statement, output the text image to be detected.
[0101] The storage path and the image identifier can be used to accurately obtain the text image to be detected. Furthermore, the query template does not need to be reconstructed, and thus the efficiency of obtaining the text image to be detected can be improved.
[0102] 104, the text image to be detected is grayed to obtain a gray image.
[0103] In at least one embodiment of the present application, the gray image refers to an image on a single channel corresponding to the text image to be detected.
[0104] In at least one embodiment of the present application, the electronic device grays the text image to be detected to obtain a gray image, including:
[0105] Obtaining channel values of the text image to be detected on multiple color channels;
[0106] Calculating a gray value of each image pixel point in the text image to be detected based on multiple channel values;
[0107] Constructing the gray image based on the gray value of each image pixel point.
[0108] The multiple color channels include RGB (Red, Green, Blue) channels and the like.
[0109] The channel value can refer to pixel information of the text image to be detected on multiple color channels.
[0110] The multiple channel values can be combined to accurately calculate the gray value, and the gray value can be used to directly construct the gray image, thereby improving the generation efficiency of the gray image.
[0111] Specifically, the calculation formula of the gray value is:
[0112]
[0113] Yi represents the gray value of the i-th image pixel point, Ri represents the channel value of the text image to be detected on the R color channel corresponding to the i-th image pixel point, Gi represents the channel value of the text image to be detected on the G color channel corresponding to the i-th image pixel point, Bi represents the channel value of the text image to be detected on the B color channel corresponding to the i-th image pixel point, K1 and K2 are constants not equal to 0. i i i i
[0114] Through the above embodiment, the gray value of each image pixel point can be accurately calculated, thereby improving the accuracy of the gray image.
[0115] 105, locate a text region in the gray image based on the text detection model.
[0116] In at least one embodiment of the present application, the text region refers to the region position of the text in the text image to be detected.
[0117] In at least one embodiment of the present application, the way in which the electronic device locates the text region in the gray image based on the text detection model is the inverse process of the way in which the electronic device adjusts the network parameters in the preset detection network based on the target training image, which will not be described herein.
[0118] 106, segment the text region to obtain a plurality of target regions.
[0119] In at least one embodiment of the present application, the plurality of target regions are obtained by segmenting the text region according to a shape size threshold. The shape size threshold refers to a size threshold corresponding to a preset shape.
[0120] In at least one embodiment of the present application, the electronic device segments the text region to obtain a plurality of target regions, including:
[0121] identifying the region shape of the text region based on the region size of the text region;
[0122] if the region shape is not the preset shape, expanding the text region in the gray image to obtain a test region;
[0123] obtaining a shape size threshold corresponding to the preset shape;
[0124] segmenting the test region according to the shape size threshold to obtain the plurality of target regions.
[0125] In order to facilitate region segmentation and in combination with the minimum circumscribed graph of Chinese characters, the preset shape is usually set as a square.
[0126] By expanding the text region in the gray image, the loss of text information in the text region can be avoided, and other feature information on the gray image can be added to the text region, which is beneficial to subsequent recognition of the text direction. Segmenting the test region based on the shape size threshold corresponding to the preset shape can ensure that the test region can be completely segmented, thereby improving the segmentation convenience of the plurality of target regions.
[0127] 107. generating the text direction of the text image to be detected based on the rotation angles of the plurality of target regions.
[0128] It should be emphasized that, in order to further ensure the privacy and security of the above-mentioned text direction, the above-mentioned text direction can also be stored in a node of a block chain.
[0129] In at least one embodiment of the present application, the rotation angle refers to the direction of the text in the plurality of target regions. For example, the rotation angle can be 30 degrees clockwise.
[0130] The text direction refers to the direction of the text in the text image to be detected.
[0131] In at least one embodiment of the present application, the electronic device generates the text direction of the text image to be detected based on the rotation angles of the plurality of target regions, comprising:
[0132] Parallelly identifying the plurality of target regions based on the angle recognition network trained in advance, to obtain a plurality of rotation angles;
[0133] Counting the number of angles in each angle interval where the plurality of rotation angles are located;
[0134] Determining the direction corresponding to the angle interval with the largest number of angles as the text direction.
[0135] The angle recognition network is used to identify the direction in the region text.
[0136] The angle interval can be set according to the accuracy requirement of the text direction. If the accuracy requirement of the text direction is high, more angle intervals can be set. For example, if the accuracy requirement of the text direction is 0.1 error, 10 angle intervals are set; if the accuracy requirement of the text direction is 0.01 error, 100 angle intervals are set.
[0137] By parallelly identifying the plurality of target regions, the identification efficiency of the plurality of rotation angles can be improved, and then the text direction is identified by counting the number of angles in each angle interval where the plurality of rotation angles are located. Since the text directions in the same document have commonality, the accuracy of the text direction can be improved by predicting the plurality of target regions.
[0138] In at least one embodiment of the present application, after generating the text direction of the text image to be detected based on the rotation angles of the plurality of target regions, the method further comprises:
[0139] Rotating the text region based on the text direction to obtain a corrected region;
[0140] obtain region pixel information of the correction region;
[0141] extract feature information of the region pixel information;
[0142] perform mapping processing on the feature information based on a preset text mapping table to obtain target text in the to-be-detected text image.
[0143] The feature information includes pixel values corresponding to the text and pixel positions corresponding to the text. The feature information can be obtained through a plurality of feature extraction layers, and each feature extraction layer includes a plurality of convolution kernels.
[0144] The preset text mapping table includes a mapping relationship between a plurality of preset vectors and preset vocabularies.
[0145] The direction of the correction region can be improved by rotating the text region in a direction, and the mapping of the feature information can be accurately completed to improve the accuracy of the target text.
[0146] As can be seen from the above technical solutions, the preset detection network is adjusted based on the target training image obtained after image enhancement processing. Since the image training amount is expanded, and the target training image of the preset detection network is adjusted to a grayscale image, the generalization ability of the text detection model can be improved. Further, by dividing the text region, elastic deformation of the text information caused by compression of the text region can be avoided, thereby improving the recognition accuracy of the text direction. In addition, since the same document has the same text direction, the text direction can be accurately recognized by combining the rotation angles of the plurality of target regions.
[0147] As Figure 2 shown is a functional module diagram of a preferred embodiment of a text direction recognition device. The text direction recognition device 11 includes an enhancement unit 110, an adjustment unit 111, an obtaining unit 112, a processing unit 113, a positioning unit 114, a division unit 115, a generation unit 116, a rotation unit 117, an extraction unit 118, and a mapping unit 119. The modules / units referred to in the present application are a series of computer-readable instruction segments that can be obtained by the processor 13 and can complete a fixed function, which are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in the subsequent embodiments.
[0148] The enhancement unit 110 performs image enhancement processing on the obtained training grayscale image to obtain a target training image.
[0149] In at least one embodiment of the present application, the training grayscale image refers to an image generated by grayscale processing of a scene text image obtained from a plurality of different preset application scenarios. The plurality of different preset application scenarios can include, but are not limited to, the invoice field, the picture book field, etc.
[0150] The target training image refers to an image obtained by data enhancement of the training grayscale image. The number of images of the target training image is greater than or equal to a preset number, wherein the preset number can be set according to actual needs. For example, the preset number can be determined according to the training accuracy and training time of the text detection model.
[0151] In at least one embodiment of the present application, the enhancement unit 110 performs image enhancement processing on the obtained training grayscale image to obtain a target training image, including:
[0152] Obtaining a scene text image from a plurality of preset application scenarios;
[0153] Grayscale processing the scene text image to obtain the training grayscale image;
[0154] Rotating the training grayscale image to obtain an initial training image;
[0155] If the number of images of the initial training image is less than a preset number, extracting any two images from the initial training image, wherein the any two images include a first image and a second image;
[0156] Adjusting the image pixel value in the first image according to a preset ratio to obtain a third image;
[0157] Synthesizing the second image and the third image to obtain the target training image.
[0158] The preset ratio can be set according to requirements.
[0159] By acquiring the scene text image from the plurality of preset application scenarios, the adaptability of the text detection model trained by using the target training image corresponding to the scene text image to the plurality of preset application scenarios can be improved, and then the scene text image is subjected to the grayscale processing, the interference caused by the color on the multiple channels of the image can be avoided, so that the generalization ability of the text detection model is improved. Further, the initial training image is generated by first rotating the training grayscale image, and then when the number of images of the initial training image is less than a preset number, the image pixel value in the first image is adjusted by the preset ratio, so that a certain pixel difference value exists between the second image and the third image, thereby facilitating the synthesis of the second image and the third image. By synthesizing the second image and the third image, the number of images of the target training image can be ensured.
[0160] Specifically, the enhancement unit 110 performs grayscale processing on the scene text image to obtain the training grayscale image, and the processing unit 113 performs grayscale processing on the to-be-detected text image to obtain a grayscale image in a similar manner. The following has been refined, and the present application will not be repeated here.
[0161] The adjustment unit 111 adjusts the network parameters in the preset detection network based on the target training image to obtain a text detection model.
[0162] In at least one embodiment of the present application, the preset detection network includes a text position recognition layer and an output layer. The text position recognition layer is used to identify the pixel position of the text in the image. The output layer is used to identify the region position formed by the position output by the text position recognition layer. The text position recognition layer includes a plurality of convolution layers, and the number of the plurality of convolution layers is related to the network parameters. The output layer includes a pooling layer and a fully connected layer.
[0163] The network parameters generally include parameters pre-configured in the text position recognition layer and the output layer.
[0164] The text detection model refers to the preset detection network corresponding to the position difference that is no longer reduced when the preset detection network is adjusted by using the target training image. The text detection model is used to predict the region where the text in the image is located.
[0165] In at least one embodiment of the present application, the adjustment unit 111 adjusts the network parameters in the preset detection network based on the target training image to obtain a text detection model, which includes:
[0166] Obtaining training pixel information of the target training image;
[0167] encoding processing on the target training image based on the training pixel information, to obtain an image vector;
[0168] inputting the image vector into a text position recognition layer in the preset detection network, to obtain a text pixel position;
[0169] inputting the text pixel position into an output layer in the preset detection network for position continuity analysis, to obtain a predicted region position;
[0170] adjusting the network parameters based on a position gap between the labeled region position of the target training image and the predicted region position, until the position gap no longer decreases, to obtain the text detection model.
[0171] The training pixel information comprises a pixel position and a pixel value at the pixel position.
[0172] The text pixel position refers to a position corresponding to a pixel of text in an image.
[0173] The predicted region position refers to a position corresponding to a region of text in an image.
[0174] The encoding of the target training image based on the training pixel information can improve the representation ability of the image vector, the pixel-level analysis and prediction of the image vector based on the text position recognition can improve the accuracy of the text pixel position, thereby improving the accuracy of the predicted region position, and then the network parameters can be accurately adjusted in combination of the predicted region position and the labeled region position, thereby improving the prediction ability of the text detection model.
[0175] The obtaining unit 112 obtains a to-be-detected text image according to the received text direction recognition request.
[0176] In at least one embodiment of the present application, the text direction recognition request can be triggered to be generated when a recognition requirement is received. The to-be-detected text image refers to an image that needs to be recognized in terms of text direction.
[0177] In at least one embodiment of the present application, the obtaining unit 112 obtains a to-be-detected text image according to the received text direction recognition request comprises:
[0178] parsing a message of the text direction recognition request, to obtain data information carried by the message;
[0179] extracting a storage path and an image identifier from the data information;
[0180] writing the storage path and the image identifier into a query template, to obtain a query statement;
[0181] Run the query statement and output the text image to be detected.
[0182] The text image to be detected can be accurately obtained through the storage path and the image identifier. Furthermore, since there is no need to reconstruct the query template, the efficiency of obtaining the text image to be detected can be improved.
[0183] The processing unit 113 performs grayscale processing on the text image to be detected to obtain a grayscale image.
[0184] In at least one embodiment of the present invention, the grayscale image refers to an image on a single channel corresponding to the text image to be detected.
[0185] In at least one embodiment of the present invention, the processing unit 113 performs grayscale processing on the text image to be detected to obtain a grayscale image, including:
[0186] Obtain the channel values of the text image to be detected in multiple color channels;
[0187] The grayscale value of each pixel in the text image to be detected is calculated based on multiple channel values;
[0188] The grayscale image is constructed based on the grayscale value of each image pixel.
[0189] The multiple color channels include RGB (Red, Green, Blue) channels.
[0190] The channel value can refer to the pixel information of the text image to be detected in multiple color channels.
[0191] By combining the multiple channel values, the grayscale value can be accurately calculated, and then the grayscale image can be directly constructed using the grayscale value, thereby improving the generation efficiency of the grayscale image.
[0192] Specifically, the formula for calculating the grayscale value is:
[0193]
[0194] Among them, Y i R represents the grayscale value of the i-th image pixel. i G represents the channel value of the text image to be detected in the R color channel corresponding to the i-th image pixel. i B represents the channel value of the text image to be detected in the G color channel corresponding to the i-th image pixel. i K1 and K2 represent the channel value of the text image to be detected in the B color channel corresponding to the i-th image pixel, where K1 and K2 are non-zero constants.
[0195] Through the above-mentioned embodiments, the gray value of each image pixel point can be accurately calculated, thereby improving the accuracy of the gray image.
[0196] The positioning unit 114 positions a text region in the gray image based on the text detection model.
[0197] In at least one embodiment of the present application, the text region refers to a region position of the text in the text image to be detected.
[0198] In at least one embodiment of the present application, the manner in which the positioning unit 114 positions the text region in the gray image based on the text detection model is a reverse process of the manner in which the adjusting unit 111 adjusts the network parameters in the preset detection network based on the target training image, and the present application will not be described here.
[0199] The segmentation unit 115 segments the text region to obtain a plurality of target regions.
[0200] In at least one embodiment of the present application, the plurality of target regions are obtained by segmenting the text region according to a shape size threshold. The shape size threshold refers to a size threshold corresponding to a preset shape.
[0201] In at least one embodiment of the present application, the segmentation unit 115 segments the text region to obtain a plurality of target regions includes:
[0202] Identifying a region shape of the text region based on a region size of the text region;
[0203] If the region shape is not a preset shape, expanding the text region in the gray image to obtain a test region;
[0204] Obtaining a shape size threshold corresponding to the preset shape;
[0205] Segmenting the test region according to the shape size threshold to obtain the plurality of target regions.
[0206] In order to facilitate region segmentation, and in combination with the minimum circumscribed graph of Chinese characters, the preset shape is usually set as a square.
[0207] By expanding the text region on the grayscale image, not only can the loss of text information in the text region be avoided, but other feature information on the grayscale image can also be added to the text region, which is beneficial for subsequent recognition of text direction. By segmenting the test region based on the shape size threshold corresponding to the preset shape, it can be ensured that the test region can be completely segmented, thus improving the convenience of segmenting the multiple target regions.
[0208] The generation unit 116 generates the text direction of the text image to be detected based on the rotation angle of the plurality of target regions.
[0209] It should be emphasized that, to further ensure the privacy and security of the aforementioned text direction, the aforementioned text direction can also be stored in a node of a blockchain.
[0210] In at least one embodiment of the present invention, the rotation angle refers to the orientation of the text in the plurality of target areas. For example, the rotation angle may be 30 degrees clockwise.
[0211] The text mode refers to the orientation of the text in the text image to be detected.
[0212] In at least one embodiment of the present invention, the generation unit 116 generates the text direction of the text image to be detected based on the rotation angle of the plurality of target regions, including:
[0213] The multiple target regions are identified in parallel based on a pre-trained angle recognition network to obtain multiple rotation angles;
[0214] Count the number of angles that fall within each angle interval from the multiple rotation angles;
[0215] The direction corresponding to the angle interval with the largest number of angles is determined as the text direction.
[0216] The angle recognition network is used to identify directions in the text region.
[0217] The angle intervals can be set according to the accuracy requirements of the text direction. If the accuracy requirement of the text direction is high, more angle intervals can be set. For example, if the accuracy requirement of the text direction is an error of 0.1, then 10 angle intervals can be set; if the accuracy requirement of the text direction is an error of 0.01, then 100 angle intervals can be set.
[0218] By identifying the plurality of target regions in parallel, the identification efficiency of the plurality of rotation angles can be improved, and then the text direction is identified by the number of angles of the plurality of rotation angles in each angle interval. Since the text directions in the same document have commonality, the accuracy of the text direction can be improved by predicting the plurality of target regions.
[0219] In at least one embodiment of the present application, after the text direction of the text image to be detected is generated based on the rotation angles of the plurality of target regions, the rotation unit 117 rotates the text region based on the text direction, obtaining a corrected region;
[0220] The acquisition unit 112 acquires region pixel information of the corrected region;
[0221] The extraction unit 118 extracts feature information of the region pixel information;
[0222] The mapping unit 119 performs mapping processing on the feature information based on a preset text mapping table, obtaining a target text in the text image to be detected.
[0223] The feature information includes pixel values corresponding to the text and pixel positions corresponding to the text. The feature information can be extracted through a plurality of feature extraction layers, and each feature extraction layer includes a plurality of convolution kernels.
[0224] The preset text mapping table includes a mapping relationship between a plurality of preset vectors and a preset vocabulary.
[0225] By rotating the text region in the direction, the direction correctness of the corrected region can be improved, and by the feature information, the mapping of the information can be accurately completed, and the accuracy of the target text can be improved.
[0226] As can be seen from the above technical solution, the present application adjusts the preset detection network based on the target training image obtained after image enhancement processing. Since the image training amount is expanded, and the target training image of the preset detection network is adjusted to a gray scale image, the generalization ability of the text detection model can be improved. Further, by dividing the text region, the elastic deformation of the text information caused by compression of the text region can be avoided, thereby improving the identification accuracy of the text direction. In addition, since the same document has the phenomenon of consistent text direction, the text direction can be accurately identified by combining the rotation angles of the plurality of target regions.
[0227] As Figure 3 shown is a structure schematic diagram of an electronic device of a preferred embodiment of the present application for realizing a text direction identification method.
[0228] In an embodiment of the present application, the electronic device 1 comprises, but is not limited to, a memory 12, a processor 13, and computer readable instructions stored in the memory 12 and executable on the processor 13, such as a text direction recognition program.
[0229] Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 1 and does not constitute a limitation on the electronic device 1, and can include more or fewer components than the diagram, or combine certain components, or different components, for example, the electronic device 1 can also include an input / output device, a network access device, a bus, etc.
[0230] The processor 13 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The processor 13 is the operation core and control center of the electronic device 1, and connects each part of the entire electronic device 1 through various interfaces and lines, and executes the operating system and installed various application programs, program codes, etc. of the electronic device 1.
[0231] For example, the computer readable instructions can be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present application. The one or more modules / units can be a series of computer readable instruction segments capable of completing a specific function, which are used to describe the execution process of the computer readable instructions in the electronic device 1. For example, the computer readable instructions can be divided into an enhancement unit 110, an adjustment unit 111, an acquisition unit 112, a processing unit 113, a positioning unit 114, a segmentation unit 115, a generation unit 116, a rotation unit 117, an extraction unit 118, and a mapping unit 119.
[0232] The memory 12 can be used to store the computer readable instructions and / or modules, and the processor 13 realizes various functions of the electronic device 1 by running or executing the computer readable instructions and / or modules stored in the memory 12, and calling the data stored in the memory 12. The memory 12 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.), and the like; and the data storage area can store data created according to the use of the electronic device, etc. The memory 12 can include non-volatile and volatile memories, for example: a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one disk storage device, a flash storage device, or other storage devices.
[0233] The memory 12 can be an external memory and / or an internal memory of the electronic device 1. Further, the memory 12 can be a memory having a physical form, such as a memory stick, a TF card (Trans-flash Card), and the like.
[0234] The modules / units integrated in the electronic device 1, if implemented in the form of software function units and sold or used as independent products, can be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the above-mentioned embodiment methods can also be completed by computer readable instructions instructing related hardware, and the computer readable instructions can be stored in a computer readable storage medium. When the computer readable instructions are executed by a processor, the steps of the above-mentioned various method embodiments can be implemented.
[0235] The computer readable instructions include computer readable instruction codes, which can be in the form of source code, object code, executable files, or some intermediate forms, etc. The computer readable medium can include any entity or device capable of carrying the computer readable instruction codes, recording media, U disks, mobile hard disks, magnetic disks, optical disks, computer memories, read-only memories (ROMs), random access memories (RAMs).
[0236] The blockchain referred to in the present application is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. The blockchain is essentially a decentralized database, and is a series of data blocks associated using cryptographic methods, each of which contains information of a batch of network transactions, for verifying the validity (anti-fake) of the information and generating the next block. The blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer, etc.
[0237] In combination Figure 1 The memory 12 in the electronic device 1 stores computer readable instructions to implement a text direction recognition method, and the processor 13 can execute the computer readable instructions to implement:
[0238] Perform image enhancement processing on the obtained training grayscale image to obtain a target training image;
[0239] Adjust network parameters in a preset detection network based on the target training image to obtain a text detection model;
[0240] Obtain a to-be-detected text image according to a received text direction recognition request;
[0241] Perform grayscale processing on the to-be-detected text image to obtain a grayscale image;
[0242] Locate a text region in the grayscale image based on the text detection model;
[0243] Segment the text region to obtain a plurality of target regions;
[0244] Generate a text direction of the to-be-detected text image based on rotation angles of the plurality of target regions.
[0245] Specifically, the specific implementation method of the processor 13 on the above computer readable instructions can refer to the description of related steps in the corresponding embodiments, which will not be repeated here. Figure 1
[0246] In several embodiments provided by the present application, it should be understood that the disclosed system, device, and method can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There can be another division manner in actual implementation.
[0247] The computer readable storage medium stores computer readable instructions, wherein the computer readable instructions are executed by the processor 13 to implement the following steps:
[0248] The obtained training gray image is subjected to image enhancement processing to obtain a target training image;
[0249] The network parameters in a preset detection network are adjusted based on the target training image to obtain a text detection model;
[0250] A text image to be detected is obtained according to a received text direction identification request;
[0251] The text image to be detected is subjected to gray processing to obtain a gray image;
[0252] The text region in the gray image is located based on the text detection model;
[0253] The text region is segmented to obtain a plurality of target regions;
[0254] The text direction of the text image to be detected is generated based on the rotation angles of the plurality of target regions.
[0255] The modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment.
[0256] In addition, the functional modules in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of hardware plus software functional modules.
[0257] Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present application is defined by the appended claims rather than the above description, and therefore all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be included in the present application. Any additional reference signs in the claims should not be considered as limiting the claims involved.
[0258] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The plurality of units or devices described can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, not any particular order.
[0259] Finally, it should be noted that the above examples are merely intended to illustrate the technical solutions of the present application and not to limit the present application. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A text direction recognition method, characterized in that, The text orientation recognition method includes: The acquired training grayscale image is subjected to image enhancement processing to obtain the target training image; Based on the target training image, the network parameters in the preset detection network are adjusted to obtain the text detection model; Obtain the image of the text to be detected based on the received text direction recognition request; The text image to be detected is converted to grayscale to obtain a grayscale image; Based on the text detection model, the text region in the grayscale image is located; The text region is segmented to obtain multiple target regions, including: identifying the region shape of the text region based on its region size; if the region shape is not a preset shape, expanding the text region in the grayscale image to obtain a test region; obtaining a shape size threshold corresponding to the preset shape; and segmenting the test region according to the shape size threshold to obtain the multiple target regions. The text direction of the text image to be detected is generated based on the rotation angle of the multiple target regions.
2. The text direction recognition method as described in claim 1, characterized in that, The step of performing image enhancement processing on the acquired training grayscale image to obtain the target training image includes: Obtain scene text images from multiple preset application scenarios; The scene text image is converted to grayscale to obtain the training grayscale image; The training grayscale image is rotated to obtain the initial training image; If the number of images in the initial training images is less than a preset number, then any two images are extracted from the initial training images, and the any two images include a first image and a second image; The image pixel values in the first image are adjusted according to a preset ratio to obtain the third image; The second image and the third image are combined to obtain the target training image.
3. The text direction recognition method as described in claim 1, characterized in that, The step of adjusting the network parameters in the preset detection network based on the target training image to obtain the text detection model includes: Obtain the training pixel information of the target training image; The target training image is encoded based on the training pixel information to obtain an image vector; The image vector is input into the text location recognition layer of the preset detection network to obtain the text pixel location; The text pixel positions are input into the output layer of the preset detection network for positional continuity analysis to obtain the predicted region position; The network parameters are adjusted based on the positional difference between the labeled region and the predicted region in the target training image until the positional difference no longer decreases, thus obtaining the text detection model.
4. The text direction recognition method as described in claim 1, characterized in that, The grayscale conversion of the text image to be detected to obtain a grayscale image includes: Obtain the channel values of the text image to be detected in multiple color channels; The grayscale value of each pixel in the text image to be detected is calculated based on multiple channel values; The grayscale image is constructed based on the grayscale value of each image pixel.
5. The text direction recognition method as described in claim 1, characterized in that, The text direction generated from the rotation angle of the multiple target regions to the text image to be detected includes: The multiple target regions are identified in parallel based on a pre-trained angle recognition network to obtain multiple rotation angles; Count the number of angles that fall within each angle interval from the multiple rotation angles; The direction corresponding to the angle interval with the largest number of angles is determined as the text direction.
6. The text direction recognition method as described in claim 1, characterized in that, After generating the text orientation of the text image to be detected based on the rotation angles of the multiple target regions, the method further includes: The text region is rotated based on the text direction to obtain the correction region; Obtain the region pixel information of the correction area; Extract feature information from the pixel information of the region; The feature information is mapped based on a preset text mapping table to obtain the target text in the text image to be detected.
7. A text orientation recognition device, characterized in that, The text orientation recognition device includes: The enhancement unit is used to perform image enhancement processing on the acquired training grayscale image to obtain the target training image; An adjustment unit is used to adjust the network parameters in a preset detection network based on the target training image to obtain a text detection model. The acquisition unit is used to acquire the text image to be detected based on the received text direction recognition request; The processing unit is used to perform grayscale processing on the text image to be detected to obtain a grayscale image; The localization unit is used to locate the text region in the grayscale image based on the text detection model; A segmentation unit is used to segment the text region to obtain multiple target regions, including: identifying the region shape of the text region based on the region size of the text region; if the region shape is not a preset shape, expanding the text region in the grayscale image to obtain a test region; obtaining a shape size threshold corresponding to the preset shape; and segmenting the test region according to the shape size threshold to obtain the multiple target regions. The generation unit is used to generate the text direction of the text image to be detected based on the rotation angle of the plurality of target regions.
8. An electronic device, characterized in that, The electronic device includes: Memory, which stores computer-readable instructions; and The processor executes computer-readable instructions stored in the memory to implement the text direction recognition method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which are executed by a processor in an electronic device to implement the text direction recognition method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Document orientation detection method and device, equipment and storage medium
CN111507267A
Text detection using global geometry estimators
US20210334528A1