Text matching and recognition method and device
By using stroke matrix and bi-headed neural network in text comparison and recognition, the similarity matrix is calculated and constructed, the problem of low accuracy of handwritten text recognition in the prior art is solved, and the accuracy and generalization of recognition are improved.
Patent Information
- Application Number
- CN202110774581.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-08
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2041-07-08
AI Technical Summary
现有技术在识别手写文字时,准确率较低,尤其是不同顾客的书写水平和习惯差异大,导致泛化性较差。
By taking the picture of the text from the picture to be compared, obtaining the stroke matrix, and calculating the similarity value of the stroke matrix, constructing a similarity matrix, inputting it to the original picture to the double-headed neural network to obtain the similarity of the text.
It improves the accuracy and generalization of text comparison and recognition, and can better grasp the overall form of text and extract and utilize text information.
Smart Images

Figure CN113449726B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of pattern recognition technology, and in particular to a text matching and recognition method and device. Background Art
[0002] In order to improve the efficiency of bank business processing, some businesses require customers to first collect paper forms and fill them out with a pen. When processing business at the counter, the hand-filled forms are photographed or scanned for archiving, and then the handwritten text in the picture is recognized. With the increase of banking business, the demand for handwritten text recognition in pictures is also increasing.
[0003] In the prior art, there is a method for recognizing handwritten text using a trained convolutional neural network model. This method directly inputs a picture of the handwritten text to be recognized into the trained neural network to obtain a recognition result.
[0004] However, due to the large differences in writing levels and writing habits among different customers, the existing technology has a low accuracy rate for recognizing text directly based on handwriting traces; and the accuracy rate is even lower for untrained text recognition, that is, the generalization is poor. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method and device for comparing and recognizing text, so as to solve the problem of low accuracy in recognizing handwritten text.
[0006] To solve the above technical problems, the embodiment of the present specification provides a text comparison method, including: cutting out a picture of a first text to be compared from a first picture to be compared, and cutting out a picture of a second text to be compared from a second picture to be compared; obtaining a stroke matrix of the first text to be compared and a stroke matrix of the second text to be compared; calculating the similarity value of the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared, and constructing a similarity matrix according to the similarity value; inputting the similarity matrix, the stroke matrix of the first text to be compared and the picture of the first text to be compared into a two-headed neural network to obtain the similarity between the first text to be compared and the second text to be compared.
[0007] The implementation mode of this specification also provides a text recognition method, including: cutting out a picture of the text to be recognized from the picture of the text to be recognized; obtaining pictures of the text in the text picture library in sequence; obtaining the stroke matrix of the text to be recognized and the stroke matrix of the text in the text picture library; calculating the similarity value between the stroke matrix of the text to be recognized and the stroke matrix of the text in the text picture library, and constructing a similarity matrix based on the similarity value; inputting the similarity matrix, the stroke matrix of the text to be recognized and the picture of the text to be recognized into a two-headed neural network to obtain the similarity between the text to be recognized and the text in the text picture library; and outputting a text recognition result that meets predetermined requirements based on the obtained similarity.
[0008] The text comparison and recognition method provided in the embodiments of this specification can better grasp the overall form of the text by introducing the stroke matrix, thereby improving the accuracy and generalization of the text comparison method; by calculating the similarity values of the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared, and then obtaining the similarity matrix, it is input into the two-headed neural network together with the first picture to be compared to obtain the similarity between the first text to be compared and the second text to be compared, which can maximize the extraction and utilization of text information, thereby further improving the accuracy and generalization of the text comparison method. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the implementation methods of the present application or the technical solutions in the prior art, the drawings required for use in the implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some implementation methods recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0010] Figure 1 A flowchart of a text comparison method according to an embodiment of this specification is shown;
[0011] Figure 2A A schematic diagram of a picture of a Chinese character is shown;
[0012] Figure 2B The four matrix diagrams (1) to (4) in FIG. Figure 2A The matrix corresponding to the longest horizontal stroke, the longest vertical stroke, the longest left stroke, and the longest right stroke in the Chinese characters shown;
[0013] Figure 2C A schematic diagram of another Chinese character is shown;
[0014] Figure 2D The four matrix diagrams (1) to (4) in FIG. Figure 2C The matrix corresponding to the longest horizontal stroke, the longest vertical stroke, the longest left stroke, and the longest right stroke in the Chinese characters shown;
[0015] Figure 3 A specific implementation method of inputting a similarity matrix, a stroke matrix of a first character to be compared, and a first picture to be compared into a double-headed neural network to obtain a similarity between the first character to be compared and the second character to be compared is shown;
[0016] Figure 4 A training method for a two-headed neural network is shown;
[0017] Figure 5 A flowchart of a text recognition method according to an embodiment of this specification is shown;
[0018] Figure 6 A functional block diagram of a text comparison device according to an embodiment of this specification is shown;
[0019] Figure 7 A principle block diagram of an obtaining unit according to an embodiment of this specification is shown;
[0020] Figure 8 A functional block diagram of an electronic device according to an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0022] In one scenario example, there is a Chinese character X, which may be a rare character, or may be newly created with the development of the times. User A did not know this Chinese character before. After briefly observing the font of the Chinese character, he wrote the Chinese character silently and wanted to know the degree of similarity between his handwriting and Chinese character X. To this end, the degree of similarity between the two can be determined through the Chinese character comparison method provided in this manual.
[0023] In one scenario example, the user's text signature is pre-stored. When the user's signature is required (such as swiping a card to pay at a shopping mall), the user's signature on site can be compared with the pre-stored text signature, and the degree of similarity can be used to determine whether the user signing on site is the real user corresponding to the signature.
[0024] In one scenario example, the answer sheets of student examinations are machine-identified, and the text recognition method provided in this manual can be used to identify the text on the electronic image corresponding to the examination paper; in some writing test questions, the examinee writes the required text in the predetermined position on the examination paper, and the text comparison method provided in this manual can be used to compare the text written by the examinee with the text in the answer to determine whether the text written by the examinee reaches the predetermined similarity threshold, thereby determining whether the written text meets the requirements.
[0025] In an example scenario, a user writes an article by hand and wants to publish it on the Internet or store it in a computer in text form. In this case, the text recognition method provided in this manual can be used to recognize each word in the handwritten manuscript.
[0026] In one scenario example, a user writes text on a touch screen of an electronic device using a fingertip, a knuckle, or a stylus configured by the electronic device, and the electronic device can run the text recognition method provided in the embodiments of this specification to recognize the handwritten text. A similar scenario can also be that a user writes on any medium using any medium, such as writing on a table with water.
[0027] In one scenario example, a user writes through a somatosensory game, records the movement path of the body part used for writing or the handheld sensor when writing, uses the movement path as the text to be recognized, and uses the text recognition method provided in this manual to recognize it.
[0028] In one scenario example, before a user goes to a bank, social security center or other department to handle business, he needs to fill out relevant forms. The teller takes a photo of the form filled out by the user, recognizes the text in the form and enters it into the system, thereby reducing the teller's input workload and the possibility of error. In this case, the text recognition method provided in this specification can be used to recognize the text in the electronic image of the filled-in form, and the recognized text can be entered into the system.
[0029] The text comparison and recognition method provided in this manual is applicable to any language and text. The text comparison and recognition method are specifically introduced below.
[0030] Figure 1 FIG. 2 shows a flow chart of a text comparison method according to an embodiment of the present specification. Figure 1 As shown, the text comparison method includes the following steps:
[0031] S110: extracting a picture of the first text to be compared from the first picture to be compared, and extracting a picture of the second text to be compared from the second picture to be compared.
[0032] The first image to be compared and the second image to be compared are usually obtained from photos taken by a camera, or are obtained by capturing frames from a recorded video, or are obtained by scanning a scanning device, etc. In addition to the text to be compared, the first image to be compared and the second image to be compared may contain other text or patterns, or the positions of the text to be compared in the images may differ greatly. For this reason, the image of the first text to be compared can be captured from the first image to be compared, and the image of the second text to be compared can be captured from the second image to be compared according to a preset capture template, so that there are as few interfering patterns or handwriting as possible in the captured image except for the text to be compared, and the text to be recognized is located in the middle of the captured image.
[0033] S120: Obtain a stroke matrix of the first character to be compared and a stroke matrix of the second character to be compared.
[0034] In some embodiments, the text is presented in the form of an image or a picture. For example, after taking a photo of a paper document with text, each text image is intercepted one by one through a pre-set interception template or the like to obtain a text picture, and the stroke matrix of the text is extracted from the picture. When extracting, the text picture is evenly divided into pixels, each pixel corresponding to an element in the stroke matrix. The matrix elements corresponding to the pixels where the text strokes are located are marked as 1, and the remaining matrix elements are marked as 0, thus obtaining the stroke matrix.
[0035] In some embodiments, the surface of the medium on which the user writes the text (such as a touch screen, a somatosensory receiver, etc.) is divided into pixels, each pixel corresponding to an element in the stroke matrix. When the user writes a stroke, the pixels at the corresponding positions on the medium surface are triggered to output special electrical signals. At this time, the matrix elements corresponding to these pixels are marked as 1, and the remaining elements are marked as 0, thus obtaining the stroke matrix.
[0036] For each character, a matrix of one type of stroke can be extracted; or matrices of multiple types of strokes can be extracted, with each type of stroke corresponding to a matrix.
[0037] A "stroke" refers to the various shaped points and lines that make up a character and are uninterrupted.
[0038] Taking Chinese characters as an example, the strokes can be horizontal (一), vertical (丨), left-falling stroke (丿), dot (丶), fold etc. It is the smallest connected pen unit that constitutes the Chinese character glyph. There are eight basic traditional Chinese character strokes, namely: dot (丶), horizontal (一), vertical (丨), left-falling stroke (丿), right-falling stroke rising stroke fold hook (亅). The strokes described in this specification can be any one or more of these eight strokes. When there are two or more strokes, a stroke matrix can be extracted for each type of stroke. For example, the strokes can include at least one of horizontal, vertical, left-falling stroke, and right-falling stroke. To simplify the comparison operation, the strokes can be only at least one of the longest horizontal, the longest vertical, the longest left-falling stroke, and the longest right-falling stroke.
[0039] For example, Figure 2A and Figure 2C show pictures of two Chinese characters. Figure 2B In (1) to (4) of Figure 2A the four matrix schematic diagrams respectively show the matrices corresponding to the longest horizontal, the longest vertical, the longest left-falling stroke, and the longest right-falling stroke in the Chinese character shown in Figure 2D In (1) to (4) of Figure 2C the four matrix schematic diagrams respectively show the matrices corresponding to the longest horizontal, the longest vertical, the longest left-falling stroke, and the longest right-falling stroke in the Chinese character shown in
[0040] In some embodiments, after obtaining at least two stroke matrices, a predetermined logical operation or arithmetic operation may be performed on the at least two matrices, so as to merge the at least two matrices into one matrix. The logical operation may be a logical AND or logical OR operation for elements at corresponding positions of the matrices, and the arithmetic operation may be a sum or product operation for elements at corresponding positions of the matrices.
[0041] In some embodiments, a stroke matrix is extracted from the image containing the text. Since the text image itself usually has three channels of R, G, and B, a stroke matrix can be extracted for each channel, that is, when there are four types of strokes, 4×3 stroke matrices can be extracted for one text. The four stroke matrices of each channel can be merged into one matrix by performing the above operation, or the matrices of the three channels of each stroke can be merged into one matrix, or all 12 matrices can be merged into one matrix.
[0042] S130: Calculate similarity values between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, and construct a similarity matrix according to the similarity values.
[0043] In step S130, a similarity algorithm may be used to calculate the similarity value. The similarity algorithm may be a similarity algorithm using any one of Euclidean distance, cosine distance, Minkowski distance, Manhattan distance, Chebyshev distance, etc. as a measurement standard. These distance calculation methods are prior art and will not be described in detail. Of course, in step S130, the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared may also be input into a pre-trained network model to obtain a similarity value.
[0044] The similarity value obtained by the similarity algorithm is a number, not a matrix. A similarity matrix can be constructed based on the similarity value so that the subsequent two-headed neural network can use the similarity value. The dimension of the similarity matrix can be the same as the dimension of the feature matrix extracted in step S142.
[0045] For example, in some embodiments, the similarity matrix can be constructed in the following manner: when the similarity value is greater than a first predetermined threshold, the elements in the similarity matrix are set to digital identifiers for indicating similarity, so as to construct a similarity matrix of a predetermined dimension. Specifically, all elements in the similarity matrix are digital identifiers indicating similarity, for example, the number 1 indicates similarity and the number 0 indicates dissimilarity, and the constructed matrix can be a matrix in which all matrix elements are 1 or a matrix in which all matrix elements are 0. Of course, elements at some positions of the matrix can also be set to 1 as required.
[0046] S140: Input the similarity matrix, the stroke matrix of the first character to be compared and the first image to be compared into a two-headed neural network to obtain the similarity between the first character to be compared and the second character to be compared.
[0047] The two-headed neural network has two inputs, which correspond to two sub-neural networks respectively. The two sub-neural networks share weights, and they can be neural networks of the same type or different types. For example, one is LSTM and the other is CNN. Among them, the input of one sub-neural network is the stroke matrix of the first text to be compared and the first picture to be compared, and the input of the other sub-neural network is the similarity matrix. The outputs of the two sub-neural networks are then processed by the DNN (full name in English: Deep Neural Networks, Chinese: Deep Neural Network) layer, and the sigmoid function is used as the final activation function to ensure that the output result is in the range of 0-1.
[0048] The above-mentioned text comparison method can better grasp the overall form of the text by introducing the stroke matrix, thereby improving the accuracy and generalization of the text comparison method; by calculating the similarity values of the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared, and then obtaining the similarity matrix, it is input into the two-headed neural network together with the first picture to be compared to obtain the similarity between the first text to be compared and the second text to be compared, which can maximize the extraction and utilization of text information, thereby further improving the accuracy and generalization of the text comparison method.
[0049] In some embodiments, a sub-neural network of the double-headed neural network in the above step S140 is a convolutional neural network, and features can be extracted through convolution operations. The convolution layer extracts features from the image pixel matrix through convolution operations. Specifically, the convolution layer continuously scans the image pixel matrix according to the step length based on a convolution kernel (a small matrix, also called receptive field, English: filter), multiplies the scanned number by the number of the corresponding position of the convolution kernel, and then calculates the sum. During the scanning process, a value is obtained for each step length. After the image pixel matrix is completely scanned, a new matrix is generated. This is the process of convolution operation. Each value in the convolution kernel is a neuron parameter that needs to be determined during the training process of the neural network model-the weight value weigh. After the convolution layer, the activation layer can be used immediately to decide whether the features extracted by the convolution operation are useful, whether to keep or discard. After the convolution operation, a lot of feature information is extracted, but the adjacent areas of these feature information can be replaced by similar feature information. If all these feature information are retained, there will be information redundancy, which increases the difficulty of calculation. At this time, the pooling layer performing the pooling operation is equivalent to a dimensionality reduction operation. The pooling operation is to take the maximum value or average value in a small matrix area of the feature information matrix obtained by the convolution operation to replace the area. The small matrix is also continuously scanned at a step size on the feature information matrix, and a value is obtained for each step size during the scanning process. For the n-1 layer and n layer in the artificial neural network, any node of the n-1 layer is connected to all the nodes of the nth layer, that is, when each node of the nth layer is calculated, the input of the activation function is the weighted sum of all the nodes of the n-1 layer. The fully connected layer plays the role of a "classifier" in the entire convolutional neural network. If operations such as the convolution layer and the pooling layer map the original data to the hidden feature space, the fully connected layer maps the learned "distributed feature representation" to the sample label space. Based on these contents, it can be understood that Figure 3 An implementation of step S140 is shown. The implementation includes the following steps.
[0050] S141: Input the similarity matrix into the first input terminal of the two-head neural network.
[0051] S142: Inputting the stroke matrix of the first character to be compared and the first image to be compared into the second input end of the double-headed neural network, wherein the double-headed neural network includes: a first layer and a second layer.
[0052] S143: extracting features of the stroke matrix of the first character to be compared and the first image to be compared inputted from the second input terminal through the first layer to obtain a feature matrix.
[0053] S144: Processing the feature matrix and the similarity matrix input from the first input end through the second layer to obtain a similarity value, and using the similarity value as the similarity between the first text to be compared and the second text to be compared.
[0054] The first layer of the two-headed neural network can be a convolutional layer, and the second layer can be a fully connected layer.
[0055] When the feature matrix and the similarity matrix input from the first input end are superimposed and input into the second layer, the Flatten layer can be used to "flatten" these matrices, that is, to convert the feature matrix and the similarity matrix into a matrix with one row.
[0056] As a special case of the embodiments of this specification, the dual-headed neural network described in this specification can also be understood in an expanded manner, that is, steps S120 and S130 can be executed using the third layer of the neural network model, then the dual-headed neural network can include a first layer, a second layer and a third layer.
[0057] Figure 4 A training method for a two-headed neural network is shown, comprising the following steps.
[0058] S401: Obtain a picture sample of a first text to be compared and a picture sample of a second text to be compared.
[0059] S402: extracting a stroke matrix of the first character to be compared from the image sample of the first character to be compared, and extracting a stroke matrix of the second character to be compared from the image sample of the second character to be compared.
[0060] S403: Calculate similarity values between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, and construct a similarity matrix according to the similarity values.
[0061] S404: Input the similarity matrix into the first input end of the two-headed neural network; input the image sample of the first text to be compared and the stroke matrix of the first text to be compared into the second input end of the two-headed neural network; when the text in the image sample of the first text to be compared and the image sample of the second text to be compared are the same, use the digital identifier used to represent the similarity as the output value of the two-headed neural network; when the text in the image sample of the first text to be compared and the image sample of the second text to be compared are different, use the digital identifier used to represent the dissimilarity as the output value of the two-headed neural network, and train the two-headed neural network model.
[0062] For example, when the first text to be compared and the second text to be compared displayed on the image sample are the same, 1 is used as the output value of the two-headed neural network; when the first text to be compared and the second text to be compared displayed on the image sample are different, 0 is used as the output value of the two-headed neural network.
[0063] For other relevant steps of the dual-headed neural network training method, please refer to Figure 1 or Figure 3 The contents of the illustrated implementation manner will not be repeated here.
[0064] The embodiment of this specification also provides a text recognition method, such as Figure 5 As shown, the following steps are included.
[0065] S501: extracting an image of the text to be recognized from the image of the text to be recognized.
[0066] S502: Obtaining pictures of characters in the text picture library in sequence.
[0067] S503: Obtain the stroke matrix of the character to be recognized and the stroke matrix of the characters in the character image library.
[0068] S504: Calculate the similarity values between the stroke matrix of the character to be recognized and the stroke matrix of the characters in the character image library, and construct a similarity matrix according to the similarity values.
[0069] S505: Input the similarity matrix, the stroke matrix of the text to be recognized and the image of the text to be recognized into a two-headed neural network to obtain the similarity between the text to be recognized and the text in the text image library.
[0070] S506: Outputting a text recognition result that meets predetermined requirements according to the obtained similarity.
[0071] Step S506 may be to output the text in the text image library corresponding to the maximum similarity as the recognition result, output the text in the text image library corresponding to a predetermined number of maximum similarities as the recognition result, and output the text in the text image library corresponding to a similarity greater than a second predetermined threshold as the recognition result.
[0072] For example, if the similarities between the character A to be recognized and the characters B1, B2, B3, B4, and B5 in the character library are 0.2, 0.6, 0.8, 0.1, and 0.4 respectively, then the character B3 can be directly used as the recognition result; or the characters B3 and B2 can be presented as the recognition results for further selection by the user.
[0073] Of course, step S506 can also output text recognition results that meet other requirements, which will not be listed one by one in this manual.
[0074] Figure 6 The schematic diagram of a text comparison device according to an embodiment of the present specification is shown. The text comparison device can be used to perform Figure 1 The text comparison method shown in the figure. Figure 6As shown, the device includes a capture unit 10 , an acquisition unit 20 , a calculation unit 30 and an ascertainment unit 40 .
[0075] The interception unit 10 is used to intercept the image of the first text to be compared from the first image to be compared, and to intercept the image of the second text to be compared from the second image to be compared. The acquisition unit 20 is used to obtain the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared. The calculation unit 30 is used to calculate the similarity value of the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared, and to construct a similarity matrix based on the similarity value. The obtaining unit 40 is used to input the similarity matrix, the stroke matrix of the first text to be compared and the image of the first text to be compared into a double-headed neural network to obtain the similarity between the first text to be compared and the second text to be compared.
[0076] In some embodiments, Figure 7 As shown, the obtaining unit 40 includes a first input subunit 41 , a second input subunit 42 , an extraction subunit 43 and a processing unit 44 .
[0077] The first input subunit 41 is used to input the similarity matrix into the first input end of the two-headed neural network. The second input subunit 42 is used to input the stroke matrix of the first character to be compared and the image of the first character to be compared into the second input end of the two-headed neural network, wherein the two-headed neural network includes: a first layer and a second layer. The extraction subunit 43 is used to extract features from the stroke matrix of the first character to be compared and the first image to be compared input into the second input end through the first layer to obtain a feature matrix. The processing unit 44 is used to process the feature matrix and the similarity matrix input into the first input end through the second layer to obtain a similarity value, and use the similarity value as the similarity between the first character to be compared and the second character to be compared.
[0078] In some embodiments, the text comparison device also includes a model training unit, which trains a double-headed neural network in the following manner: obtaining a picture sample of a first text to be compared and a picture sample of a second text to be compared; extracting a stroke matrix of the first text to be compared from the picture sample of the first text to be compared, and extracting a stroke matrix of the second text to be compared from the picture sample of the second text to be compared; calculating the similarity value between the stroke matrix of the first text to be compared and the stroke matrix of the second text to be compared, and constructing a similarity matrix according to the similarity value; inputting the similarity matrix into a first input end of the double-headed neural network; inputting the picture sample of the first text to be compared and the stroke matrix of the first text to be compared into a second input end of the double-headed neural network; when the text in the picture sample of the first text to be compared and the picture sample of the second text to be compared is the same, using a digital identifier used to represent similarity as the output value of the double-headed neural network, and when the text in the picture sample of the first text to be compared and the picture sample of the second text to be compared is different, using a digital identifier used to represent dissimilarity as the output value of the double-headed neural network, and training the double-headed neural network model.
[0079] In some embodiments, the text comparison device further includes a fusion unit for performing a predetermined logical operation or arithmetic operation on the stroke matrix of the first text to be compared, so as to merge at least two stroke matrices into one matrix.
[0080] The description and functions of the above units can be understood by referring to the content of the text comparison method part, which will not be repeated here.
[0081] The embodiment of this specification also provides a text recognition device. The text recognition device can be used to perform Figure 5 The text recognition method shown in the figure. The device comprises a cutting unit 10, an acquiring unit 20, a calculating unit 30 and a obtaining unit 40, and further comprises an output unit 50.
[0082] The interception unit 10 is used to intercept the image of the text to be recognized from the image of the text to be recognized. The acquisition unit 20 is used to sequentially acquire the images of the text in the text image library, and acquire the stroke matrix of the text to be recognized and the stroke matrix of the text in the text image library. The calculation unit 30 is used to calculate the similarity value between the stroke matrix of the text to be recognized and the stroke matrix of the text in the text image library, and construct a similarity matrix based on the similarity value. The obtaining unit 40 is used to input the similarity matrix, the stroke matrix of the text to be recognized and the image of the text to be recognized into a double-headed neural network to obtain the similarity between the text to be recognized and the text in the text image library. The output unit 50 is used to output a text recognition result that meets predetermined requirements based on the obtained similarity.
[0083] The description and functions of the above units can be understood by referring to the content of the text comparison method part, which will not be repeated here.
[0084] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, the electronic device may include a processor 81 and a memory 82, wherein the processor 81 and the memory 82 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.
[0085] The processor 81 may be a central processing unit (CPU). The processor 81 may 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, or a combination of the above chips.
[0086] The memory 82 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the text comparison or recognition method in the embodiment of the present invention (for example, Figure 6 The processor 81 executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory 82, that is, the text comparison or recognition method in the above method embodiment is implemented.
[0087] The memory 82 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created by the processor 81, etc. In addition, the memory 82 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 82 may optionally include a memory remotely arranged relative to the processor 81, and these remote memories may be connected to the processor 81 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0088] The one or more modules are stored in the memory 82 and when executed by the processor 81, perform the following steps: Figure 1 The text comparison method in the embodiment shown or Figure 5The text recognition method in the illustrated embodiment.
[0089] For details of the above electronic equipment, please refer to Figure 1 or Figure 5 The corresponding descriptions and effects in the embodiments can be understood and will not be repeated here.
[0090] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0091] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip2. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog2. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0092] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0093] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions.
[0094] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0095] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute certain parts of the methods of each implementation method of the present application.
[0096] The present application can be used in many general or special computer system environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.
[0097] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0098] Although the present application has been described through embodiments, those skilled in the art will appreciate that there are many modifications and variations to the present application without departing from the spirit of the present application, and it is intended that the appended claims include these modifications and variations without departing from the spirit of the present application.
Claims
1. A text comparison method, characterized in that: include: Cut out a picture of the first text to be compared from the first picture to be compared, and cut out a picture of the second text to be compared from the second picture to be compared; Obtain a stroke matrix of a first character to be compared and a stroke matrix of a second character to be compared; Calculating similarity values between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, and constructing a similarity matrix according to the similarity values; Inputting the similarity matrix, the stroke matrix of the first character to be compared and the image of the first character to be compared into a double-headed neural network to obtain the similarity between the first character to be compared and the second character to be compared; Inputting the similarity matrix, the stroke matrix of the first character to be compared, and the image of the first character to be compared into a double-headed neural network, and obtaining the similarity between the first character to be compared and the second character to be compared includes: Inputting the similarity matrix into the first input terminal of the double-headed neural network; Inputting the stroke matrix of the first character to be compared and the picture of the first character to be compared into the second input end of the double-headed neural network, wherein the double-headed neural network includes: a first layer and a second layer; Extracting features of the stroke matrix of the first character to be compared and the first picture to be compared inputted from the second input end through the first layer to obtain a feature matrix; The feature matrix and the similarity matrix input from the first input end are processed by the second layer to obtain a similarity value, and the similarity value is used as the similarity between the first text to be compared and the second text to be compared.
2. The text comparison method according to claim 1, characterized in that: The dual-head neural network is trained in the following way: Obtaining a picture sample of the first text to be compared and a picture sample of the second text to be compared; Extracting a stroke matrix of the first character to be compared from the image sample of the first character to be compared, and extracting a stroke matrix of the second character to be compared from the image sample of the second character to be compared; Calculating similarity values between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, and constructing a similarity matrix according to the similarity values; The similarity matrix is input into the first input end of the two-headed neural network; the image sample of the first text to be compared and the stroke matrix of the first text to be compared are input into the second input end of the two-headed neural network; when the characters in the image sample of the first text to be compared and the image sample of the second text to be compared are the same, the digital identifier used to represent similarity is used as the output value of the two-headed neural network; when the characters in the image sample of the first text to be compared and the image sample of the second text to be compared are different, the digital identifier used to represent dissimilarity is used as the output value of the two-headed neural network, and the two-headed neural network model is trained.
3. The text comparison method according to claim 1, characterized in that: The stroke matrix of the first character to be compared includes at least two stroke matrices; Before calculating the similarity value between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, the method further includes: A predetermined logical operation or arithmetic operation is performed on the stroke matrix of the first character to be compared, so as to merge at least two stroke matrices into one matrix.
4. A method for character recognition, characterized in that: include: Cut out the picture of the text to be recognized from the picture of the text to be recognized; Get the pictures of the text in the text picture library in sequence; Obtain the stroke matrix of the text to be recognized and the stroke matrix of the text in the text image library; Calculating similarity values between the stroke matrix of the character to be recognized and the stroke matrix of the characters in the character image library, and constructing a similarity matrix according to the similarity values; Input the similarity matrix, the stroke matrix of the character to be recognized and the picture of the character to be recognized into a double-headed neural network to obtain the similarity between the character to be recognized and the characters in the character picture library; Outputting a text recognition result that meets predetermined requirements according to the obtained similarity; Inputting the similarity matrix, the stroke matrix of the character to be recognized and the picture of the character to be recognized into a double-headed neural network, and obtaining the similarity between the character to be recognized and the characters in the character picture library includes: Inputting the similarity matrix into the first input terminal of the double-headed neural network; Inputting the stroke matrix of the character to be recognized and the picture of the character to be recognized into the second input end of the double-headed neural network, wherein the double-headed neural network includes: a first layer and a second layer; Extracting features of the stroke matrix of the to-be-recognized characters and the picture of the to-be-recognized characters inputted from the second input terminal through the first layer to obtain a feature matrix; The feature matrix and the similarity matrix input from the first input end are processed by the second layer to obtain a similarity value, and the similarity value is used as the similarity between the text to be recognized and the text in the text image library.
5. The text recognition method according to claim 4, characterized in that: Outputting a text recognition result that meets predetermined requirements according to the obtained similarity includes at least one of the following: The text in the text image library corresponding to the maximum similarity is output as the recognition result, the text in the text image library corresponding to a predetermined number of maximum similarities is output as the recognition result, and the text in the text image library corresponding to the similarity greater than the second predetermined threshold is output as the recognition result.
6. A text comparison device, characterized in that: include: A cutting unit, used for cutting out a picture of the first text to be compared from the first picture to be compared, and cutting out a picture of the second text to be compared from the second picture to be compared; An acquisition unit, used for acquiring a stroke matrix of a first character to be compared and a stroke matrix of a second character to be compared; A calculation unit, used for calculating similarity values between the stroke matrix of the first character to be compared and the stroke matrix of the second character to be compared, and constructing a similarity matrix according to the similarity values; An obtaining unit, used for inputting the similarity matrix, the stroke matrix of the first character to be compared and the image of the first character to be compared into a double-headed neural network to obtain the similarity between the first character to be compared and the second character to be compared; Inputting the similarity matrix, the stroke matrix of the first character to be compared, and the image of the first character to be compared into a double-headed neural network, and obtaining the similarity between the first character to be compared and the second character to be compared includes: Inputting the similarity matrix into the first input terminal of the double-headed neural network; Inputting the stroke matrix of the first character to be compared and the picture of the first character to be compared into the second input end of the double-headed neural network, wherein the double-headed neural network includes: a first layer and a second layer; Extracting features of the stroke matrix of the first character to be compared and the first picture to be compared inputted from the second input end through the first layer to obtain a feature matrix; The feature matrix and the similarity matrix input from the first input end are processed by the second layer to obtain a similarity value, and the similarity value is used as the similarity between the first text to be compared and the second text to be compared.
7. A text recognition device, characterized in that: include: A capture unit, used to capture the image of the text to be recognized from the image of the text to be recognized; An acquisition unit, used to sequentially acquire images of characters in a character image library, and acquire a stroke matrix of the character to be recognized and a stroke matrix of the character in the character image library; A calculation unit, used for calculating the similarity values between the stroke matrix of the character to be recognized and the stroke matrix of the characters in the character image library, and constructing a similarity matrix according to the similarity values; An obtaining unit, used for inputting the similarity matrix, the stroke matrix of the character to be recognized and the picture of the character to be recognized into a double-headed neural network to obtain the similarity between the character to be recognized and the characters in the character picture library; An output unit, used to output a text recognition result that meets predetermined requirements according to the obtained similarity; Inputting the similarity matrix, the stroke matrix of the character to be recognized and the picture of the character to be recognized into a double-headed neural network, and obtaining the similarity between the character to be recognized and the characters in the character picture library includes: Inputting the similarity matrix into the first input terminal of the double-headed neural network; Inputting the stroke matrix of the character to be recognized and the picture of the character to be recognized into the second input end of the double-headed neural network, wherein the double-headed neural network includes: a first layer and a second layer; Extracting features of the stroke matrix of the to-be-recognized characters and the picture of the to-be-recognized characters inputted from the second input terminal through the first layer to obtain a feature matrix; The feature matrix and the similarity matrix input from the first input end are processed by the second layer to obtain a similarity value, and the similarity value is used as the similarity between the text to be recognized and the text in the text image library.
8. An electronic device, characterized in that: include: A memory and a processor, wherein the processor and the memory are communicatively connected to each other, the memory stores computer instructions, and the processor implements the steps of the method according to any one of claims 1 to 5 by executing the computer instructions.
9. A computer storage medium, characterized in that The computer storage medium stores computer program instructions, and when the computer program instructions are executed, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Handwritten model training method, handwriting recognition method, device, equipment and medium
CN108764195A
Handwriting model training method, handwriting recognition method, device and apparatus and medium
CN108985442A