A hybrid verification code recognition method and system based on weight strategy

Through a hybrid verification code recognition method based on weight strategy, multiple OCR APIs are used to obtain and analyze recognition characters, which solves the problems of long training, low accuracy and poor concurrency performance in the prior art, and achieves efficient and accurate verification code recognition .

CN114387601BActive Publication Date: 2024-11-05YANGTZE OPTICAL FIBRE & CABLE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210025040.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-10
Publication Date
2024-11-05
Estimated Expiration
2042-01-10

AI Technical Summary

Technical Problem

The existing hybrid verification code recognition method requires model training, which leads to a complex and time-consuming recognition process. The method based on commercial OCR interface has low recognition accuracy and poor concurrency performance, and has limited use times, which is easy to exceed the limit and report errors.

Method used

A hybrid verification code recognition method based on weight strategy is adopted to obtain recognition character groups through multiple OCR APIs, reorder and assign weight values, and determine the most likely correct character combination as recognition results based on weight analysis.

Benefits of technology

Implement verification code recognition in a shorter time, improving the recognition accuracy, reducing the number of uses and concurrency, and improving the recognition efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114387601B_ABST
    Figure CN114387601B_ABST
Patent Text Reader

Abstract

The present invention discloses a hybrid verification code recognition method based on a weight strategy, comprising: obtaining a verification code image, and preprocessing the verification code image to obtain a preprocessed image, respectively inputting the preprocessed image into N optical character recognition application program interfaces (OCR APIs) to obtain a recognition character group consisting of a plurality of recognition characters corresponding to each OCR API, all recognition character groups constitute a recognition character set, and by setting different weight numbers for the characters in each character group, after one-by-one comparison, the characters with the largest weight number are obtained to form the final recognition characters. The present invention can solve the technical problem that the existing hybrid verification code recognition method needs to train the model and the training process is very lengthy, resulting in a complex and time-consuming recognition process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of picture and text recognition, and more specifically, relates to a hybrid verification code recognition method and system based on a weight strategy. Background Art

[0002] The emergence of verification codes is to prevent certain malicious programs from damaging websites, such as batch registration, batch posting, and also to prevent those crawlers from ignoring the rules and crawling resources. The so-called verification code is to generate a picture with a set of random numbers or symbols, and add some interference elements to the picture. When users submit a form, they need to identify and fill in the verification code. Only after the verification code is successfully verified in the background can the form be successfully submitted. This process is not easy for machine programs to simulate, and those sticky characters make it difficult for machine programs to recognize, which to a certain extent protects the website from attacks by malicious programs.

[0003] While verification codes bring security to websites, they also bring certain inconveniences to some people engaged in web crawling. The verification code recognition algorithm is designed to solve this problem.

[0004] There are two traditional verification code recognition methods, namely the hybrid verification code recognition method and the recognition method based on the commercial OCR interface. For the first method, the verification code is subjected to image preprocessing methods such as grayscale, binarization, noise reduction, and segmentation, and then a convolutional neural network model is established through deep learning frameworks such as Tensorflow. The single characters obtained by segmentation are sent to the trained model to recognize the verification code; for the second method, after the obtained verification code image is processed, the application program interface (API) of a professional image and text recognition company is used to quickly identify the verification code.

[0005] However, both of the above-mentioned two existing verification code recognition methods have some defects that cannot be ignored: first, since the first method requires model training, the training process is very lengthy, making the recognition process complicated and time-consuming; second, the second method does not require a training process, and although the research time is short, it does not make targeted optimization based on the verification code, which will lead to low recognition accuracy; third, the second method has a limit on the number of uses at the same time, and has poor concurrency performance. If multiple recognitions exceed the limit, the interface will report an error and become unavailable. Summary of the invention

[0006] In response to the above defects or improvement needs of the prior art, the present invention provides a hybrid verification code recognition method and system based on a weight strategy, which aims to solve the technical problems of the existing hybrid verification code recognition method that the recognition process is complicated and time-consuming due to the need to train the model and the very lengthy training process, and the technical problems of the existing recognition method based on the commercial OCR interface that the recognition accuracy is low due to the lack of targeted optimization according to the verification code, and the technical problems that there is a limit on the number of uses at the same time and the concurrency performance is poor. If multiple recognitions exceed the limit, the interface will report an error and become unavailable.

