Vector character recognition method and system based on bag-of-words model feature point retrieval
By using a feature point retrieval method based on the bag-of-words model, characters in vector graphics files can be directly identified. This solves the problems of small recognition range, slow speed, and inability to distinguish fonts in existing technologies, achieving high accuracy and fast vector character recognition, and supporting multi-font recognition.
Patent Information
- Application Number
- CN202111466725.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-03
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2041-12-03
AI Technical Summary
Existing OCR methods have difficulty directly recognizing characters in vector graphics files, and are insufficient in terms of Chinese character coverage, recognition accuracy, and recognition speed, and cannot distinguish fonts.
A feature point retrieval method based on the bag-of-words model is adopted. By reading the character outline information of the vector image file, parsing it into control point coordinates, drawing grayscale images of control points, extracting ORB feature vectors, and searching for the character ID with the highest similarity in the visual dictionary, the recognition is performed by combining font and Unicode encoding.
It enables direct character recognition of vector graphics files, covering 6763 Chinese characters in the GB2312 character set with 100% accuracy. The recognition speed is fast, with a single character recognition time of 1.5ms and a single page of 700 characters in just 1 second. It can also determine the font type.
Smart Images

Figure CN114328801B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of vector graph recognition, and in particular relates to a vector character recognition method and system based on bag-of-words model feature point retrieval. BACKGROUND
[0002] OCR (Optical Character Recognition) refers to the process by which an electronic device (such as a scanner or digital camera) examines printed characters on paper, determines their shape by detecting patterns of light and dark, and then translates the shape into computer text using character recognition methods; that is, for printed characters, an optical method is used to convert the characters in a paper document into a black-and-white bitmap image file, and the characters in the image are converted into text format by recognition software for further editing and processing by word processing software. How to debug or use auxiliary information to improve recognition accuracy is the most important issue of OCR, and the term ICR (Intelligent Character Recognition) is also derived from this. The main indicators for measuring the performance of an OCR system are: rejection rate, misrecognition rate, recognition speed, user interface friendliness, product stability, ease of use, and feasibility. Among the current open-source OCR methods, the best comprehensive performance is PP-OCRv2 of Baidu Paddle.
[0003] Currently, the main character recognition method for Chinese character recognition using OCR methods is the bitmap file (such as bmp, jpg, png, etc.), and for vector graph files (such as svg, ps) that store characters in vector path mode, OCR methods need to be rendered into bitmaps. At the same time, the existing OCR methods are difficult to have all of the following characteristics: wide coverage of Chinese characters, high accuracy of character recognition, and fast recognition speed, and have many shortcomings: first, the range of character recognition is small and the accuracy is not high, the accuracy of character recognition of traditional OCR methods is about 95%; the accuracy of deep learning OCR methods such as PP-OCR is about 99%, the range of character recognition is about 6000 characters including English, numbers, and symbols, and some national standard characters cannot be recognized; second, the speed of character recognition is slow, the fastest PP-OCRv2 in the case of not opening the cpu instruction set acceleration, the single word recognition speed is about 12ms, and after opening, it can be accelerated to about 8ms, calculated by 700 words per page, it still needs 5-6 seconds per page; third, it cannot distinguish fonts, all current Chinese OCR methods do not have the ability to recognize fonts, and cannot be used for tasks such as invisible watermark embedding that need to operate according to the font type. SUMMARY
[0004] The purpose of the present invention is to provide a vector character recognition method and system based on feature point retrieval of the bag-of-words model, which can greatly improve the recognition accuracy and speed of vector characters.
[0005] To achieve the above purpose, the first technical solution adopted by the present invention is: a vector character recognition method based on feature point retrieval of the bag-of-words model, including the following steps: S100. For any character vector graph in the to-be-retrieved vector graph file, read the vector graph data to obtain character contour information; S200. Parse the character contour information into control point coordinates; S300. Draw the control point coordinates into a control point grayscale image; S400. Extract the ORB feature vector according to the control point grayscale image; S500. Use the ORB feature vector as input, and find the character ID with the highest similarity from the visual dictionary through the bag-of-words tree index. The visual dictionary and the bag-of-words tree index are constructed in advance according to the ORB feature vectors of existing characters through the bag-of-words model algorithm; S600. Obtain the font and unicode encoding corresponding to the vector character through the character ID mapping relationship.
[0006] To achieve the above purpose, the second technical solution adopted by the present invention is: a vector character recognition system based on feature point retrieval of the bag-of-words model, including a control point coordinate calculation module for reading the character vector graph data to obtain character contour information and parsing it into control point coordinates; a mapping module for drawing all control points of the character into a control point grayscale image according to the control point coordinates; a feature extraction module for extracting the ORB feature vector according to the control point grayscale image; a retrieval module for finding the character ID with the highest similarity from the visual dictionary through the bag-of-words tree index based on the input ORB feature vector and outputting it; a query module for obtaining the corresponding font and unicode encoding according to the mapping relationship of the character ID; wherein, the visual dictionary and the bag-of-words tree index in the retrieval module are constructed in advance according to the ORB feature vectors of existing characters through the bag-of-words model algorithm.
[0007] Compared with the prior art, the present invention has the following technical effects: Through the above solution, character recognition can be directly performed on vector graph files without format conversion, and at the same time, it has the following multiple advantages: First, the character recognition range is large and the accuracy is high. The character recognition range includes 6,763 Chinese characters in the GB2312 character set, and can be extended to a larger character set, and the recognition accuracy of characters within the training font range is 100%; Second, the character recognition speed is fast. The single-word recognition speed is about 1.5 ms. Calculated at 700 words per page, it only takes 1 second per page; Third, the font can be judged while performing character recognition. Except for characters with extremely few feature points (for example: 丶), the font type can be accurately judged. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 is a schematic flowchart of the present invention;
[0009] Figure 2 is the control point gray scale diagram of the Fanti Song "ah" character;
[0010] Figure 3 is a principle block diagram of the present application. DETAILED DESCRIPTION
[0011] The present application will be described in further detail below. Figures 1 to 3 The present application will be described in further detail below.
[0012] Referring to Figure 1 The present application discloses a kind of vector character recognition method based on bag-of-words model feature point retrieval, comprising the following steps: S100, to any character vector graph in the vector graph file to be retrieved, read the vector graph data to obtain character contour information, as an example in.svg format, the contour information of each character is a path label d attribute, example is as follows: <pathd="M 0.9375 -10.28125 L 1.640625 -9.796875 …… " / >;S200, character contour information is parsed into control point coordinates;S300, control point coordinates are drawn into control point gray scale diagram, control point gray scale diagram is as shown in Figure Figure 2 Different control point gray scale diagrams correspond to each character, Figure 2 The control point gray scale diagram of the Fanti Song "ah" character in it;S400, according to control point gray scale diagram, extract ORB feature vector, ORB is the abbreviation of Oriented Fast and Rotated Brief, can be used to create feature vector quickly to key point in image, these feature vectors can be used to identify object in image;S500, ORB feature vector is regarded as input, find the highest similarity character ID from visual dictionary through bag-of-words tree index, while also can output similarity score, completely consistent score is 1;Visual dictionary and bag-of-words tree index are constructed according to existing character ORB feature vector by bag-of-words model algorithm in advance;S600, through character ID mapping relationship, obtain the font and unicode code corresponding to the vector character, so that all characters in vector graph file are identified by traversing all characters.
[0013] Bag of Words (BoW): The bag of words model was initially used in text classification to represent documents as feature vectors. Its basic idea is to assume that for a text, ignoring its word order, grammar, and syntax, it is simply regarded as a collection of words, and each word in the text is independent. If a document contains more words such as pigs, horses, cows, sheep, valleys, land, and tractors, and fewer words such as banks, buildings, cars, and parks, we tend to judge it as a document depicting the countryside rather than a description of a town. The bag of words model is simple and efficient in processing feature vector search, so it has been introduced into the field of image retrieval and can be combined with various computer vision feature vectors to complete the task of searching for similar images by pictures. Since the bag of words model can conveniently and quickly add new pictures for training during use, it is especially suitable for loop detection tasks. The feature point retrieval method based on the bag of words model is widely used in loop detection in visual SLAM (where a robot uses a camera to observe the surrounding environment for simultaneous localization and mapping) (which means that during the map construction process, the robot detects whether a trajectory closed loop has occurred through sensor information such as vision, that is, judges whether it has entered the same historical location). Therefore, in this invention, after extracting ORB feature vectors for different characters of different fonts and saving them, it is possible to quickly select the ORB vector feature with the highest similarity to the character to be recognized from all the saved ORB vector features through the bag of words tree index and visual dictionary.
[0014] Through the above solution, character recognition can be directly performed on vector graph files without converting the format, and it also has the following multiple advantages: First, the character recognition range is large and the accuracy is high. The character recognition range includes 6,763 Chinese characters in the GB2312 character set and can be extended to a larger character set, and the recognition accuracy rate for characters within the training font range is 100%; Second, the character recognition speed is fast. The single-word recognition speed is about 1.5 ms. Calculated at 700 words per page, it only takes 1 second per page; Third, the font can be judged while performing character recognition. Except for characters with extremely few feature points (for example: 丶), the font type can be accurately judged.
[0015] Further, in the step S500, the bag-of-words tree index and the visual dictionary are created by the following steps: S510, selecting common fonts to be recognized, and obtaining.ttf or.ttc files of the fonts; S520, setting a range of characters to be recognized, and sequentially numbering each character of each font to form a character ID, so as to establish a one-to-one mapping relationship between the character ID and each character of each font; S530, sequentially traversing each character to perform step S540, and performing step S550 after obtaining the ORB feature vector of all characters; S540, searching for the contour information of the character in the.ttf or.ttc file through the unicode code of the character, and obtaining the ORB feature vector of the character according to steps S200-S400; S550, collecting the ORB feature vectors of all characters, and performing bag-of-words clustering through a bag-of-words model algorithm to create the visual dictionary and the bag-of-words tree index, wherein the bag-of-words model algorithm is DBow2 or DBow3 or FBow. The bag-of-words tree index and the visual dictionary only need to be created once, and do not need to be created again in subsequent character vector graph recognition. Only when it is intended to expand to a larger character set, and new fonts or characters are added, the new bag-of-words tree index and the visual dictionary need to be re-created according to steps S510-S550.
[0016] Further, in the step S300, the following steps are included: S310, normalizing the control point coordinates to a certain size of square coordinate region, which is equivalent to a normalization operation. In the present application, the size of the square region is 128*128px; S320, drawing the control points into a control point grayscale image with a white background and black points. In the control point grayscale image, there are only white background and black points, which facilitates the extraction of the ORB feature in the subsequent step.
[0017] Further, in the step S520, the following steps are included: S521, calculating the total number N of characters contained in the range of characters to be recognized, such as the GB2312 character set, wherein there are 6,763 Chinese characters, and thus N is equal to 6,763; S522, sequentially numbering the N characters of the first font as 1-N; S553, sequentially numbering the N characters of the second font as (N+1)-2N; S554, sequentially numbering the N characters of the M fonts as 1-(M*N), wherein the number is the character ID. For example, the 6,763 characters of Songti are sequentially numbered as 1-6,763, the 6,763 characters of Kaishu are sequentially numbered as 6,764-13,526, and so on. Thus, for the same character, the character IDs corresponding to different fonts are different, and through subsequent processing, only the character ID needs to be searched to obtain accurate font and unicode encoding information.
[0018] Further, the step S550 further comprises a step S560 of saving the visual dictionary and the bag-of-words tree index as a database file, and in the step S500, the ORB feature vector is input after being read and parsed from the database file into the visual dictionary and the bag-of-words tree index. After the step S560 is set, the database file can be conveniently migrated and modified, and the visual dictionary and the bag-of-words tree index obtained in the steps S510-S550 can be used on multiple devices, and only the database file needs to be migrated.
[0019] Referring to Figure 3 The application further discloses a vector character recognition system based on bag-of-words model feature point retrieval, which comprises a control point coordinate calculation module, a drawing module, a feature extraction module and a retrieval module.
[0020] Specifically, the visual dictionary and the bag-of-words tree index are constructed according to the steps S510-S560; the retrieval module reads and parses the visual dictionary and the bag-of-words tree index from the database file and saves them; and the mapping relationship in the query module is the numbering rule in the step S520.
[0021] The application further discloses a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the vector character recognition method based on bag-of-words model feature point retrieval. Meanwhile, the application further discloses an electronic device, which comprises a memory, a processor and a computer program stored in the memory, and the processor executes the computer program to realize the vector character recognition method based on bag-of-words model feature point retrieval.
Claims
1. A vector character recognition method based on bag-of-words model feature point retrieval, characterized in that: The method comprises the following steps: S100, reading character outline information of any character vector diagram in a to-be-searched vector diagram file; S200, parsing the character outline information into control point coordinates; S300, drawing the control point coordinates into a control point grayscale diagram, comprising: S310, normalizing the control point coordinates to a square coordinate region; S320, drawing the control point into a control point grayscale diagram with a white background and black points; S400, extracting an ORB feature vector according to the control point grayscale diagram; S500, searching for a character ID with the highest similarity from a visual dictionary through a bag-of-words tree index by taking the ORB feature vector as input, wherein the visual dictionary and the bag-of-words tree index are constructed in advance according to ORB feature vectors of existing characters through a bag-of-words model algorithm, comprising: S510, selecting common fonts to be recognized, and obtaining.ttf or.ttc files of the fonts; S520, setting a character recognition range, and sequentially numbering each character of each font to form a character ID; S530, sequentially traversing each character to obtain the ORB feature vector of each character, and then performing step S550; S540, searching for the specified character in the.ttf or.ttc file through the unicode code of the character to obtain the outline information of the character, and obtaining the ORB feature vector of the character according to steps S200-S400; S550, collecting the ORB feature vectors of all characters, and performing bag-of-words clustering through a bag-of-words model algorithm to create a visual dictionary and a bag-of-words tree index; S600, obtaining the font and the unicode code corresponding to the vector character through the character ID mapping relationship.
2. The vector character recognition method based on bag-of-words model feature point retrieval of claim 1, wherein: In step S520, the following steps are included: S521, calculating the total number N of characters contained in the character recognition range; S522, sequentially numbering the N characters of the first font as 1-N; S553, sequentially numbering the N characters of the second font as (N+1)-2N; S554, sequentially numbering the N characters of the M fonts as 1-(M*N), wherein the number is the character ID.
3. The vector character recognition method based on bag-of-words model feature point retrieval of claim 1, wherein: In step S310, the square region size is 128*128px; in step S550, the bag-of-words model algorithm is DBow2 or DBow3 or FBow.
4. The vector character recognition method based on bag-of-words model feature point retrieval of claim 1, wherein: After step S550, step S560 is further included: saving the visual dictionary and the bag-of-words tree index as a database file; in step S500, the ORB feature vector is input after being read from the database file and parsed into the visual dictionary and the bag-of-words tree index.
5. A vector character recognition system based on bag-of-words model feature point retrieval, characterized in that: The method comprises a control point coordinate calculation module for reading character vector diagram data to obtain character outline information and parsing the character outline information into control point coordinates; a drawing module for drawing all control points of the character into a control point grayscale diagram according to the control point coordinates, comprising: normalizing the control point coordinates to a square coordinate region, and drawing the control point into a control point grayscale diagram with a white background and black points; a feature extraction module for extracting an ORB feature vector according to the control point grayscale diagram; The retrieval module finds the character ID with the highest similarity from the visual dictionary through bag-of-words tree index according to the input ORB feature vector and outputs the character ID; The query module obtains the corresponding font and unicode code of the character ID according to the mapping relationship of the character ID; The visual dictionary and the bag-of-words tree index in the retrieval module are constructed in advance according to the ORB feature vector of the existing character through the bag-of-words model algorithm, and include: S510, selecting common fonts that need to be recognized, and obtaining.ttf or.ttc files of the fonts; S520, setting the range of recognized characters, and sequentially numbering each character of each font to form a character ID; S530, sequentially traversing each character to execute step S540, and executing step S550 after obtaining the ORB feature vector of all characters; S540, finding the contour information of the character in the.ttf or.ttc file through the unicode code of the character, and obtaining the ORB feature vector of the character according to steps S200-S400; S550, collecting the ORB feature vectors of all characters, and performing bag-of-words clustering through the bag-of-words model algorithm to create a visual dictionary and a bag-of-words tree index.
6. A computer-readable storage medium, characterized in that: The computer program is stored on the computer program, and the computer program is executed by the processor to realize the vector character recognition method based on the bag-of-words model feature point retrieval according to any one of claims 1-4.
7. An electronic device, comprising: The computer program is stored on the computer program, and the computer program is executed by the processor to realize the vector character recognition method based on the bag-of-words model feature point retrieval according to any one of claims 1-4.
Citation Information
Patent Citations
Font recognition method, device and storage medium
CN112784932A