Background
In a system for automatically identifying bills based on templates, the position of the bill to be identified is often directly positioned according to the position of an information area defined in each type of template, and the positioning accuracy of the method for directly positioning the information area of the template is low. This is because each bill has its own features, and because the shooting angle and the completeness of the bill are different, the success rate of directly applying template information to locate the text is not high, which results in failure of subsequent character recognition.
Chinese patent publication No. CN104916034A discloses a bill recognition system and recognition method based on an interventionalisable template, where the location of the text region of interest in the system is the position information of the text directly using the original template, and no additional optimization operation is made for the text location. The method basically fails to locate the bill which has a difference with the shooting size of the template bill or has obvious overprinting effect.
Chinese patent publication No. CN107622255A discloses a method and system for positioning bill field based on position template and semantic template, which simply uses position template information in positioning of interested text, and the method is not suitable for bills with different bill size in image and template bill size due to difference in shooting angle. Meanwhile, the system carries out position correction by using a method of combining position information and bill mark fields for text positioning of the over printing type invoices, but the method requires that a characteristic field is defined for each type of invoices firstly and the relative offset is calculated by detecting the characteristic field of each invoice, and the method has limitation. The first method needs to manually design the characteristic field for each type of bill, which is time-consuming and labor-consuming, and cannot ensure that the characteristic mark can be designed for each type of bill; secondly, when the characteristic field is searched, the characteristic field is possibly failed to find due to recognition error, and then the text positioning is failed; thirdly, the adoption of the method is premised on that all text rows need to be recognized, and the efficiency is very low.
Disclosure of Invention
The invention aims to overcome at least one defect in the prior art, and provides a text region positioning method based on feature point bill alignment and eight-neighborhood connector offset correction. The whole set of positioning algorithm can solve the positioning problem of most bills, and the method has strong universality.
The technical scheme of the invention is as follows: a text region positioning method based on note alignment of characteristic points and eight-neighborhood connector offset correction comprises two parts of note alignment and eight-neighborhood connector offset correction based on characteristic point matching,
the bill alignment part based on feature point matching is the first stage of the whole text region positioning algorithm, firstly, the bill size is standardized, SIFT feature point extraction is carried out on the bill, then, feature matching is carried out on the bill feature points and the template bill feature points, a transformation matrix is obtained, projection transformation is carried out, and bill alignment in the first stage is completed;
the eight-neighborhood connector offset correction is the second stage of the text region positioning algorithm, on the basis that the bills are aligned, one information region is selected as a main operation region, and the positions of other regions of the template are corrected by using the offset error according to the offset error between the character region information on the original bill template and the connector queue, so that the accurate position of each information region is obtained.
Furthermore, the same type of bill alignment is realized by obtaining a transformation matrix through extraction and matching calculation of the feature points, and perspective transformation is performed according to the transformation matrix to complete bill alignment.
Further, an eight-neighborhood searching area is generated for a certain information area in the bill template, then binarization and morphological processing are carried out on the searching area, and the communicating bodies in the searching area are queued and stored according to a specified sequence, so that a main communicating body queue is generated.
Furthermore, the sequence of the communication bodies in the search area which are queued and stored according to the designated sequence is middle, right, left, upper, lower, upper right, lower right, upper left and lower left.
Further, the center coordinates of the connected body at the head of the queue are calculated, the offset between the coordinates and the center coordinates of the area in the template is calculated, the positions of the information areas in other templates are corrected according to the offset, the connected bodies are searched in the same eight neighborhoods of the calculated information areas and are queued, if the connected bodies meeting the conditions are positioned in the connected body queue in other positions, the offset is calculated correctly, otherwise, the connected bodies are dequeued, and the same operation is continuously performed on the next connected body in the main queue.
The note alignment is the first stage of the whole set of positioning algorithm, and the specific steps of the note alignment stage are as follows:
(1) firstly, the size standardization of the image of the bill to be processed is carried out, namely, the image of the bill to be processed is scaled to the specified size of the bill.
(2) Graying the bill image to be processed, extracting SIFT feature points, matching the SIFT feature points with the feature points of the corresponding template image, and further solving a transformation matrix H.
(3) And performing projection transformation on the image to be processed according to the transformation matrix H to obtain a transformed bill image, thereby finishing the alignment operation of the image to be processed and the reference image.
Generally speaking, for character positioning of common and non-sleeve printed bills, after bill alignment in the first stage is carried out, accurate text regions can be obtained by directly applying information of information region positions in a template. If the problem of character offset of the set of ticketing data needs to be solved, the second stage of the algorithm, namely the offset correction stage, needs to be carried out continuously, and the specific steps are as follows:
(1) and randomly selecting an information area in the template as a main operation area, and expanding the area to the eight directions of the periphery of the area by the size of the area to generate an eight-neighborhood search area.
(2) And carrying out binarization and corresponding morphological processing on the eight-neighborhood search area, and enqueuing and storing the connected bodies in the nine grids according to a certain rule.
(3) And calculating the center coordinate of the first communication body of the queue, and obtaining the offset K by taking the difference value between the center coordinate of the first communication body of the queue and the center coordinate of the area template information.
(4) And recalculating the specific position information of other information areas according to the offset K to obtain new information area position information, properly amplifying the position area for each new position, detecting whether a connected body meeting the appointed condition of the area exists in the area, if so, indicating that the offset is the real offset, completing the offset correction stage, and otherwise, performing the same offset correction operation on the next connected body in the queue.
Compared with the prior art, the beneficial effects are: the method makes full use of the higher similarity between the bills, and can finish the alignment of the bills by means of the characteristic points between the bills of the same kind. On the basis that the bills are aligned, the text is accurately positioned by using the characteristic that the relative position between the overprint fonts is unchanged and using the offset correction of the eight-neighborhood connected body. The method is suitable for wide bills, does not need to design characteristic marks in advance for auxiliary positioning, and is simple to operate and high in accuracy.
Detailed Description
The drawings are for illustrative purposes only and are not to be construed as limiting the patent; for the purpose of better illustrating the embodiments, certain features of the drawings may be omitted, enlarged or reduced, and do not represent the size of an actual product; it will be understood by those skilled in the art that certain well-known structures in the drawings and descriptions thereof may be omitted. The positional relationships depicted in the drawings are for illustrative purposes only and are not to be construed as limiting the present patent.
As shown in FIG. 1, the scheme is divided into two stages of note alignment and offset correction. The specific steps of the note alignment stage include: (1) reading a bill image to be identified, classifying the bill image and obtaining corresponding bill template information; (2) graying the image to be recognized and standardizing the size of the image to be recognized to be the uniform size of the bill; (3) SIFT feature point extraction is carried out on the image, a feature point set of the image is matched with a feature point set of a template image, and a transformation matrix H is obtained; (4) and carrying out perspective transformation on the graph according to the transformation matrix H to realize the registration of the current bill and the template bill, namely realizing the alignment of the bills.
As shown in fig. 3, the specific steps of the bill offset correction phase include: (1) randomly selecting any information area in the template as a main operation area, and generating search areas with the same size as the information area in eight directions of the area, wherein the main operation area totally comprises nine grids as shown in fig. 2; (2) carrying out binarization and morphological processing on the search area of the nine grids, adhering text lines into a whole to form a communicating body by using expansion operation, and eliminating small-particle small noise by using corrosion operation; (3) and enqueuing and storing the communication bodies in the search area according to a certain sequence, wherein the enqueuing sequence determines the priority of the current communication body according to which of nine grids the center of each communication body falls, the priority of each grid is shown in FIG. 2, 1 is the highest priority, and 9 is the lowest priority. Determining an enqueuing sequence according to the priorities of the communicating bodies during enqueuing, wherein the communicating bodies with high priorities enqueue first; (4) calculating the center coordinate of the first communicating body of the queue, and obtaining an offset K by taking the difference value between the center coordinate and the area template information center coordinate; (5) recalculating the specific position information of other information areas according to the offset K to obtain new information area position information, and appropriately amplifying the position area for each new position, for example, multiplying the height and width of the area position defined by the template by 1.2 times; (6) and detecting whether a connected body meeting the appointed conditions of the area exists in the area, if so, indicating that the offset is the real offset, completing the offset correction stage, otherwise, performing the same offset correction operation on the next connected body in the queue until the offset calculation is successful, ending the offset correction stage, or ending the algorithm until the queue is empty and still cannot find out a proper offset, and returning positioning failure information.
It should be understood that the above-described embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are neither required nor exhaustive of all embodiments. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the claims of the present invention.