[0007] To achieve the above object, according to one aspect of the present invention, a method for identifying a hybrid verification code based on a weight strategy is provided, comprising the following steps:

[0008] (1) Obtain a verification code image, and preprocess the verification code image to obtain a preprocessed image.

[0009] (2) Inputting the image preprocessed in step (1) into N optical character recognition application program interfaces (OCR APIs) respectively to obtain a recognition character group consisting of a plurality of recognition characters corresponding to each OCR API, wherein all recognition character groups constitute a recognition character set, where N is a natural number.

[0010] (3) Set counter i=1;

[0011] (4) Determine whether the counter i is greater than the total number N of OCR APIs used in step (2). If so, return to step (1); otherwise, proceed to step (5);

[0012] (5) determining whether the number of recognized characters in the recognized character group corresponding to the i-th OCR API is equal to the total number of characters in the image preprocessed in step (1), if so, proceeding to step (7), otherwise proceeding to step (6);

[0013] (6) Set step i=i+1 and return to step (5);

[0014] (7) The recognition character group corresponding to the i-th OCR API is placed at the beginning of the recognition character set, thereby obtaining a reordered recognition character set {(D11, D12, ..., D1 p’ ), (D21, D22, …, D2 q’ ),…,(D(N-1)1,D(N-1)2,…,D(N-1) t’ ), (DN1, DN2, …, DN r’)}, and then proceed to step (8); wherein p' represents the total number of recognized characters in the first recognized character group in the reordered recognized character set, q' represents the total number of recognized characters in the second recognized character group in the reordered recognized character set, ..., t' represents the total number of recognized characters in the second to last recognized character group in the reordered recognized character set, and r' represents the total number of recognized characters in the last recognized character group in the reordered recognized character set.

[0015] (8) assigning a weight value of 2 to the first recognition character D11, ..., D(N-1)1, DN1 in all the recognition character groups in the recognition character set reordered in step (7), assigning a weight value of 1 to the second recognition character D22, ..., D(N-1)2, DN2 in all the recognition character groups other than the first recognition character group in the recognition character set reordered in step (7), and for each recognition character in the formed first recognition character set {D11, ..., D(N-1)1, DN1, D22, ..., D(N-1)2, DN2} that appears twice or more, adding the weight values ​​corresponding to the recognition characters to obtain the weight sum corresponding to the recognition characters, sorting the obtained multiple weight sums in descending order, and taking the recognition character corresponding to the maximum weight sum as the first character of the recognition result;

[0016] (9) Set counter k=1;

[0017] (10) Determine whether the counter k is greater than p'-1, if so, proceed to step (13), otherwise proceed to step (11);

[0018] (11) multiple recognition character groups (D12, ..., D1 p’-1 ), (D22, D22, …, D2 q’-1 ),…,(D(N-1)2,D(N-1)3,…,D(N-1) t’-1 ), the kth recognized character D1 in all recognized character groups k , ..., D(N-1) k , D.N. k Assign a weight value of 2 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k-1th recognized character D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 Assign a weight value of 1 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k+1th recognized character D2 k+1 , ..., D(N-1) k+1, D.N. k+1 Assign a weight value of 1, and for the second recognition character set {D1 k , ..., D(N-1) k , D.N. k , DN1, D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 , D2 k+1 , ..., D(N-1) k+1 , D.N. k+1}, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the kth middle character of the recognition result;

[0019] (12) Set counter k=k+1 and return to step (10);

[0020] (13) is the last recognized character D1 in all recognized character groups in the recognized character set reordered in step (7) p’ , ..., D(N-1) t’ , D.N. r’ Assign a weight value of 2 to the penultimate recognized character D2 in all recognized character groups except the first recognized character group in the reordered recognized character set in step (7). q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 Assign a weight value of 1 to the third recognition character set {D1 p’ , ..., D(N-1) t’ , D.N. r’ , D2 q’ -1, ..., D(N-1) t’-1 , D.N. r’-1 For each recognized character that appears twice or more in}, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums from large to small, and take the recognized character corresponding to the maximum weight sum as the last character of the recognition result.

[0021] (14) The first character obtained in step (9), the middle character obtained in step (11), and the last character obtained in step (13) are combined into a final recognition result.

[0022] Preferably, the preprocessing of the verification code image in step (1) specifically includes the following sub-steps:

[0023] (1-1) graying the verification code image to obtain a grayscale image;

