Handwriting sample digitization method, device, computer equipment and storage medium
By combining and serializing the image pixel matrix and annotation information on the handwriting sample data set, a binary file is generated, which solves the problems of large calculation volume and low efficiency caused by inconsistent data formats in handwriting text recognition model training, and achieves a more efficient model training.
Patent Information
- Application Number
- CN201811085666.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-09-18
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2038-09-18
AI Technical Summary
The existing handwriting sample data format is not uniform, which leads to the problem of large calculation amount and low training efficiency of the handwritten text recognition model.
By obtaining the sample pictures and annotation information in the handwriting sample data set, the image pixel matrix is generated, combined with the annotation information according to the preset combination method, serialized, and the binary sequence is obtained, written into the sample data file, and saved in the database. .
Convert handwritten sample data into a unified binary file to reduce the amount of calculation, reduce resource consumption, and improve the efficiency of model training.
Smart Images

Figure CN109492657B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a handwriting sample digitization method, device, computer equipment and storage medium. Background Art
[0002] In the research on handwritten text recognition, a large number of handwritten samples need to be prepared to support the model training of the handwritten text recognition model.
[0003] However, current handwriting samples are often collected manually. Due to the wide variety of handwriting samples, the data formats of the manually collected handwriting samples are different. If the manually collected handwriting sample data set is directly used for model training of the handwriting text recognition model, the model calculation will result in a huge amount of data, high resource consumption, and reduced model training efficiency. Summary of the invention
[0004] The embodiments of the present invention provide a handwriting sample digitization method, apparatus, computer equipment and storage medium to solve the problem that the current handwriting sample data format is not unified, resulting in a large amount of calculation and low training efficiency of the handwriting text recognition model.
[0005] A handwriting sample digitization method, comprising:
[0006] Obtaining a handwriting sample from a handwriting sample data set, wherein the handwriting sample includes a sample image and annotation information of the sample image;
[0007] Generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture;
[0008] Combining the image pixel matrix and the annotation information according to a preset combination method to obtain element information corresponding to the handwriting sample;
[0009] Serializing the element information to obtain a binary sequence corresponding to the element information;
[0010] Writing the binary sequence into a preset sample data file;
[0011] The sample data file is saved in a preset sample database.
[0012] A handwriting sample digitizing device, comprising:
[0013] A sample acquisition module, used to acquire a handwriting sample in a handwriting sample data set, wherein the handwriting sample includes a sample image and annotation information of the sample image;
[0014] A matrix generation module, used to generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture;
[0015] An information combination module, used to combine the image pixel matrix and the annotation information according to a preset combination method to obtain element information corresponding to the handwriting sample;
[0016] A serialization module, used to perform serialization processing on the element information to obtain a binary sequence corresponding to the element information;
[0017] A data writing module, used for writing the binary sequence into a preset sample data file;
[0018] The file saving module is used to save the sample data file into a preset sample database.
[0019] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned handwriting sample digitization method when executing the computer program.
[0020] A computer-readable storage medium stores a computer program, which implements the steps of the handwriting sample digitization method when executed by a processor.
[0021] In the above-mentioned handwriting sample digitization method, device, computer equipment and storage medium, by combining the image pixel matrix of the sample image in the handwriting sample data set and the annotation information of the sample image, and serializing the obtained element information, a binary sequence corresponding to the element information is obtained, and the binary sequence is written into a preset sample data file, thereby realizing the conversion of each handwriting sample data in the handwriting sample data set into a unified serialized binary file, so that the binary file can be directly used to train and tune the handwritten text recognition model, reduce the amount of calculation, reduce resource consumption, improve calculation efficiency, and thus improve the efficiency of model training. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0023] Figure 1 is a schematic diagram of an application environment of a handwriting sample digitization method in one embodiment of the present invention;
[0024] Figure 2 is a flow chart of a method for digitizing a handwriting sample in one embodiment of the present invention;
[0025] Figure 3 is a schematic diagram of a specific sample image in a handwriting sample digitization method in one embodiment of the present invention;
[0026] Figure 4 is a flow chart of step S4 in the handwriting sample digitization method in one embodiment of the present invention;
[0027] Figure 5 is a flow chart of step S43 in the handwriting sample digitization method in one embodiment of the present invention;
[0028] Figure 6 is another flow chart of step S4 in the handwriting sample digitization method in one embodiment of the present invention;
[0029] Figure 7 is a flow chart of step S6 in the handwriting sample digitization method in one embodiment of the present invention;
[0030] Figure 8 is a flow chart of a recovery process of a handwriting sample in a handwriting sample digitization method in one embodiment of the present invention;
[0031] Fig. 9 is a flow chart of step S74 in the handwriting sample digitization method in one embodiment of the present invention;
[0032] Fig.10 is a schematic diagram of a handwriting sample digitizing device in one embodiment of the present invention;
[0033] Fig.11 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] The handwriting sample digitization method provided in this application can be applied to Figure 1In the application environment shown, the application environment includes a server and a client, wherein the server and the client are connected via a network, which may be a wired network or a wireless network, the client specifically includes but is not limited to various personal computers, laptops, smart phones, tablet computers, and portable wearable devices, and the server may be implemented using an independent server or a server cluster consisting of multiple servers. The client sends the collected handwriting sample data set to the server, and the server digitizes the handwriting samples in the received handwriting sample data set.
[0036] In one embodiment, if Figure 2 As shown, a handwriting sample digitization method is provided, and the method is applied in Figure 1 The server in is used as an example to illustrate the details as follows:
[0037] S1: Obtain a handwriting sample in a handwriting sample dataset, wherein the handwriting sample includes a sample image and annotation information of the sample image.
[0038] Specifically, the handwriting sample data set includes different types of handwriting samples collected in advance, and each handwriting sample includes a sample image and annotation information of the sample image.
[0039] The annotation information of the sample image includes preset annotation attributes, and these annotation attributes are combined according to a preset format. The preset annotation attributes include, but are not limited to: the image name of the sample image, the image size of the sample image, the text content in the sample image, and the relative position information of the text content in the sample image.
[0040] The relative position information may be expressed as: (the coordinate position of the pixel point at the upper left corner of the text content in the sample image), and the size of the image of the area where the text content is located.
[0041] For example, Figure 3 The annotation information of the sample image shown can be:
[0042] {11_bolepianti_C000008_1202_10.png|280*70|"Woolen, 1.5 million sets of clothing"|(3,3), 270*64}
[0043] Among them, 11_bolepianti_C000008_1202_10.png is the image name of the sample image, which includes the relative storage path of the sample image; 280*70 is the image size of the sample image, that is, the length is 280 pixels and the width is 70 pixels; "wool, 1.5 million sets of clothing" is the text content in the sample image; (3, 3) represents the coordinate position of the upper left corner pixel point A of the text content in the sample image, that is, the position 3 pixels to the right and 3 pixels below the upper left corner of the sample image as the coordinate origin; 270*64 is the size of the image B where the text content is located, that is, the length of the pixel area occupied by the text content is 270 pixels and the width is 64 pixels.
[0044] S2: Generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture.
[0045] Specifically, according to the image size of the sample image in the annotation information, the pixel value of each pixel in the sample image is obtained, and the pixel value of each pixel is used to form an image pixel matrix according to the image size of the sample image.
[0046] S3: combining the image pixel matrix and the annotation information of the sample image according to a preset combination method to obtain element information corresponding to the handwriting sample.
[0047] Specifically, the image pixel matrix of the sample image is combined with the annotation information. The preset combination method can be a tuple method, or a JSON (JavaScript Object Notation) method, or other combination methods. It can be set according to the needs of the actual application and is not limited here.
[0048] For example, if the image pixel matrix is img1 and the labeling information is label1, if the combination method is tuple method, the element information corresponding to the obtained handwriting sample is expressed as (img1, label1); if the combination method is JSON method, the element information corresponding to the obtained handwriting sample is expressed as {"img":img1, "label":label1}.
[0049] Continue with Figure 3 Taking the sample picture shown as an example, when the element information is represented in tuple form, label1 can be specifically represented as: "11_bolepianti_C000008_1202_10.png|280*70|"woolen, 1.5 million sets of clothing"|(3,3), 270*64"; when the element information is represented in JSON form, label1 can be specifically represented as the following multiple key-value pairs:
[0050]
[0051] S4: Serialize the element information to obtain a binary sequence corresponding to the element information.
[0052] Specifically, the element information obtained in step S3 is serialized, and the element information is converted into a binary digital string to obtain a binary sequence corresponding to the element information. The serialization process includes serialization of the image pixel matrix and serialization of the annotation information.
[0053] Serialization is the process of converting the state information of an object into a form that can be stored or transmitted. Serialization can make handwriting samples easy to store and transmit.
[0054] S5: Write the binary sequence into a preset sample data file.
[0055] Specifically, the binary sequence obtained by the serialization process in step S4 is written into a preset sample data file. In the preset sample data file, each line of data corresponds to a binary sequence of a handwriting sample. The suffix of the sample data file can be customized, for example, the suffix is .dt.
[0056] It can be understood that there may be one or more sample data files.
[0057] S6: Save the sample data file into a preset sample database.
[0058] Specifically, the sample database is used to store handwriting samples, and the sample data file written with the binary sequence obtained in step S5 is saved in the sample database.
[0059] It should be noted that the sample data file is a binary file, which is easy to store and transmit, and can be directly input into the handwritten text recognition model as a training sample or a test sample. The handwritten text recognition model can directly read the sample data for training and tuning according to the data storage structure in the sample data file. Compared with the huge amount of computation required for model training using the original handwritten sample data set, using serialized sample data for model training can effectively reduce the amount of computation required during model training, improve computing efficiency, and reduce resource consumption.
[0060] In this embodiment, by combining the image pixel matrix of the sample image in the handwriting sample data set and the annotation information of the sample image, and serializing the obtained element information, a binary sequence corresponding to the element information is obtained, and the binary sequence is written into a preset sample data file, thereby converting each handwriting sample data in the handwriting sample data set into a unified serialized binary file, which is easy to store and transmit, and the binary file can be directly used to train and tune the handwriting text recognition model, thereby reducing the amount of calculation, reducing resource consumption, and improving calculation efficiency, thereby improving the efficiency of model training.
[0061] In one embodiment, the annotation information of the sample image includes at least one annotation attribute. The annotation attribute is used to identify the features of the sample image and the features of the handwritten text in the sample image.
[0062] Specifically, the annotation attribute may be at least one of a picture name of the sample picture, a picture size of the sample picture, text content in the sample picture, and relative position information of the text content in the sample picture.
[0063] Furthermore, if Figure 4 As shown, in step S4, the element information is serialized to obtain a binary sequence corresponding to the element information, which specifically includes the following steps:
[0064] S41: Extracting pixel values in the image pixel matrix in a preset order to obtain a pixel value sequence.
[0065] Specifically, since the picture pixel matrix is a matrix composed of the pixel values of each pixel in the sample picture, when the picture pixel matrix is serialized, the pixel values in the matrix are directly converted into a pixel value sequence in a preset order.
[0066] The preset order may be from left to right and from top to bottom, or any other order. The order may be set as required and is not limited here.
[0067] For example, suppose the image pixel matrix is The preset order is from left to right and from top to bottom, so the pixel value sequence obtained after serialization processing of the pixel matrix of the image is: 122, 130, 98, 210, 18, 70, 40, 55, 255.
[0068] S42: Parsing the annotation information according to the annotation format preset in the annotation information to obtain each annotation attribute in the annotation information.
[0069] Specifically, the preset annotation format is the format of the annotation information, which defines the arrangement format of the annotation attributes in the annotation information. The annotation information is parsed according to the preset annotation format to obtain each annotation attribute.
[0070] Furthermore, if the element information is represented in tuple form, the annotation information in the tuple is first obtained, and then the annotation information is parsed according to the annotation format preset in the annotation information to obtain the string corresponding to each annotation attribute. If the element information is represented in JSON form, a parsing tool provided by a third party, such as Fastjson, can be directly used to parse the key-value pairs to obtain the string corresponding to each annotation attribute.
[0071] Continue with Figure 3 Taking the sample picture shown as an example, each of the annotation attributes obtained by parsing is: 11_bolepianti_C000008_1202_10.png, 280*70, "woolen, 1.5 million sets of clothing" and (3, 3), 270*64.
[0072] S43: Serialize each annotation attribute respectively to obtain an attribute serialization result of each annotation attribute.
[0073] Specifically, each annotation attribute parsed in step S42 is serialized, and the content of each annotation attribute is converted into a binary digital string to obtain an attribute serialization result of each annotation attribute.
[0074] S44: Connect the pixel value sequence and the attribute serialization result of each annotation attribute into the serialization result of the element information according to a preset connection method, and convert the serialization result of the element information into a binary sequence.
[0075] The default connection method can be to use specific symbols or characters to connect two different serialization results.
[0076] Specifically, according to a preset connection method, the pixel value sequence obtained in step S41 and the attribute serialization result of each annotation attribute obtained in step S43 are connected into the serialization result of the element information, and the serialization result of the element information is converted into a binary sequence.
[0077] Continue with Figure 3 Taking the sample picture shown as an example, if the preset connection method is to use ";" to connect two different serialization results, the serialization result of the element information is: 122, 130, 98, 210, 18, 70, 40, 55, 255; k1; k2; k3; k4. Among them, k1, k2, k3 and k4 represent the attribute serialization results of each annotation attribute respectively.
[0078] In this embodiment, by serializing the image pixel evidence and annotation information respectively, the pixel values in the image pixel matrix are extracted in a preset order to obtain a pixel value sequence. At the same time, the annotation information is parsed according to the preset annotation format in the annotation information to obtain each annotation attribute in the annotation information, and each annotation attribute is serialized respectively to obtain the attribute serialization result of each annotation attribute. Then, according to a preset connection method, the pixel value sequence and the attribute serialization result of each annotation attribute are connected into the serialization result of the element information, and the serialization result of the element information is converted into a binary sequence, thereby realizing serialization processing of the element information of the handwriting sample, converting the element information into a unified serialized binary sequence, thereby facilitating the storage and transmission of the handwriting sample, and being able to directly use the handwriting sample of the binary sequence to train and tune the handwriting text recognition model, thereby reducing the amount of calculation, reducing resource consumption, and improving calculation efficiency, thereby improving the efficiency of model training.
[0079] In one embodiment, the annotation attributes include the image name of the sample image, the image size of the sample image, the text content in the sample image, and the relative position information of the text content in the sample image, and the attribute serialization results of the annotation attributes include the attribute serialization results of the image name, the attribute serialization results of the image size, the attribute serialization results of the text content, and the attribute serialization results of the relative position information.
[0080] Furthermore, if Figure 5 As shown, in step S43, each annotation attribute is serialized respectively to obtain the attribute serialization result of each annotation attribute, which specifically includes the following steps:
[0081] S431: Select an unused random number from a preset random number pool as the attribute serialization result of the picture name, and save the picture name and the unused random number in a preset mapping table in correspondence.
[0082] The preset random number pool contains a sufficient number of non-repetitive random numbers. Each random number corresponds to a usage identifier, which is used to identify whether the random number has been used. When a random number with a usage identifier of "unused" is selected from the random number pool, the usage identifier of the random number is modified to "used" and will not be used again until the sample image corresponding to the random number is deleted, and the usage identifier of the random number is modified to "unused" again.
[0083] Specifically, a random number marked as "unused" is selected from the random number pool as the attribute serialization result of the picture name, and the picture name and the unused random number are correspondingly saved in a preset mapping table.
[0084] Continue with Figure 3Taking the sample picture shown as an example, a random number 4809803782 with a usage identifier of "unused" is selected from the random number pool as the attribute serialization result of the picture name "11_bolepianti_C000008_1202_10.png", and 11_bolepianti_C000008_1202_10.png and 4809803782 are correspondingly saved in the mapping table.
[0085] The preset mapping table is used to record the picture name of each sample picture and its corresponding random number, so as to be used when deserializing the picture name of the sample picture.
[0086] S432: Parse the image size according to a preset size format of the image size to obtain size data, and use the obtained size data as a result of attribute serialization of the image size.
[0087] Specifically, if the preset size format of the image size is that the image size of the sample image is defined by the number of pixels contained in the length and width of the sample image respectively, the image size is parsed, and the obtained size data is the length and width of the sample image, and the size data is used as the attribute serialization result of the image size.
[0088] Continue with Figure 3 Taking the sample picture shown as an example, the attribute serialization result corresponding to the picture size "280*70" is: 280, 70.
[0089] S433: According to a preset character encoding dictionary, obtain the encoding corresponding to each character in the text content, and use the encoding as the attribute serialization result of the text content.
[0090] In the preset character encoding dictionary, the encodings corresponding to characters such as Chinese characters, punctuation marks, letters, and numbers are set according to a predetermined encoding method, and the encodings are globally unique.
[0091] Specifically, according to a preset character encoding dictionary, the encoding corresponding to each character in the text content is obtained, and the obtained encoding is used as the attribute serialization result of the text content.
[0092] Continue with Figure 3 Taking the sample picture shown as an example, the attribute serialization result corresponding to the text content "woolen, 1.5 million sets of clothing" is: b1, b2, ..., b10. Among them, b1 is the code corresponding to the character "wolen", b2 is the code corresponding to the character "woolen", b3 is the code corresponding to the character ",", b4 is the code corresponding to the character "1", and so on, b10 is the code corresponding to the character "dress".
[0093] It should be noted that the predetermined encoding method can be Unicode encoding, one-hot encoding, or other encoding methods. The specific selection can be made according to the needs of the actual application and is not set here.
[0094] S434: Parse the relative position information according to the position representation method preset in the relative position information, and use the obtained position data as the attribute serialization result of the relative position information.
[0095] Specifically, if the preset position representation in the relative position information is: (the coordinate position of the upper left corner pixel of the text content in the sample image), the size of the area image where the text content is located, where the coordinate position and size are both numbers, then the relative position information is directly parsed according to the position representation, and the obtained coordinates and sizes are used as the serialization results of the relative position information.
[0096] Continue with Figure 3 Taking the sample picture shown as an example, the attribute serialization result corresponding to the relative position information "(3, 3), 270*64" is: 3, 3, 270, 64.
[0097] It should be noted that there is no necessary order of execution among step S431, step 432, step S433 and step S434, and they can be executed in parallel, which is not limited here.
[0098] In this embodiment, when the annotation attributes include the picture name of the sample picture, the picture size of the sample picture, the text content in the sample picture, and the relative position information of the text content in the sample picture, the attribute serialization results of the annotation attributes include the attribute serialization results of the picture name, the attribute serialization results of the picture size, the attribute serialization results of the text content, and the attribute serialization results of the relative position information. Each annotation attribute is parsed according to the representation method of each annotation attribute to obtain the attribute serialization results of each annotation attribute, so that the annotation attributes are serialized in a targeted manner according to the different characteristics of each annotation attribute to ensure the accuracy of the serialization results.
[0099] In one embodiment, if Figure 6 As shown, in step S4, the element information is serialized to obtain a binary sequence corresponding to the element information, which specifically includes the following steps:
[0100] S401: Calculate the hash value of the character string corresponding to the element information.
[0101] Specifically, the hash value of each character in the string corresponding to each element information is calculated according to formula (1):
[0102] hash[i]=(hash[i-1]*p+f(s[i]))%m formula (1)
[0103] Among them, i is the subscript of the string corresponding to the element information, i is greater than or equal to 1 and less than or equal to I, I is the length of the string, s[i] is the i-th character in the string corresponding to the element information, the f(x) function is used to define the mapping relationship between the character x and the number that uniquely identifies the character, f(s[i]) is the preset number mapped to the character s[i], hash[i] is the hash value of the i-th character, and hash[0] is set to 1, and p and m are preset parameters.
[0104] The hash value hash[I] of the I-th character calculated by the above formula is used as the hash value H of the character string corresponding to the element information, that is, H=hash[I].
[0105] It should be noted that the preset parameters p and m can usually be set to 13 and 101 respectively, that is, p=13, m=101, but are not limited to this. The specific values of p and m can be set according to the needs of actual application and are not limited here.
[0106] S402: Perform a modulo operation on the hash value and the number of preset serialization servers, and use the obtained operation result as the target serial number.
[0107] Specifically, the target sequence number is calculated according to formula (2):
[0108] M=H mod N Formula (2)
[0109] Among them, N is the number of preset serialization servers, H is the hash value of the string corresponding to the element information, and M is the target serial number.
[0110] The serialization server is used to serialize the element information. When the amount of handwriting sample data is huge, it takes a lot of time to serialize the element information, especially the annotation information. In order to improve the execution efficiency of the serialization processing, multiple serialization servers can be used for parallel processing.
[0111] S403: Determine the target serialization server corresponding to the target serial number according to the preset correspondence between the serial number and the serialization server.
[0112] The preset corresponding relationship is the mapping relationship between the pre-selected serial number and the serialization server. For example, assuming that the serialization server includes 4 servers A, B, C and D, that is, N=4, then the serial number is set to 0, 1, 2, 3, corresponding to serialization server A, serialization server B, serialization server C and serialization server D respectively.
[0113] Specifically, according to the target serial number obtained in step S402, a serialization server corresponding to a serial number identical to the target serial number is searched in the corresponding relationship, and the serialization server is determined as the target serialization server.
[0114] S404: Send the element information to the target serialization server for serialization processing.
[0115] Specifically, according to the target serialization server determined in step S403, the element information is sent to the target serialization server for serialization processing.
[0116] The process of serializing the element information by the serialization server may adopt the same method as in steps S41 to S43, and steps S431 to S434, and will not be described again here to avoid repetition.
[0117] S405: Receive the binary sequence corresponding to the element information returned by the target serialization server.
[0118] Specifically, after completing the serialization processing of the received element information, the target serialization server returns the binary sequence corresponding to the element information to the server.
[0119] In this embodiment, the hash value of the character string corresponding to the element information is calculated by formula (1), and the modulus operation between the hash value and the number of serialization servers is performed using formula (2) to obtain the target serial number. Then, according to the preset correspondence between the serial number and the serialization server, the target serialization server corresponding to the target serial number is determined, and then the element information is sent to the target serialization server for serialization processing. This achieves the goal of evenly distributing different element information to different serialization servers for serialization processing according to the hash value, so that multiple serialization servers complete the serialization process of the element information in parallel, thereby improving the execution efficiency of serialization.
[0120] In one embodiment, if Figure 7 As shown, in step S6, the sample data file is saved in a preset sample database, which specifically includes the following steps:
[0121] S61: Encrypt the sample data file according to a preset encryption method to obtain an encrypted sample file.
[0122] Specifically, after obtaining the sample data file, the sample data file is further encrypted. The preset encryption method can select the encryption algorithm commonly used in the prior art as needed, such as DES (Data Encryption Standard), AES (Advanced Encryption Standard), RSA asymmetric encryption algorithm, Base64 encryption algorithm, etc.
[0123] Furthermore, when generating encryption keys, corresponding encryption keys can be generated by classification according to the types of handwriting samples. Since the handwriting sample data set may contain different types of handwriting samples, the types of handwriting samples can identify the application scenarios to which the handwriting samples belong. When generating sample data files, sample data files corresponding to each type are generated by classification according to the types, and corresponding random numbers are pre-set for each type of handwriting sample. The random numbers are used to generate the encryption keys corresponding to the types according to the preset generation method, that is, each type of sample data file is encrypted using the encryption key of the type.
[0124] S62: Save the encrypted sample file into a preset sample database.
[0125] Specifically, the encrypted sample file obtained in step S61 is saved in a preset sample database.
[0126] Furthermore, when the sample data files are generated according to the type classification, the encrypted sample files and the types are correspondingly saved in the sample database.
[0127] In this embodiment, the security of the sample data file is improved by encrypting the sample data file, and encryption keys are further generated according to the type classification of the handwriting samples, so that different types of handwriting samples are encrypted using different encryption keys, making the encrypted sample data file more secure and effectively improving the data security of the handwriting samples.
[0128] In one embodiment, if Figure 8 As shown, after step S62, the handwriting sample digitization method further includes a recovery process of the handwriting sample, which specifically includes the following steps:
[0129] S71: If a request for obtaining a handwriting sample from a user is received, determining the user's obtaining authority according to the user identity information included in the obtaining request.
[0130] Specifically, if the user needs to view the sample image and annotation information of the handwriting sample, a request for obtaining the handwriting sample may be sent to the server, where the request includes user identity information, which is used to uniquely identify the user's identity.
[0131] The server receives the acquisition request, extracts the user identity information from the acquisition request, and determines whether the user is legal based on the legal identity information of the legal user stored on the server. If the user identity information of the user is legal, the user is confirmed to be legal, and the user's acquisition permission is determined to be allowed to obtain. If the user identity information of the user is not legal, the user is confirmed to be illegal, and the user's acquisition permission is determined to be not allowed to obtain.
[0132] Furthermore, if the user's access authority does not allow access, the server returns a prompt message indicating that the access failed to the user.
[0133] If the user's access authority allows access, then continue to step S72.
[0134] S72: If the user's access authority is to allow access, the encrypted sample file is obtained from the sample database, and the encrypted sample file is decrypted according to a preset decryption method to obtain a decrypted file.
[0135] Specifically, if the user's access authority is to allow access, the encrypted sample file is read from the sample database.
[0136] When decrypting the encrypted sample file, the preset decryption method is specifically the decryption method corresponding to the encryption method preset in step S61. For example, if when encrypting the sample data file, the corresponding encryption key is generated according to the type of the handwriting sample, and the encrypted sample file and the type are correspondingly saved in the sample database, then when decrypting the encrypted sample file, according to the type corresponding to the encrypted sample file, the random number corresponding to the type is obtained, and the random number is used to generate a decryption key corresponding to the encryption key according to the preset generation method, and then the decryption key is used to decrypt the encrypted sample file to obtain a decrypted file.
[0137] S73: Read the binary sequence corresponding to the element information from the decryption file.
[0138] Specifically, the binary sequence corresponding to the element information is read from the decrypted file. For example, if each line in the decrypted file is an element information, each line of data is read from the decrypted file to obtain the binary sequence of each element information.
[0139] S74: Deserialize the binary sequence to obtain a pixel matrix of the sample image and labeling information of the sample image.
[0140] Specifically, each binary sequence obtained in step S73 is deserialized. The deserialization process may be a process opposite to the serialization process in step S4. Through the deserialization process, the image pixel matrix and annotation information are obtained by reverse deduction. Then, the sample image can be restored according to the image pixel matrix, thereby obtaining the restored handwriting sample.
[0141] In this embodiment, the user's access authority is determined by performing identity verification on the user's access request, and when the access authority is allowed, the encrypted sample file is decrypted to obtain a decrypted file, and then the binary sequence in the decrypted file is deserialized to obtain the image pixel matrix and annotation information of the sample image, and then the sample image can be restored based on the image pixel matrix, and the restored handwriting sample can be obtained, thereby achieving accurate restoration of the handwriting sample through deserialization, and improving data security by verifying the user's identity.
[0142] In one embodiment, if Fig. 9 As shown, in step S74, the binary sequence is deserialized to obtain the image pixel matrix of the sample image and the annotation information of the sample image, which specifically includes the following steps:
[0143] S741: According to a preset connection method, parse the pixel value sequence and the binary data segment corresponding to each annotation attribute from the binary sequence.
[0144] Specifically, continue with Figure 3 Taking the sample picture shown as an example, if the preset connection method is to use ";" to connect two different serialization results, and the binary sequence is: p0; p1; p2; p3; p4, then p0 is parsed to be the binary data segment corresponding to the pixel value sequence, and p1, p2, p3 and p4 are the binary data segments corresponding to each annotation attribute respectively.
[0145] S742: According to a preset mapping table, a preset size format, a preset character encoding dictionary and a preset position identification method, the binary data segment corresponding to each annotation attribute is parsed to obtain the image name, image size, text content and relative position information respectively.
[0146] Specifically, according to a preset mapping table, query the picture name corresponding to the value of the binary data segment corresponding to the picture name in the mapping table; according to a preset size format, parse the picture size information represented by the binary data segment corresponding to the picture size, for example, length and width; according to a preset character encoding dictionary, query the character corresponding to the binary encoding of each character in the binary data segment corresponding to the text content in the character encoding dictionary; according to the position identification method, parse the relative position represented by the binary data segment corresponding to the relative position information, for example, the coordinate position of the upper left corner pixel of the text content in the sample picture and the size of the regional image where the text content is located.
[0147] S743: According to a preset annotation format, the image name, image size, text content and relative position information are combined into annotation information of the sample image.
[0148] Specifically, the picture name, picture size, text content and relative position information parsed in step S742 are combined into annotation information according to a preset annotation format.
[0149] For example, continue with Figure 3 Taking the sample picture shown as an example, if the preset annotation format is to use “|” to separate adjacent annotation attributes, the combined annotation information is: “11_bolepianti_C000008_1202_10.png|280*70|“woolen, 1.5 million sets of clothing”|(3, 3), 270*64”.
[0150] S744: Restore the image pixel matrix of the sample image according to the pixel value sequence and the image size.
[0151] Specifically, according to the image size of the sample image parsed in step S742, the length and width of the image pixel matrix are determined, and then the segmentation position of the pixel value sequence is determined according to the length and width, and the image pixel matrix is obtained by segmentation according to the segmentation position.
[0152] For example, if the pixel value sequence is "a1, a2, a3, a4, a5, a6", and the image size is 3*2, that is, 3 pixels long and 2 pixels wide, then the pixel value sequence is divided between every 3 consecutive pixel values, so the resulting image pixel matrix is
[0153] In this embodiment, first, according to a preset connection method, a pixel value sequence and a binary data segment corresponding to each annotation attribute are parsed from a binary sequence. Then, the binary data segment corresponding to each annotation attribute is parsed to obtain the image name, image size, text content and relative position information, and the image name, image size, text content and relative position information are combined into annotation information. Then, according to the pixel value sequence and the image size, the image pixel matrix is restored, and the binary sequence is deserialized to obtain an accurate image pixel matrix and annotation information, so that the handwriting sample that the user can view can be accurately restored.
[0154] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0155] In one embodiment, a handwriting sample digitization device is provided, and the handwriting sample digitization device corresponds to the handwriting sample digitization method in the above embodiment. Fig.10 As shown, the handwriting sample digitization device includes a sample acquisition module 101, a matrix generation module 102, an information combination module 103, a serialization module 104, a data writing module 105 and a file storage module 106. The functional modules are described in detail as follows:
[0156] The sample acquisition module 101 is used to acquire handwriting samples in the handwriting sample data set, wherein the handwriting samples include sample images and annotation information of the sample images;
[0157] The matrix generation module 102 is used to generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture;
[0158] An information combination module 103 is used to combine the image pixel matrix and the annotation information according to a preset combination method to obtain element information corresponding to the handwriting sample;
[0159] The serialization module 104 is used to perform serialization processing on the element information to obtain a binary sequence corresponding to the element information;
[0160] The data writing module 105 is used to write the binary sequence into a preset sample data file;
[0161] The file saving module 106 is used to save the sample data file into a preset sample database.
[0162] Furthermore, the annotation information includes at least one annotation attribute, and the serialization module 104 includes:
[0163] The pixel value extraction submodule is used to extract the pixel values in the image pixel matrix according to a preset order to obtain a pixel value sequence;
[0164] The annotation parsing submodule is used to parse the annotation information according to the annotation format preset in the annotation information to obtain each annotation attribute in the annotation information;
[0165] The attribute serialization submodule is used to serialize each annotation attribute separately to obtain the attribute serialization result of each annotation attribute;
[0166] The binary conversion submodule is used to connect the pixel value sequence and the attribute serialization result of each annotation attribute into the serialization result of the element information according to a preset connection method, and convert the serialization result of the element information into a binary sequence.
[0167] Further, the annotated attributes include the image name of the sample image, the image size of the sample image, the text content in the sample image, and the relative position information of the text content in the sample image. The attribute serialization results of the annotated attributes include the attribute serialization results of the image name, the attribute serialization results of the image size, the attribute serialization results of the text content, and the attribute serialization results of the relative position information. The attribute serialization submodule includes:
[0168] A name serialization unit, used to select an unused random number from a preset random number pool as the attribute serialization result of the picture name, and save the picture name and the unused random number in a preset mapping table in correspondence;
[0169] A size serialization unit, used to parse the image size according to a preset size format of the image size to obtain size data, and use the obtained size data as a result of attribute serialization of the image size;
[0170] The content serialization unit is used to obtain the encoding corresponding to each character in the text content according to a preset character encoding dictionary, and use the encoding as the attribute serialization result of the text content;
[0171] The position serialization unit is used to parse the relative position information according to the position representation method preset in the relative position information, and use the obtained position data as the attribute serialization result of the relative position information.
[0172] Furthermore, the serialization module 104 also includes:
[0173] The hash value calculation submodule is used to calculate the hash value of the string corresponding to the element information;
[0174] The serial number calculation submodule is used to perform a modulus operation between the hash value and the number of preset serialization servers, and use the obtained operation result as the target serial number;
[0175] A server determination submodule, used to determine a target serialization server corresponding to a target serial number according to a preset correspondence between the serial number and the serialization server;
[0176] The information sending submodule is used to send the element information to the target serialization server for serialization processing;
[0177] The sequence receiving submodule is used to receive the binary sequence corresponding to the element information returned by the target serialization server.
[0178] Furthermore, the file storage module 106 includes:
[0179] The encryption submodule is used to encrypt the sample data file according to a preset encryption method to obtain an encrypted sample file;
[0180] The save submodule is used to save the encrypted sample file into the preset sample database.
[0181] Furthermore, the handwriting sample digitization device also includes:
[0182] A request receiving module, configured to determine the user's access authority based on the user identity information contained in the access request if a user's access request for the handwriting sample is received;
[0183] The file decryption module is used to obtain the encrypted sample file from the sample database if the user's access authority is to allow access, and decrypt the encrypted sample file according to a preset decryption method to obtain a decrypted file;
[0184] A sequence reading module is used to read the binary sequence corresponding to the element information from the decrypted file;
[0185] The deserialization module is used to deserialize the binary sequence to obtain the image pixel matrix of the sample image and the annotation information of the sample image.
[0186] Furthermore, the deserialization module includes:
[0187] A first parsing submodule is used to parse the pixel value sequence and the binary data segment corresponding to each annotation attribute from the binary sequence according to a preset connection method;
[0188] The second parsing submodule is used to parse the binary data segment corresponding to each annotation attribute according to a preset mapping table, a preset size format, a preset character encoding dictionary and a preset position identification method, and obtain the image name, image size, text content and relative position information respectively;
[0189] A combination submodule, used to combine the image name, image size, text content and relative position information into the annotation information of the sample image according to a preset annotation format;
[0190] The restoration submodule is used to restore the image pixel matrix of the sample image according to the pixel value sequence and the image size.
[0191] The specific definition of the handwriting sample digitization device can be found in the definition of the handwriting sample digitization method above, which will not be repeated here. Each module in the above-mentioned handwriting sample digitization device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0192] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store sample data files and encrypted sample files. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a handwriting sample digitization method is implemented.
[0193] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the handwriting sample digitization method of the above embodiment are implemented, such as Figure 2 Alternatively, when the processor executes the computer program, the functions of each module / unit of the handwriting sample digitization device in the above embodiment are realized, for example Fig.10 The functions of modules 101 to 106 are shown in Figure 1. To avoid repetition, they will not be described here.
[0194] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the handwriting sample digitization method in the above method embodiment is implemented, or when the computer program is executed by a processor, the functions of each module / unit in the handwriting sample digitization device in the above device embodiment are implemented. To avoid repetition, it will not be described here.
[0195] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0196] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0197] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for digitizing a handwriting sample, characterized in that: The handwriting sample digitization method comprises: Obtaining a handwriting sample from a handwriting sample data set, wherein the handwriting sample includes a sample image and annotation information of the sample image; Generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture; Combining the image pixel matrix and the annotation information according to a preset combination method to obtain element information corresponding to the handwriting sample; Serializing the element information to obtain a binary sequence corresponding to the element information; Writing the binary sequence into a preset sample data file; Saving the sample data file into a preset sample database; The annotation information includes at least one annotation attribute, and the serialization process of the element information to obtain a binary sequence corresponding to the element information includes: Extracting the pixel values in the picture pixel matrix in a preset order to obtain a pixel value sequence; Parsing the annotation information according to a preset annotation format in the annotation information to obtain each annotation attribute in the annotation information; Serialize each of the annotation attributes respectively to obtain an attribute serialization result of each of the annotation attributes; According to a preset connection method, the pixel value sequence and the attribute serialization result of each of the annotation attributes are connected to form the serialization result of the element information, and the serialization result of the element information is converted into a binary sequence.
2. The handwriting sample digitization method according to claim 1, characterized in that: The annotation attributes include the image name of the sample image, the image size of the sample image, the text content in the sample image, and the relative position information of the text content in the sample image. The attribute serialization result of the annotation attributes includes the attribute serialization result of the image name, the attribute serialization result of the image size, the attribute serialization result of the text content, and the attribute serialization result of the relative position information. The attribute serialization result of each annotation attribute obtained by serializing each annotation attribute includes: Select an unused random number from a preset random number pool as the attribute serialization result of the picture name, and save the picture name and the unused random number in a preset mapping table in correspondence; Parsing the image size according to a preset size format of the image size to obtain size data, and using the obtained size data as a result of attribute serialization of the image size; According to a preset character encoding dictionary, obtain the encoding corresponding to each character in the text content, and use the encoding as the attribute serialization result of the text content; The relative position information is parsed according to a preset position representation method in the relative position information, and the obtained position data is used as the attribute serialization result of the relative position information.
3. The handwriting sample digitization method according to any one of claims 1 to 2, characterized in that: The serializing the element information to obtain a binary sequence corresponding to the element information further comprises: Calculate the hash value of the string corresponding to the element information; Performing a modulo operation between the hash value and the number of preset serialization servers, and using the obtained operation result as the target serial number; Determine the target serialization server corresponding to the target serial number according to the preset correspondence between the serial number and the serialization server; Sending the element information to the target serialization server for serialization processing; Receive a binary sequence corresponding to the element information returned by the target serialization server.
4. The handwriting sample digitization method according to claim 2, characterized in that: The step of saving the sample data file into a preset sample database includes: Encrypting the sample data file according to a preset encryption method to obtain an encrypted sample file; The encrypted sample file is saved in a preset sample database.
5. The handwriting sample digitization method according to claim 4, characterized in that: After the encrypted sample file is saved in a preset sample database, the handwriting sample digitization method further includes: If a request for obtaining the handwriting sample from the user is received, determining the user's access authority according to the user identity information included in the access request; If the acquisition authority is to allow acquisition, the encrypted sample file is acquired from the sample database, and the encrypted sample file is decrypted according to a preset decryption method to obtain a decrypted file; Reading a binary sequence corresponding to the element information from the decryption file; The binary sequence is deserialized to obtain a picture pixel matrix of the sample picture and labeling information of the sample picture.
6. The handwriting sample digitization method according to claim 5, characterized in that: Deserializing the binary sequence to obtain the picture pixel matrix of the sample picture and the labeling information of the sample picture includes: According to the preset connection mode, the pixel value sequence and the binary data segment corresponding to each of the annotation attributes are parsed from the binary sequence; According to the preset mapping table, the preset size format, the preset character encoding dictionary and the preset position identification method, the binary data segment corresponding to each of the annotation attributes is parsed to obtain the picture name, the picture size, the text content and the relative position information respectively; According to the preset annotation format, the picture name, the picture size, the text content and the relative position information are combined into annotation information of the sample picture; The picture pixel matrix of the sample picture is restored according to the pixel value sequence and the picture size.
7. A handwriting sample digitizing device, characterized in that: The handwriting sample digitizing device comprises: A sample acquisition module, used to acquire a handwriting sample in a handwriting sample data set, wherein the handwriting sample includes a sample image and annotation information of the sample image; A matrix generation module, used to generate a picture pixel matrix corresponding to the sample picture according to the pixel value of each pixel point in the sample picture; An information combination module, used to combine the image pixel matrix and the annotation information according to a preset combination method to obtain element information corresponding to the handwriting sample; A serialization module, used to perform serialization processing on the element information to obtain a binary sequence corresponding to the element information; A data writing module, used for writing the binary sequence into a preset sample data file; A file saving module, used to save the sample data file into a preset sample database; The annotation information includes at least one annotation attribute; the serialization module includes: The pixel value extraction submodule is used to extract the pixel values in the image pixel matrix according to a preset order to obtain a pixel value sequence; The annotation parsing submodule is used to parse the annotation information according to the annotation format preset in the annotation information to obtain each annotation attribute in the annotation information; The attribute serialization submodule is used to serialize each annotation attribute separately to obtain the attribute serialization result of each annotation attribute; The binary conversion submodule is used to connect the pixel value sequence and the attribute serialization result of each annotation attribute into the serialization result of the element information according to a preset connection method, and convert the serialization result of the element information into a binary sequence.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the handwriting sample digitization method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the handwriting sample digitization method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Encryption / decryption method and system based on image transmission
CN102625025A
File conversion method and device and file transmission system
CN106776677A
Hash partitioning optimization method and device
CN107633001A
Information control method, server and computer readable medium
CN108332423A
Method, system and equipment for recognizing handwritten Chinese characters
CN108364037A
