Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other examples obtained based on the examples in the present invention are within the scope of the present invention.
The traditional font recognition algorithm is mainly a feature extraction method, shallow features of a font picture to be recognized are extracted through traditional algorithms such as SIFT, wavelet multi-layer decomposition and the like, then the features are combined according to a certain rule, similarity matching calculation is carried out on the features and a feature library generated by a font file (TTF for short), and finally a result with the largest similarity value is selected as the name of the font to be recognized. However, due to the fact that the conventional font identification scheme needs to perform necessary image preprocessing (noise removal, blur removal, tilt correction and the like) on the font picture to be identified, part of font features of the font picture to be identified can be indirectly lost, so that the identification precision is not high, the name of the font currently liked by the user cannot be quickly and accurately identified, and further the user experience is poor. In order to solve the technical problem, the invention provides a font identification method, a font identification device, font identification equipment and a computer readable storage medium.
It should be noted that the font identification method, apparatus, device and computer readable storage medium provided by the present invention can be applied in any type of font identification scenario.
Fig. 1 is a diagram of a network architecture on which the present invention is based, and as shown in fig. 1, the network architecture on which the present invention is based at least includes a font recognition apparatus 1 and a shooting module 2. The font identification apparatus 1 may be specifically implemented by software and/or hardware, and when implemented by software, it may be written in C language, Java, or the like. The shooting module 2 may be a camera or a separate camera or video camera provided in the user terminal. The font recognition device 1 may be disposed in a user terminal, or may be an independent device, and accordingly, the shooting module 2 may be disposed in the user terminal, or may be an independent camera or video camera, etc., which is not limited herein. It should be noted that the font recognition device 1 may communicate with the photographing module 2 in a wired or wireless manner to realize data interaction, specifically, when both the font recognition device 1 and the photographing module 2 are disposed in a user terminal, both may communicate in a wired manner, and when both are not disposed in the same terminal, may communicate in a wireless manner.
Fig. 2 is a schematic flow chart of a font identification method according to an embodiment of the present invention, where on the basis of the above embodiment, the method includes:
step 101, receiving a font image shot by a shooting module.
The execution subject of the embodiment is a font recognition device, and the font recognition device can communicate with the shooting module in a wired or wireless manner to realize data interaction. Specifically, when finding the favorite font, the user can shoot the font through the shooting module, obtain the font image of the font, and send the font image to the font recognition device in a wired or wireless mode. Accordingly, the font recognition apparatus can accept the font image transmitted by the photographing module.
As an implementable manner, the font image may also be a screenshot of a font of the centering device when the user browses a certain interface through the user terminal, or may also be a font image obtained in any other form, which is not limited herein.
And 102, preprocessing the font image.
In the present embodiment, in order to improve the accuracy of font recognition, the font recognition apparatus may perform preprocessing on the font image after receiving the font image, and obtain a processed font image.
Step 103, adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In this embodiment, in order to recognize the font, a font recognition model may be preset, the font image may be preprocessed to obtain a processed font image, and then the processed font image may be added to the font recognition model to recognize the font of the user mind and obtain the name of the font. Accordingly, after the name of the font is obtained, the name of the font can be displayed on a display screen of the user terminal, and then the user can download and use the font according to the name of the font.
It is to be understood that after obtaining the preprocessed font image, on one hand, the font may be recognized by using the preset font recognition model as in the foregoing embodiment, and in addition, the font may also be recognized by using any other recognition method, which is not limited herein.
In the font identification method provided by the embodiment, the font image shot by the shooting module is received; preprocessing the font file; and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image. Therefore, the name of the font liked by the user can be quickly acquired, so that the user can download and use the font according to the font name, and the user experience is improved.
Further, on the basis of any of the above embodiments, the method further includes:
receiving a font image shot by a shooting module;
preprocessing the font image;
training a preset model to be trained through preset font data to be trained to obtain the preset font recognition model;
and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In this embodiment, in order to recognize the font, a font recognition model may be preset, the font image is preprocessed, and after the processed font image is obtained, the processed font image may be added to the font recognition model, so as to recognize the font of the user psychoscope and obtain the name of the font. Specifically, in order to obtain the font identification model, a model to be processed needs to be established, the convolutional neural network mainly comprises a data layer, a convolutional layer, an activation layer, a pooling layer, a full-link layer, a classification layer and the like, different layers are combined and connected according to the identification purpose and the required precision, and finally a model to be processed with a proper width is designed. Specifically, a data layer is established, the sizes of all input pictures are converted into M, then the inclusion blocks are designed in sequence, each inclusion block comprises a convolution layer, an activation layer, a normalization layer, a pooling layer and the like, finally a full-connection layer is designed, N results are output, and the results are arranged in a descending order. And adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
According to the font identification method provided by the embodiment, the preset model to be trained is trained through the preset font data to be trained to obtain the preset font identification model, so that a basis is provided for subsequent font identification, and further the user experience can be improved.
Fig. 3 is a schematic flow chart of a font identification method according to a second embodiment of the present invention, where on the basis of any of the above embodiments, the method includes:
step 201, receiving a font image shot by a shooting module;
step 202, preprocessing the font image;
step 203, acquiring preset data to be processed, wherein the data to be processed is a black and white font image;
step 204, rendering the data to be processed into color image data randomly;
step 205, randomly dividing the color image data into a test set and a training set;
step 206, labeling the color image data in the test set and the training set respectively to obtain the font data to be trained;
step 207, training a preset model to be trained through preset font data to be trained to obtain the preset font recognition model;
and 208, adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In this embodiment, to implement training of the model to be trained, the font data to be trained should be acquired first. Specifically, preset data to be processed is obtained, and the data to be processed is a black-and-white font image, for example, the data to be processed may be a black-and-white image of a single character single image generated from an n-pattern ttf file of a squareness family word stock. Further, in order to improve the recognition accuracy of the model, data amplification may be performed on the data to be processed. Black and white images can be randomly rendered as color RGB images. Further, the color image data is randomly divided into a training set and a testing set, and the data in the training set and the data in the testing set are labeled to obtain the data to be trained. Therefore, the model to be trained can be trained according to the data to be trained in the training set, and the font recognition model can be finally obtained by testing the data in the data to be trained in the testing set. Therefore, the font image shot by the shooting module at present can be identified according to the font identification model, and the name of the font is obtained. Accordingly, after the name of the font is obtained, the name of the font can be displayed on a display screen of the user terminal, and then the user can download and use the font according to the name of the font.
In the font identification method provided by this embodiment, preset data to be processed is acquired, where the data to be processed is a black-and-white font image; randomly rendering the data to be processed into color image data; randomly dividing the color image data into a test set and a training set; and respectively labeling the color image data in the test set and the training set to obtain the font data to be trained, so that the identification precision of the model can be improved, and the user experience is further improved.
Further, on the basis of any of the above embodiments, the method comprises:
receiving a font image shot by a shooting module;
preprocessing the font image;
acquiring preset data to be processed, wherein the data to be processed is a black and white font image;
randomly rendering the data to be processed into color image data;
randomly dividing the color image data into a test set and a training set;
adding random noise and random fuzziness in the test set and the training set;
marking the font name of the color image data aiming at each color image data in the test set and the training set;
training a preset model to be trained through preset font data to be trained to obtain the preset font recognition model;
and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In this embodiment, after the color image data is randomly divided into the training set and the test set, the data in the training set and the test set need to be labeled to obtain the data to be trained. Specifically, interference processing such as random blurring and random noise may be added to the training set and the data to be trained in the test set, and in addition, in order to enable the font recognition model to accurately recognize the font, the font name of the data in the test set and the training set needs to be labeled. Specifically, for each color image data in the test set and the training set, a font name of the color image data is labeled.
In the font identification method provided by this embodiment, random noise and random fuzziness are added to the test set and the training set; and marking the font name of the color image data aiming at each color image data in the test set and the training set, so that the font identification model can accurately realize the identification of the font, and the user experience is improved.
Further, on the basis of any of the above embodiments, the method comprises:
receiving a font image shot by a shooting module;
preprocessing the font image;
acquiring preset data to be processed, wherein the data to be processed is a black and white font image;
randomly rendering the data to be processed into color image data;
randomly dividing the color image data into a test set and a training set;
labeling the color image data in the test set and the training set respectively to obtain font data to be trained;
training the model to be trained through the test set and the training set, and adjusting the hyper-parameters of the model to be trained until the model to be trained is converged to obtain the font recognition model;
and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In this embodiment, after labeling the data in the training set and the test set, the model to be trained may be trained through the training set and the test set. Specifically, the model to be trained can be trained according to the data to be trained in the training set, the data in the data to be trained in the testing set is tested, and the hyper-parameters of the model to be trained are continuously adjusted according to the training result, wherein the hyper-parameters include but are not limited to a learning rate, a learning strategy, a forgetting rate and a maximum iteration number until the model to be trained converges, and finally the font recognition model is obtained.
According to the font identification method provided by the embodiment, the model to be trained is trained through the test set and the training set, the hyper-parameters of the model to be trained are adjusted until the model to be trained is converged, and the font identification model is obtained, so that the identification precision of the font identification model can be improved, and the user experience is further improved.
Further, on the basis of any of the above embodiments, the method comprises:
receiving a font image shot by a shooting module;
calculating a mean image of the font recognition model;
subtracting the average value image from the font image to obtain the preprocessed font image;
and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image.
In the embodiment, when receiving the font image to be recognized sent by the shooting module, in order to improve the efficiency and accuracy of font recognition, the font image needs to be preprocessed first. Specifically, a mean image of the font identification model may be determined first, and the mean image is subtracted from the captured font image to obtain a characteristic portion of the font image, and the pre-processed font image is identified by the preset font identification model to obtain a name of the font. Accordingly, after the name of the font is obtained, the name of the font can be displayed on a display screen of the user terminal, and then the user can download and use the font according to the name of the font.
In the font identification method provided by this embodiment, the mean image of the font identification model is calculated; and subtracting the mean value image from the font image to obtain the preprocessed font image, so that the efficiency and the precision of font identification can be improved, and the user experience is further improved.
Fig. 4 is a schematic structural diagram of a font identification apparatus provided in a third embodiment of the present invention, and as shown in fig. 4, the font identification apparatus includes:
a font image receiving module 31 for receiving the font image photographed by the photographing module;
a preprocessing module 32, configured to preprocess the font file;
the recognition module 33 is configured to add the preprocessed font image to a preset font recognition model, and obtain a font name corresponding to the font image.
In this embodiment, the font recognition device may communicate with the shooting module in a wired or wireless manner, so as to implement data interaction. Specifically, when finding the favorite font, the user can shoot the font through the shooting module, obtain the font image of the font, and send the font image to the font recognition device in a wired or wireless mode. Accordingly, the font recognition apparatus can accept the font image transmitted by the photographing module.
As an implementable manner, the font image may also be a screenshot of a font of the centering device when the user browses a certain interface through the user terminal, or may also be a font image obtained in any other form, which is not limited herein.
In order to improve the accuracy of font identification, the font identification device may perform preprocessing on the font image after receiving the font image, and obtain a processed font image.
In order to realize the identification of the font, a font identification model can be preset, the font image is preprocessed, and after the processed font image is obtained, the processed font image can be added into the font identification model, so that the identification of the font of the user psychoscope is realized, and the name of the font is obtained. Accordingly, after the name of the font is obtained, the name of the font can be displayed on a display screen of the user terminal, and then the user can download and use the font according to the name of the font.
The font recognition device provided by the embodiment receives the font image shot by the shooting module; preprocessing the font file; and adding the preprocessed font image into a preset font identification model to obtain a font name corresponding to the font image. Therefore, the name of the font liked by the user can be quickly acquired, so that the user can download and use the font according to the font name, and the user experience is improved.
Further, on the basis of any one of the above embodiments, the apparatus further includes:
and the training module is used for training a preset model to be trained through preset font data to be trained to obtain the preset font identification model.
The font recognition device that this embodiment provided trains the model of waiting to train through the font data of waiting to train that predetermine, obtains predetermined font recognition model to for subsequent font discernment provides the basis, and then can improve user experience.
Further, on the basis of any one of the above embodiments, the apparatus further includes:
the device comprises a to-be-processed data acquisition module, a processing module and a processing module, wherein the to-be-processed data acquisition module is used for acquiring preset to-be-processed data, and the to-be-processed data is a black and white font image;
the rendering module is used for rendering the data to be processed into color image data at random;
the classification module is used for randomly dividing the color image data into a test set and a training set;
and the marking module is used for marking the color image data in the test set and the color image data in the training set respectively to obtain the font data to be trained.
The font identification device provided by this embodiment acquires preset data to be processed, where the data to be processed is a black-and-white font image; randomly rendering the data to be processed into color image data; randomly dividing the color image data into a test set and a training set; and respectively labeling the color image data in the test set and the training set to obtain the font data to be trained, so that the identification precision of the model can be improved, and the user experience is further improved.
Further, on the basis of any of the above embodiments, the labeling module includes:
an adding unit, configured to add random noise and random ambiguity in the test set and the training set;
and the marking unit is used for marking the font name of the color image data aiming at each color image data in the test set and the training set.
In the font recognition apparatus provided in this embodiment, random noise and random fuzziness are added to the test set and the training set; and marking the font name of the color image data aiming at each color image data in the test set and the training set, so that the font identification model can accurately realize the identification of the font, and the user experience is improved.
Further, on the basis of any of the above embodiments, the training module includes:
and the training unit is used for training the model to be trained through the test set and the training set, adjusting the hyper-parameters of the model to be trained until the model to be trained is converged, and obtaining the font recognition model.
The font recognition device provided by this embodiment trains the model to be trained through the test set and the training set, and adjusts the hyper-parameter of the model to be trained until the model to be trained converges to obtain the font recognition model, thereby improving the recognition accuracy of the font recognition model and further improving the user experience.
Further, on the basis of any of the above embodiments, the preprocessing module includes:
the calculation unit is used for calculating a mean image of the font identification model;
and the processing unit is used for subtracting the average value image from the font image to obtain the preprocessed font image.
The font identification device provided by this embodiment calculates a mean image of the font identification model; and subtracting the mean value image from the font image to obtain the preprocessed font image, so that the efficiency and the precision of font identification can be improved, and the user experience is further improved.
Fig. 5 is a schematic structural diagram of a font identification device according to a fourth embodiment of the present invention, and as shown in fig. 5, the font identification device includes:
a memory 41, a processor 42;
a memory 41; a memory 41 for storing instructions executable by the processor 42;
wherein the processor 42 is configured to execute the font recognition method as described above by the processor 42;
the font recognition device further comprises a communication interface 43.
Yet another embodiment of the present invention provides a computer-readable storage medium having stored therein computer-executable instructions for implementing the font recognition method as described above when executed by a processor.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method embodiment, and is not described herein again.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.