[0024] (1-2) Binarizing the grayscale image obtained in step (1-1) to obtain a binary matrix;

[0025] (1-3) performing denoising on the binary matrix obtained in step (1-2) to obtain a denoised binary matrix;

[0026] (1-4) sharpening the binary matrix after denoising in step (1-3) to obtain a binary matrix after sharpening;

[0027] (1-5) converting the binary matrix after the sharpening process in step (1-4) into an image as a preprocessed image;

[0028] Preferably, step (1-3) is specifically as follows: first, the binary matrix is ​​traversed in order from top to bottom and from left to right, starting from the first element obtained that is 1, all elements adjacent to the element in eight directions are obtained, and it is determined whether the number of elements that are 1 in all the obtained elements is less than or equal to 2. If so, the value of the element is set to 0, otherwise it remains unchanged, and then the next element is entered, and the above process is repeated until the binary matrix is ​​traversed.

[0029] Preferably, the OCR API interface includes Baidu text recognition interface, CNN open source interface, and Alibaba OCR API interface.

[0030] Preferably, all the recognition character groups in step (2) constitute the recognition character set {(C11, C12, ..., C1 p ), (C21, C22, …, C2 q ),…,(C(N-1)1,C(N-1)2,…,C(N-1) t ), (CN1, CN2, …, CN r )}; wherein p represents the total number of recognized characters in the recognized character group corresponding to the first OCR API, q represents the total number of recognized characters in the recognized character group corresponding to the second OCR API, ..., t represents the total number of recognized characters in the recognized character group corresponding to the N-1th OCR API, and r represents the total number of recognized characters in the recognized character group corresponding to the Nth OCR API.

[0031] According to another aspect of the present invention, a hybrid verification code recognition system based on a weight strategy is provided, comprising:

[0032] The first module is used to obtain a verification code image and preprocess the verification code image to obtain a preprocessed image.

[0033] The second module is used to input the images preprocessed by the first module into N optical character recognition application program interfaces (OCR APIs) respectively to obtain a recognition character group consisting of multiple recognition characters corresponding to each OCR API, and all recognition character groups constitute a recognition character set, where N is a natural number.

[0034] The third module is used to set the counter i=1;

[0035] The fourth module is used to determine whether the counter i is greater than the total number N of OCR APIs used in the second module, if so, return to the first module, otherwise enter the fifth module;

[0036] The fifth module is used to determine whether the number of recognized characters in the recognized character group corresponding to the i-th OCR API is equal to the total number of characters in the picture preprocessed by the first module, if yes, enter the seventh module, otherwise enter the sixth module;

[0037] The sixth module is used to set step i=i+1 and return to the fifth module;

[0038] The seventh module is used to place the recognition character group corresponding to the i-th OCR API at the beginning of the recognition character set, so as to obtain a reordered recognition character set {(D11, D12, ..., D1 p’ ), (D21, D22, …, D2 q’ ),…,(D(N-1)1,D(N-1)2,…,D(N-1) t’ ), (DN1, DN2, …, DN r’ )}, and then enter the eighth module; wherein p' represents the total number of recognized characters in the first recognized character group in the reordered recognized character set, q' represents the total number of recognized characters in the second recognized character group in the reordered recognized character set, ..., t' represents the total number of recognized characters in the second to last recognized character group in the reordered recognized character set, and r' represents the total number of recognized characters in the last recognized character group in the reordered recognized character set.

[0039] an eighth module, for assigning a weight value of 2 to the first recognition character D11, ..., D(N-1)1, DN1 in all the recognition character groups in the recognition character set reordered by the seventh module, and assigning a weight value of 1 to the second recognition character D22, ..., D(N-1)2, DN2 in all the recognition character groups except the first recognition character group in the recognition character set reordered by the seventh module, and for each recognition character that appears twice or more in the formed first recognition character set {D11, ..., D(N-1)1, DN1, D22, ..., D(N-1)2, DN2}, adding the weight values ​​corresponding to the recognition characters to obtain the weight sum corresponding to the recognition characters, sorting the obtained multiple weight sums in descending order, and taking the recognition character corresponding to the maximum weight sum as the first character of the recognition result;

[0040] The ninth module is used to set the counter k=1;

[0041] The tenth module is used to determine whether the counter k is greater than p'-1, if so, enter the thirteenth module, otherwise enter the eleventh module;

[0042] The eleventh module is used to sort the multiple recognition character groups (D12, ..., D1 p’-1 ), (D22, D22, …, D2 q’-1 ),…,(D(N-1)2,D(N-1)3,…,D(N-1) t’-1 ), the kth recognized character D1 in all recognized character groups k , ..., D(N-1) k , D.N. k Assign a weight value of 2 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k-1th recognized character D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 Assign a weight value of 1 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k+1th recognized character D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 Assign a weight value of 1, and for the second recognition character set {D1 k , ..., D(N-1) k , D.N. k , DN1, D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 , D2 k+1, ..., D(N-1) k+1 , D.N. k+1}, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the kth middle character of the recognition result;

[0043] The twelfth module is used to set the counter k=k+1 and return to the tenth module;

[0044] The thirteenth module is used for the last recognized character D1 in all recognized character groups in the recognized character set reordered by the seventh module. p’ , ..., D(N-1) t’ , D.N. r’ Assign a weight value of 2 to the penultimate recognized character D2 in all recognized character groups except the first recognized character group in the reordered recognized character set of the seventh module. q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 Assign a weight value of 1 to the third recognition character set {D1 p’ , ..., D(N-1) t’ , D.N. r’ , D2 q’ -1, ..., D(N-1) t’-1 , D.N. r’-1 For each recognized character that appears twice or more in}, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums from large to small, and take the recognized character corresponding to the maximum weight sum as the last character of the recognition result.

[0045] The fourteenth module is used to combine the first character obtained by the ninth module, the middle character obtained by the eleventh module, and the last character obtained by the thirteenth module into a final recognition result.

[0046] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:

[0047] (1) Since the present invention adopts step (2), it is not necessary to train and study the neural network model, so the verification code can be recognized in a shorter time;

[0048] (2) The present invention adopts steps (7) to (14), which uses a weight-based hybrid recognition method, can simultaneously use multiple OCR recognition algorithms to obtain results, and then find the most likely correct character based on the weight strategy, thereby improving the recognition accuracy;

[0049] (3) Since the present invention adopts step (2), it uses multiple OCR APIs to obtain recognition characters and form recognition character groups for weight analysis, thereby improving the recognition efficiency of the present invention and reducing the number of uses and concurrency times. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a schematic diagram of a verification code image obtained by the present invention;

[0051] Figure 2 is a schematic diagram of the present invention using multiple OCR APIs to obtain multiple recognized characters;

[0052] Figure 3 It is a schematic diagram of the recognition result finally obtained by the present invention.

[0053] Figure 4 The invention is a flow chart of a hybrid verification code recognition method based on a weight strategy. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0055] Traditional verification schemes mainly focus on image processing tuning or neural network algorithm training set tuning, with long development cycles and low accuracy. Commercial API interfaces are convenient but lack tuning space. The present invention compares multiple algorithm results to identify the most likely data results. Compared with a single recognition algorithm, the recognition accuracy is increased by 63% under the same number of recognitions, effectively improving the recognition accuracy of hybrid verification codes.

[0056] like Figure 4 As shown, the present invention provides a hybrid verification code recognition method based on a weight strategy, comprising the following steps:

[0057] (1) Get the verification code image (such as Figure 1 As shown), and preprocess the verification code image to obtain a preprocessed image;

[0058] Specifically, verification code images can be obtained from web pages, application software, mobile phone screenshots, etc.

[0059] In this step, preprocessing the verification code image includes the following sub-steps:

[0060] (1-1) graying the verification code image to obtain a grayscale image;

[0061] Specifically, this step uses the imread method in the matplotlib.pyplot library in Python to achieve grayscale conversion, converting the color verification code image into a grayscale image with a grayscale value between 0 and 255.

[0062] The advantage of this step is that color images are generally composed of RGB, which is actually the superposition of three two-dimensional arrays. When R=G=B, the color image will become a grayscale color, commonly known as a "black and white photo". In this way, the three two-dimensional arrays can be simplified into one two-dimensional array.

[0063] (1-2) Binarizing the grayscale image obtained in step (1-1) to obtain a binary matrix;

[0064] Specifically, the size of the binarized matrix obtained in this step is exactly the same as the size of the verification code image. If the size of the verification code image is 16*16, the size of the binarized matrix obtained is also 16*16.

[0065] An element of 1 in the binary matrix indicates that the grayscale value of the corresponding pixel in the grayscale image is greater than a value selected between 0 and 255, and an element of 0 in the binary matrix indicates that the grayscale value of the corresponding pixel in the grayscale image is less than or equal to a value selected between 0 and 255.

[0066] The advantage of this step is that it further simplifies the image while turning it into a digital object of 0 and 1, which can then be processed mathematically.

[0067] (1-3) performing denoising on the binary matrix obtained in step (1-2) to obtain a denoised binary matrix;

[0068] Specifically, this step is, first, traverse the binary matrix in order from top to bottom and from left to right, starting from the first element obtained that is 1, obtain all elements adjacent to the element in eight directions (i.e., above, below, left, right, diagonally upper left, diagonally upper right, diagonally lower left, and diagonally lower right), and determine whether the number of elements that are 1 in all the obtained elements is less than or equal to 2. If so, set the value of the element to 0, otherwise keep it unchanged, and then enter the next element, and repeat the above process until the binary matrix is ​​traversed.

[0069] The purpose of this step is to remove the noise other than the verification code in the verification code image to facilitate subsequent processing.

[0070] (1-4) sharpening the binary matrix after denoising in step (1-3) to obtain a binary matrix after sharpening;

[0071] Specifically, the sharpening process in this step uses a weighted summation method or an integral operation method of the image neighborhood based on the Python language, which has been specifically described on the web page. https: / / blog.csdn.net / baidu_41902768 / article / details / 94613788 It should be understood that the present invention is not limited to the above-mentioned sharpening method, and any sharpening method known in the art can be used and referenced.

[0072] (1-5) converting the binary matrix after the sharpening process in step (1-4) into an image as a preprocessed image;

[0073] Specifically, the image obtained in this step is in png format, and this step can use any existing Python-based method for converting a binary matrix into a png format image.

[0074] The main purpose of the above steps (1-1) to (1-5) is to simplify the verification code image and remove unnecessary noise to form a new universal image that meets the OCR interface transmission requirements.

[0075] (2) inputting the image preprocessed in step (1) into a plurality of optical character recognition (OCR) application programming interfaces (APIs) to obtain a recognition character group consisting of a plurality of recognition characters corresponding to each OCR API (e.g., Figure 2 As shown), all the recognition character groups constitute the recognition character set {(C11, C12, ..., C1 p ), (C21, C22, …, C2 q ),…,(C(N-1)1,C(N-1)2,…,C(N-1) t ), (CN1, CN2, …, CN r )}; wherein p represents the total number of recognized characters in the recognized character group corresponding to the first OCR API, q represents the total number of recognized characters in the recognized character group corresponding to the second OCR API, …, t represents the total number of recognized characters in the recognized character group corresponding to the N-1th OCR API, r represents the total number of recognized characters in the recognized character group corresponding to the Nth OCR API, and N represents the total number of OCR APIs used.

[0076] Specifically, the OCR API interface used in this step can be a Baidu text recognition interface, a convolutional neural network (CNN) open source interface, an Alibaba OCR API interface, etc.

[0077] (3) Set counter i=1;

[0078] (4) Determine whether the counter i is greater than the total number N of OCR APIs used in step (2). If so, return to step (1); otherwise, proceed to step (5);

[0079] (5) determining whether the number of recognized characters in the recognized character group corresponding to the i-th OCR API is equal to the total number of characters in the image preprocessed in step (1), if so, proceeding to step (7), otherwise proceeding to step (6);

[0080] (6) Set step i=i+1 and return to step (5);

[0081] (7) The recognition character group corresponding to the i-th OCR API is placed at the beginning of the recognition character set, thereby obtaining a reordered recognition character set {(D11, D12, ..., D1 p’ ), (D21, D22, …, D2 q’ ),…,(D(N-1)1,D(N-1)2,…,D(N-1) t’ ), (DN1, DN2, …, DN r’ )}, and then proceed to step (8); wherein p' represents the total number of recognized characters in the first recognized character group in the reordered recognized character set, q' represents the total number of recognized characters in the second recognized character group in the reordered recognized character set, ..., t' represents the total number of recognized characters in the second to last recognized character group in the reordered recognized character set, and r' represents the total number of recognized characters in the last recognized character group in the reordered recognized character set.

[0082] The advantage of this step is that a group of characters with the highest accuracy among multiple recognition results is firstly found as benchmark data, thereby improving the success rate of correct recognition.

[0083] (8) assigning a weight value of 2 to the first recognition character D11, ..., D(N-1)1, DN1 in all the recognition character groups in the recognition character set reordered in step (7), assigning a weight value of 1 to the second recognition character D22, ..., D(N-1)2, DN2 in all the recognition character groups other than the first recognition character group in the recognition character set reordered in step (7), and for each recognition character in the formed first recognition character set {D11, ..., D(N-1)1, DN1, D22, ..., D(N-1)2, DN2} that appears twice or more, adding the weight values ​​corresponding to the recognition characters to obtain the weight sum corresponding to the recognition characters, sorting the obtained multiple weight sums in descending order, and taking the recognition character corresponding to the maximum weight sum as the first character of the recognition result;

[0084] (9) Set counter k=1;

[0085] (10) Determine whether the counter k is greater than p'-1, if so, proceed to step (13), otherwise proceed to step (11);

[0086] (11) multiple recognition character groups (D12, ..., D1 p’-1 ), (D22, D22, …, D2 q’-1 ),…,(D(N-1)2,D(N-1)3,…,D(N-1) t’-1 ), the kth recognized character D1 in all recognized character groups k , ..., D(N-1) k , D.N. k Assign a weight value of 2 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k-1th recognized character D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 Assign a weight value of 1 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k+1th recognized character D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 Assign a weight value of 1, and for the second recognition character set {D1 k , ..., D(N-1) k , D.N. k , DN1, D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 , D2 k+1 , ..., D(N-1)k+1 , D.N. k+1}, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the kth middle character of the recognition result;

[0087] (12) Set counter k=k+1 and return to step (10);

[0088] (13) is the last recognized character D1 in all recognized character groups in the recognized character set reordered in step (7) p’ , ..., D(N-1) t’ , D.N. r’ Assign a weight value of 2 to the penultimate recognized character D2 in all recognized character groups except the first recognized character group in the reordered recognized character set in step (7). q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 Assign a weight value of 1 to the third recognition character set {D1 p’ , ..., D(N-1) t’ , D.N. r’ , D2 q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 For each recognized character that appears twice or more in}, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums from large to small, and take the recognized character corresponding to the maximum weight sum as the last character of the recognition result.

[0089] The advantage of this step is that multiple OCR interfaces are used to recognize the same verification code image, and the recognized character groups are compared with each other to obtain the character composition recognition result with the highest accuracy rate in each character, which are verified with each other according to the weight strategy, thereby optimizing the recognition result.

[0090] (14) The first character obtained in step (9), the middle character obtained in step (11) and the last character obtained in step (13) are combined into the final recognition result, such as Figure 3 shown.

[0091] The present invention uses the results of multiple algorithms to obtain the optimal solutions respectively, so that the recognition rate of the picture verification code is increased by more than 0.5 times, which greatly reduces the manpower and time invested in the verification code recognition.

[0092] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A hybrid verification code recognition method based on a weight strategy, characterized in that: The following steps are involved: (1) Obtaining a verification code image, and preprocessing the verification code image to obtain a preprocessed image; (2) inputting the image preprocessed in step (1) into N optical character recognition application program interfaces (OCR APIs) respectively to obtain a recognition character group consisting of a plurality of recognition characters corresponding to each OCR API, wherein all the recognition character groups constitute a recognition character set, where N is a natural number; (3) Set counter i=1; (4) Determine whether the counter i is greater than the total number N of OCR APIs used in step (2). If so, return to step (1); otherwise, proceed to step (5). (5) Determine whether the number of recognized characters in the recognized character group corresponding to the i-th OCR API is equal to the total number of characters in the image preprocessed in step (1). If so, proceed to step (7); otherwise, proceed to step (6); (6) Set step i = i + 1 and return to step (5); (7) Place the recognized character group corresponding to the i-th OCR API at the beginning of the recognized character set, thereby obtaining the reordered recognized character set {(D11, D12, …, D1 p’ ), (D21, D22, …, D2 q’ ),…,(D(N-1)1,D(N-1)2,…,D(N-1) t’ ), (DN1, DN2, …, DN r’ )}, and then proceed to step (8); wherein p' represents the total number of recognized characters in the first recognized character group in the reordered recognized character set, q' represents the total number of recognized characters in the second recognized character group in the reordered recognized character set, ..., t' represents the total number of recognized characters in the second to last recognized character group in the reordered recognized character set, and r' represents the total number of recognized characters in the last recognized character group in the reordered recognized character set; (8) assigning a weight value of 2 to the first recognized character D11, ..., D(N-1)1, DN1 in all recognized character groups in the recognized character set reordered in step (7), assigning a weight value of 1 to the second recognized character D22, ..., D(N-1)2, DN2 in all recognized character groups other than the first recognized character group in the recognized character set reordered in step (7), and for each recognized character in the formed first recognized character set {D11, ..., D(N-1)1, DN1, D22, ..., D(N-1)2, DN2} that appears twice or more, adding the weight values ​​corresponding to the recognized character to obtain the weight sum corresponding to the recognized character, sorting the obtained multiple weight sums in descending order, and taking the recognized character corresponding to the maximum weight sum as the first character of the recognition result; (9) Set counter k = 1; (10) Determine whether the counter k is greater than p'-1. If so, proceed to step (13); otherwise, proceed to step (11); (11) multiple recognition character groups (D12, ..., D1 p’-1 ), (D22, D22, …, D2 q’-1 ),…,(D(N-1)2,D(N-1)3,…,D(N-1) t’-1 ), the kth recognized character D1 in all recognized character groups k , ..., D(N-1) k , D.N. k Assign a weight value of 2 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k-1th recognized character D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 Assign a weight value of 1 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k+1th recognized character D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 Assign a weight value of 1, and for the second recognition character set {D1 k , ..., D(N-1) k , D.N. k , DN1, D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 , D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 }, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the kth middle character of the recognition result; (12) Set counter k = k + 1 and return to step (10); (13) is the last recognized character D1 in all recognized character groups in the recognized character set after reordering in step (7) p’ , ..., D(N-1) t’ , D.N. r’ Assign a weight value of 2 to the penultimate recognized character D2 in all recognized character groups except the first recognized character group in the reordered recognized character set in step (7). q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 Assign a weight value of 1 to the third recognition character set { D1 p’ , ..., D(N-1) t’ , D.N. r’ , D2 q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 }, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the last character of the recognition result; (14) The first character obtained in step (9), the middle character obtained in step (11), and the last character obtained in step (13) are combined into a final recognition result.

2. The hybrid verification code recognition method based on weight strategy according to claim 1 is characterized in that: The preprocessing of the verification code image in step (1) specifically includes the following sub-steps: (1-1) graying the verification code image to obtain a grayscale image; (1-2) Binarizing the grayscale image obtained in step (1-1) to obtain a binary matrix; (1-3) performing denoising on the binary matrix obtained in step (1-2) to obtain a denoised binary matrix; (1-4) sharpening the binary matrix after denoising in step (1-3) to obtain a sharpened binary matrix; (1-5) Convert the binary matrix after sharpening in step (1-4) into an image as the preprocessed image.

3. The hybrid verification code recognition method based on weight strategy according to claim 2 is characterized in that: Steps (1-3) are as follows: first, traverse the binary matrix from top to bottom and from left to right, starting from the first element that is 1, obtain all elements adjacent to the element in the eight directions, and determine whether the number of elements that are 1 among all the elements obtained is less than or equal to 2. If so, set the value of the element to 0, otherwise keep it unchanged, and then enter the next element, and repeat the above process until the binary matrix is ​​traversed.

4. The hybrid verification code recognition method based on weight strategy according to claim 3 is characterized in that: OCRAPI interfaces include Baidu text recognition interface, CNN open source interface, and Alibaba OCR API interface.

5. The hybrid verification code recognition method based on weight strategy according to claim 1 is characterized in that: All the recognized character groups in step (2) constitute the recognized character set {(C11, C12, ..., C1 p ), (C21, C22, …, C2 q ),…,(C(N-1)1,C(N-1)2,…,C(N-1) t ), (CN1, CN2, …, CN r )}; wherein p represents the total number of recognized characters in the recognized character group corresponding to the first OCR API, q represents the total number of recognized characters in the recognized character group corresponding to the second OCR API, ..., t represents the total number of recognized characters in the recognized character group corresponding to the N-1th OCR API, and r represents the total number of recognized characters in the recognized character group corresponding to the Nth OCR API.

6. A hybrid verification code recognition system based on a weight strategy, characterized in that: include: The first module is used to obtain a verification code image and preprocess the verification code image to obtain a preprocessed image; The second module is used to input the images preprocessed by the first module into N optical character recognition application program interfaces (OCR APIs) respectively, so as to obtain a recognition character group consisting of a plurality of recognition characters corresponding to each OCR API, and all the recognition character groups constitute a recognition character set, wherein N is a natural number; The third module is used to set the counter i=1; The fourth module is used to determine whether the counter i is greater than the total number N of OCR APIs used in the second module, if so, return to the first module, otherwise enter the fifth module; The fifth module is used to determine whether the number of recognized characters in the recognized character group corresponding to the i-th OCR API is equal to the total number of characters in the picture preprocessed by the first module, if yes, enter the seventh module, otherwise enter the sixth module; The sixth module is used to set step i=i+1 and return to the fifth module; The seventh module is used to place the recognition character group corresponding to the i-th OCR API at the beginning of the recognition character set, so as to obtain a reordered recognition character set {(D11, D12, ..., D1 p’ ), (D21, D22, …, D2 q’ ),…,(D(N-1)1,D(N-1)2,…,D(N-1) t’ ), (DN1, DN2, …, DN r’ )}, and then enter the eighth module; wherein p' represents the total number of recognized characters in the first recognized character group in the reordered recognized character set, q' represents the total number of recognized characters in the second recognized character group in the reordered recognized character set, ..., t' represents the total number of recognized characters in the second to last recognized character group in the reordered recognized character set, and r' represents the total number of recognized characters in the last recognized character group in the reordered recognized character set; an eighth module, for assigning a weight value of 2 to the first recognition character D11, ..., D(N-1)1, DN1 in all the recognition character groups in the recognition character set reordered by the seventh module, and assigning a weight value of 1 to the second recognition character D22, ..., D(N-1)2, DN2 in all the recognition character groups except the first recognition character group in the recognition character set reordered by the seventh module, and for each recognition character that appears twice or more in the formed first recognition character set {D11, ..., D(N-1)1, DN1, D22, ..., D(N-1)2, DN2}, adding the weight values ​​corresponding to the recognition characters to obtain the weight sum corresponding to the recognition characters, sorting the obtained multiple weight sums in descending order, and taking the recognition character corresponding to the maximum weight sum as the first character of the recognition result; The ninth module is used to set the counter k=1; The tenth module is used to determine whether the counter k is greater than p'-1, if so, enter the thirteenth module, otherwise enter the eleventh module; The eleventh module is used to sort the multiple recognition character groups (D12, ..., D1 p’-1 ), (D22, D22, …, D2 q’-1 ),…,(D(N-1)2,D(N-1)3,…,D(N-1) t’-1 ), the kth recognized character D1 in all recognized character groups k , ..., D(N-1) k , D.N. k Assign a weight value of 2 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k-1th recognized character D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 Assign a weight value of 1 to all characters except the first recognized character group (D12, ..., D1 p’-1 ) in all recognized character groups except the k+1th recognized character D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 Assign a weight value of 1, and for the second recognition character set {D1 k , ..., D(N-1) k , D.N. k , DN1, D2 k-1 , ..., D(N-1) k-1 , D.N. k-1 , D2 k+1 , ..., D(N-1) k+1 , D.N. k+1 }, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the kth middle character of the recognition result; The twelfth module is used to set the counter k=k+1 and return to the tenth module; The thirteenth module is used for the last recognized character D1 in all the recognized character groups in the recognized character set reordered by the seventh module. p’ , ..., D(N-1) t’ , D.N. r’ Assign a weight value of 2 to the penultimate recognized character D2 in all recognized character groups except the first recognized character group in the reordered recognized character set of the seventh module. q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 Assign a weight value of 1 to the third recognition character set { D1 p’ , ..., D(N-1) t’ , D.N. r’ , D2 q’-1 , ..., D(N-1) t’-1 , D.N. r’-1 }, for each recognized character that appears twice or more, add the weight values ​​corresponding to the recognized characters to obtain the weight sum corresponding to the recognized characters, sort the obtained multiple weight sums in descending order, and take the recognized character corresponding to the maximum weight sum as the last character of the recognition result; The fourteenth module is used to combine the first character obtained by the ninth module, the middle character obtained by the eleventh module, and the last character obtained by the thirteenth module into a final recognition result.