Text detection method, device, equipment and storage medium
By screening the rotated anchor boxes and determining the positive samples in the rotated object detector and optimizing the loss function, the problem of long training time of the rotated object detector is solved, and fast and efficient text detection is achieved.
Patent Information
- Application Number
- CN202111610949.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The existing rotation object detector has a long training time and slow speed due to the complex intersection-over-union calculation logic and too many anchor boxes during the training process, which affects the efficiency of text detection.
By obtaining the image to be detected and inputting it into the predetermined target text detection model, the loss function is determined according to the angle of the positive sample, the rotated anchor frame is screened, the intersection-over-union ratio is calculated, the positive sample is determined, and the loss function is adjusted to optimize model training, reduce the amount of calculation, and increase the training speed.
It greatly reduces model training time, improves the speed and efficiency of text detection, and ensures the accuracy of detection.
Smart Images

Figure CN114332880B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of text detection technology, and in particular to a text detection method, apparatus, device, and storage medium. Background Art
[0002] With the rapid development of artificial intelligence technology, artificial neural networks are increasingly being used in various fields, such as text detection, vehicle detection, and person detection. However, objects such as text and vehicles in images are not horizontal, and rotated object detection is required. In the rotated object detection scenario, the detection results of the horizontal box detector often carry redundant background information. In order to improve the ability of the horizontal box detector to detect rotated objects, academia and industry are increasingly conducting research on rotated object detectors. In the training and optimization of rotated object detectors, the traditional horizontal anchor box needs to be improved into a rotated anchor box to meet the requirements of the rotated object detector. However, this improvement brings the following problems to the training:
[0003] First, the logic for calculating the intersection-and-union ratio is more complex. Compared with horizontal rectangular boxes, rotating rectangular boxes will produce complex positive and negative sample matching calculation logic. The main reason is that the complexity of solving the intersection-and-union set between rotated rectangular boxes is the highest. Second, it is necessary to balance the relationship between generating high-quality rotated anchor boxes and the amount of calculation required for positive and negative sample matching. As we all know, the rotated anchor boxes of the rotation detector usually take angles from [0,180] or [0,90] and other ranges at equal intervals as candidate angle sets. The smaller the interval, the more anchor boxes are generated. In the process of positive and negative sample matching, the higher the overlap between the anchor box and the real sample box, the higher the quality of positive samples can be generated to participate in training.
[0004] However, the complex IoU calculations make the training process longer than for horizontal rectangular box detectors, resulting in a slowdown in training iterations. Excessive anchor boxes significantly increase the computational effort required to match positive and negative samples, further slowing down training iterations. Consequently, existing models struggle with long training times and slow training speeds when detecting objects like text, hindering their ability to detect text. Summary of the Invention
[0005] The present invention provides a text detection method, apparatus, device and storage medium to achieve rapid and accurate detection of the location of text.
[0006] In a first aspect, an embodiment of the present invention provides a text detection method, the method comprising:
[0007] Get the image to be detected;
[0008] Inputting the image to be detected into a predetermined target text detection model, wherein a loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle;
[0009] The text in the image to be detected is detected according to the output result of the target text detection model to obtain the target text box corresponding to the text.
[0010] In a second aspect, an embodiment of the present invention further provides a text detection device, the device comprising:
[0011] Image acquisition module, used to obtain the image to be detected;
[0012] An input module, configured to input the image to be detected into a predetermined target text detection model, wherein a loss function of the target text detection model is determined based on a positive sample, and the positive sample is determined based on an angle;
[0013] The detection module is used to detect the text in the image to be detected according to the output result of the target text detection model to obtain the target text box corresponding to the text.
[0014] In a third aspect, an embodiment of the present invention further provides a computer device, the device comprising:
[0015] one or more processors;
[0016] a memory for storing one or more programs,
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement a text detection method as described in any one of the embodiments of the present invention.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a text detection method as described in any one of the embodiments of the present invention.
[0019] The embodiment of the present invention provides a text detection method, apparatus, device and storage medium. The method comprises the following steps: obtaining a picture to be detected; inputting the picture to be detected into a predetermined target text detection model, wherein the loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle; detecting the text in the picture to be detected according to the output result of the target text detection model, and obtaining a target text box corresponding to the text. The positive sample is determined according to the angle, and then the loss function of the target text detection model is calculated using the positive sample. The target text detection model is adjusted using the loss function, and then text detection is performed on the picture to be detected using the target text detection model to obtain the target text box where the text is located. This method solves the problems of long training time and slow training speed caused by the large amount of sample matching calculations during model training, greatly reduces the training time, improves the training speed, and thus achieves fast and efficient text detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 is a flowchart of a text detection method in embodiment 1 of the present invention;
[0021] Figure 2a This is a schematic diagram showing multiple target text boxes in the first embodiment of the present invention;
[0022] Figure 2b This is another schematic diagram showing multiple target text boxes in the first embodiment of the present invention;
[0023] Figure 2c This is a schematic diagram showing a single target text box in the first embodiment of the present invention.
[0024] Figure 3 is a flowchart of a text detection method in embodiment 2 of the present invention;
[0025] Figure 4a This is an example diagram showing the positions of a standard detection frame and an anchor frame to be matched in the second embodiment of the present invention;
[0026] Figure 4b This is an example diagram showing the positions of a standard horizontal detection frame and a horizontal anchor frame to be matched in the second embodiment of the present invention;
[0027] Figure 5 This is a structural diagram of a text detection device in Embodiment 3 of the present invention;
[0028] Figure 6 It is a structural diagram of a computer device in embodiment 4 of the present invention. DETAILED DESCRIPTION
[0029] To make the purpose, technical solutions, and advantages of this application more clear, the embodiments of this application will be further described in detail below with reference to the accompanying drawings. It should be understood that the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0030] When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0031] In the description of this application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to the specific circumstances. In addition, in the description of this application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.
[0032] Example 1
[0033] Figure 1 A flowchart of a text detection method provided in Example 1 of the present application is provided. This method is applicable to detecting text in images. The method can be executed by a computer device, which can be composed of two or more physical entities or a single physical entity. Generally speaking, the computer device can be a laptop, desktop computer, smart tablet, etc.
[0034] like Figure 1 As shown, the text detection method provided in this embodiment includes the following steps:
[0035] S101: Obtain a picture to be detected.
[0036] In this embodiment, the image to be detected can be specifically understood as a picture with detection requirements. The image to be detected may include backgrounds such as text, people, trees, and the sky. The image to be detected may be a photographed image of a book, newspaper, journal, etc., or any photographed image. For example, an image taken on the street may include plaques, paper, etc., and the plaques and paper may include text. The image to be detected can be collected and stored in advance, and detected when detection is required or when the detection conditions (timing) are met. During detection, the image can be directly obtained from a server, a local storage space, or the like; alternatively, the image to be detected can be detected in real time after collection, and the image to be detected can be obtained from an image acquisition device (e.g., a camera, a video camera) and detected in real time.
[0037] S102: Input the image to be detected into a predetermined target text detection model. The loss function of the target text detection model is determined according to the positive sample, and the positive sample is determined according to the angle.
[0038] In this embodiment, the target text detection model can be specifically understood as a neural network model capable of text detection, such as the Yolov3 model. A positive sample can be specifically understood as a sample that is closest to the annotated standard information during model training. The angle in this application refers to the rotation angle of the text detection box in the image relative to the horizontal direction.
[0039] Specifically, the neural network model is pre-trained, and the loss function is continuously calculated during the training process. Backpropagation is performed through the loss function to achieve model convergence, obtain a target text detection model that meets the requirements, and complete the training. Detection frames are pre-labeled for the text in the image. During the model training process, detection frames of different sizes and angles are generated based on the relevant information of the pre-given detection frames. The detection frame closest to the pre-labeled detection frame is selected from each detection frame based on its angle as a positive sample. The loss function is calculated based on the information of the detection frame corresponding to the positive sample, completing the training of the target text detection model.
[0040] S103: Detect the text in the image to be detected according to the output result of the target text detection model, and obtain the target text box corresponding to the text.
[0041] In this embodiment, the target text box can be specifically understood as a detection box for selecting text, which can be a matrix box.
[0042] For example, consider an image containing a plaque or banner containing Chinese characters. The image is fed into the target text detection model. The model detects the image based on learned experience or the model's network parameters, locates the text within it, and generates a target text box to select the text. Multiple target text boxes can be used. If the text within the image is scattered, one or more target text boxes can be used for selection.
[0043] For example, the first line of the image to be detected has the text "China" and "World" on the left and right respectively, and the second line has the text "Universe" on the left. Figure 2a A schematic diagram showing multiple target text boxes is provided, such as Figure 2a As shown, the text in the same row in the image to be detected is selected using a target text box 21. Figure 2b Another schematic diagram for displaying multiple target text boxes is provided, in which "China", "World" and "Universe" in the image to be detected are respectively selected using three target text boxes 21. Figure 2c A schematic diagram showing a single target text box is provided, where all text in the image to be detected is selected using a target text box 21 .
[0044] An embodiment of the present invention provides a text detection method, which comprises obtaining a picture to be detected; inputting the picture to be detected into a predetermined target text detection model, wherein the loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle; and detecting the text in the picture to be detected according to the output result of the target text detection model to obtain a target text box corresponding to the text. The positive sample is determined according to the angle, and then the loss function of the target text detection model is calculated using the positive sample. The target text detection model is adjusted using the loss function, and then text detection is performed on the picture to be detected using the target text detection model to obtain the target text box where the text is located. This method solves the problems of long training time and slow training speed caused by the large amount of sample matching calculations during model training, greatly reduces the training time, improves the training speed, and thus achieves fast and efficient text detection.
[0045] Example 2
[0046] Figure 3 This is a flowchart of a text detection method provided in Example 2 of the present invention. The technical solution of this embodiment is further refined on the basis of the above technical solution, and specifically includes the following steps:
[0047] S301. Acquire a training sample set including at least one training sample, where the training sample includes standard frame information of a standard detection frame, where the standard frame information includes standard center point coordinates, standard length, standard width, and standard angle.
[0048] In this embodiment, the training sample set can be specifically understood as a set consisting of one or more training samples, and the standard detection frame can be specifically understood as a detection frame used as a reference standard for the prediction result. The standard frame information can be specifically understood as the detection frame information of the standard detection frame, including the standard center point coordinates, standard length, standard width, and standard angle.
[0049] Specifically, one or more training samples are obtained in advance. To ensure the accuracy of model prediction, a large number of training samples are usually required. The training samples are annotated and the text in the training samples is annotated with a standard detection frame. The standard frame information of the standard detection frame includes the standard center point coordinates, standard length, standard width and standard angle. A detection frame can be uniquely determined by the coordinates, length, width and angle. In the real-time example of this application, the horizontal direction is the x-axis and the vertical direction is the y-axis to determine the standard angle.
[0050] S302. Input the training samples corresponding to the current iteration into the current text detection model to be trained. The text detection model to be trained generates at least one rotation anchor frame according to the training samples under the current iteration. The rotation frame information of the rotation anchor frame includes the coordinates of the rotation center point, the rotation length, the rotation width and the rotation angle.
[0051] In this embodiment, the to-be-trained text detection model can be specifically understood as a neural network model with training requirements for text detection. The rotated anchor frame can be specifically understood as a detection frame used for text detection, each of which may contain text. The rotated anchor frame information can be specifically understood as information describing the size, position, and angle of the rotated anchor frame.
[0052] Specifically, the training samples corresponding to the current iteration are input into the current text detection model to be trained, which includes the information of the pre-set detection frame. The rotation anchor frame is generated according to the position of the training samples in the current iteration and the information of the pre-set detection frame, and the position, size and angle of the rotation frame are represented by the rotation frame information.
[0053] As an optional embodiment of this embodiment, this optional embodiment further optimizes the text detection model to be trained to generate at least one rotated anchor frame according to the training sample in the current iteration:
[0054] A1. Obtain a predetermined anchor frame information set, where the anchor frame information set includes a preset number of anchor frame information, and the anchor frame information includes length, width, and angle.
[0055] In this embodiment, the anchor frame information set can be specifically understood as a set of one or more pieces of information used to generate a rotated anchor frame. The preset number can be specifically understood as a pre-set number, which is set based on the actual situation and requirements of model training. The length and width in the anchor frame information are used to define the length and width of the generated rotated anchor frame, that is, the size of the rotated anchor frame, and the angle is used to define the angle of the rotated anchor frame.
[0056] A2. Use the standard center point coordinates of the training sample in the current iteration as the center point, and generate the rotated anchor frame corresponding to each anchor frame information according to the anchor frame information.
[0057] Determine the standard center coordinates of the training sample in the current iteration. Use the standard center coordinates as the center of the rotated anchor frame. Generate corresponding rotated anchor frames based on the information of each anchor frame. This results in rotated anchor frames with the same center but different lengths, widths, and angles. The rotation center coordinates of each rotated anchor frame are the same as the standard center coordinates. The number of rotated anchor frames is the preset number.
[0058] S303: Filter each rotation anchor frame according to the standard angle of the training sample in the current iteration to obtain at least one anchor frame to be matched.
[0059] In this embodiment, the anchor frame to be matched can be specifically understood as the rotated anchor frame that needs to be matched with the standard detection frame. The standard angle of the training sample is compared with the rotation angle of each rotated anchor frame to screen the rotated anchor frames. The rotated anchor frame that is closest in angle to the standard detection frame in the training sample is obtained, and the selected rotated anchor frame is determined as the anchor frame to be matched.
[0060] When the angles of the standard detection frame and the rotated anchor frame are close, it can be approximately considered that the two rotated rectangles are horizontally distributed along a straight line ax+by+c=0. Therefore, this application screens each rotated anchor frame by the standard angle.
[0061] As an optional embodiment of this embodiment, this optional embodiment further screens each rotated anchor frame according to the standard angle of the training sample in the current iteration, and obtains at least one anchor frame to be matched and is optimized as follows:
[0062] B1. Determine the angle difference between the standard angle of the training sample and the rotation angle of each rotation anchor frame.
[0063] Determine the standard angle of the standard detection frame of the training sample and the rotation angle of each rotation anchor frame, and calculate the angle difference between the standard angle and each rotation angle. The angle difference in this application refers to the absolute value of the angle difference, which can be the standard angle minus the rotation angle, or the rotation angle minus the standard angle.
[0064] B2. Compare the angle differences and determine the minimum angle difference.
[0065] In this embodiment, the minimum angle difference can be specifically understood as the minimum value of the angle differences. By comparing the sizes of the angle differences, the minimum value of the angle differences is determined, that is, the minimum angle difference.
[0066] B3. Determine the rotation anchor frames corresponding to the minimum angle difference as the anchor frames to be matched.
[0067] Determine the rotation anchor frames corresponding to the minimum angle difference, and determine this part of the rotation anchor frames as the matching detection frames.
[0068] S304: Determine positive samples based on each anchor frame to be matched.
[0069] Calculate the matching degree between each anchor frame to be matched and the standard detection frame. For example, calculate the overlapping area, intersection-over-union ratio, etc. of the anchor frame to be matched and the standard detection frame to obtain the anchor frame to be matched with a higher matching degree and determine it as a positive sample.
[0070] As an optional embodiment of this embodiment, this optional embodiment further optimizes the positive samples determined according to each anchor frame to be matched as follows:
[0071] C1. Horizontally transform the standard detection frame to obtain a standard horizontal detection frame.
[0072] In this embodiment, the standard horizontal detection frame can be specifically understood as the detection frame corresponding to the standard detection frame in the horizontal direction. The standard detection frame is converted horizontally to a horizontal detection frame while maintaining the standard center point coordinates unchanged. The standard angle of the standard detection frame is set to 0, thereby obtaining the standard horizontal detection frame.
[0073] C2. Perform horizontal transformation on each anchor frame to be matched to obtain a horizontal anchor frame to be matched.
[0074] In this embodiment, the horizontal anchor frame to be matched can be specifically understood as the anchor frame corresponding to the anchor frame to be matched in the horizontal direction. The anchor frame to be matched is horizontally transformed, maintaining the coordinates of its rotation center point unchanged, to convert it into a horizontal anchor frame. The rotation angle of the anchor frame to be matched is set to 0, resulting in the horizontal anchor frame to be matched. The resulting standard horizontal detection frame aligns with the center point of the horizontal anchor frame to be matched, and both are horizontally oriented, facilitating the subsequent calculation of the intersection-over-union ratio.
[0075] For example, Figure 4a An example diagram showing the positions of a standard detection frame and an anchor frame to be matched is provided, such as Figure 4a As shown, the standard detection frame 401 and the anchor frame to be matched 402 have a certain angle relative to the horizontal direction. Figure 4b An example diagram showing the positions of a standard horizontal detection frame and a horizontal anchor frame to be matched is provided, such as Figure 4bAs shown in FIG, after horizontal rotation, the horizontal angle between the standard horizontal detection frame 411 and the horizontal anchor frame to be matched 412 is 0, and two horizontal detection frames are obtained. Figure 4a and Figure 4b Two different styles of lines are used to represent different detection boxes.
[0076] C3. Calculate the intersection-over-union ratio of the standard horizontal detection frame and each horizontal anchor frame to be matched.
[0077] For each horizontal anchor frame to be matched, calculate the intersection area of the standard horizontal detection frame and the horizontal anchor frame to be matched, as well as the area of the standard horizontal detection frame and the area of the horizontal anchor frame to be matched, and calculate the intersection-in-union ratio according to the intersection-in-union ratio calculation formula. The intersection-in-union ratio calculation formula is as follows:
[0078]
[0079] Where A∩B is the area of the intersection of the standard horizontal detection frame and the horizontal anchor frame to be matched; A is the area of the standard horizontal detection frame; B is the area of the horizontal anchor frame to be matched.
[0080] The standard horizontal detection frame and the horizontal anchor frame to be matched in this application can also be represented by the coordinates of the upper left and lower right points.
[0081] C4. Determine the maximum intersection-over-union ratio and determine the horizontal anchor box to be matched corresponding to the maximum intersection-over-union ratio as a positive sample.
[0082] In this embodiment, the maximum IoU can be specifically understood as the maximum value of the IoUs. The IoUs are compared to determine the maximum value, i.e., the maximum IoU. The horizontal anchor frame to be matched corresponding to the maximum IoU is determined, and this horizontal anchor frame to be matched is determined as a positive sample. A positive sample is the detection frame with the highest degree of overlap with the standard detection frame.
[0083] As an optional embodiment of this embodiment, this optional embodiment is further optimized to include determining the training sample as an invalid sample if the maximum intersection-over-union (IoU) is less than a preset IoU threshold before determining the to-be-matched horizontal anchor frame corresponding to the maximum IoU as a positive sample.
[0084] In this embodiment, the IoU threshold can be understood as a pre-set threshold used to determine whether the maximum IoU is within the allowable error range. After determining the maximum IoU, a determination is made as to whether the maximum IoU is greater than or equal to the pre-set IoU threshold. If so, the horizontal anchor box to be matched corresponding to the maximum IoU can be determined as a positive sample. If not, the error of the training sample is too large, and the training sample is determined to be an invalid sample and excluded from model training, thereby improving the model detection accuracy.
[0085] As an optional embodiment of this embodiment, this optional embodiment is further optimized to include rounding the standard center point coordinates when the standard center point coordinates are non-integers.
[0086] When the standard center point coordinates are non-integer, the standard center point coordinates are rounded to an integer. The rounding calculation can be rounding down, rounding up, etc. For example, if the standard center point coordinates are (10.2, 11.5), the rounded standard center point coordinates are (10, 11), and accordingly, the rotation center point coordinates are also (10, 11). When the standard center point coordinates are not integers, the calculation results are unstable when calculated using the standard center point coordinates. Therefore, this application uses rounding for calculation.
[0087] It should be noted that in the prior art, when calculating the intersection-union ratio of two detection frames, it is necessary to first convert the coordinates of the standard detection frame and the rotated anchor frame into the form of four-point coordinates (x1, y1, x2, y2, x3, y3, x4, y4); convert the point set containing the four points into a point set sorted clockwise; calculate one by one whether the two sides between the real sample frame and the anchor frame intersect and the intersection coordinates [x, y], and finally obtain the intersection set; sort the intersection set clockwise; calculate the area of the intersection set C, and then calculate the area of the standard detection frame and the rotated anchor frame; calculate the intersection-union ratio according to the intersection-union ratio formula. The above method is computationally intensive and logically complex during calculation, involving a large amount of numerical calculations and logical judgments, and the training time is long, which greatly reduces the model training speed. This application first screens by angle to obtain the rotated anchor frame corresponding to the minimum angle difference, i.e., the to-be-matched anchor frame. The standard detection frame and the to-be-matched anchor frame are then horizontally transformed, and the intersection-over-union ratio is calculated. This reduces the amount of computation required during sample matching, saving training time. Furthermore, the number of rotation angles for the rotated anchor frame can be increased in the model to improve the convergence speed of the model. Due to the high computational complexity in the prior art, to ensure the training iteration speed, the interval range for selecting rotated anchor frames at different angles is relatively large, typically 30°.
[0088] S205. Based on a given loss function expression, the loss function is determined by combining the rotation box information of the positive sample and the standard box information.
[0089] In this embodiment, the loss function can be a GAN loss function, an L1 loss function, a focal loss function, a VGG perceptual loss function, etc.
[0090] For each positive sample, the loss function expression is used for calculation based on its corresponding rotation frame information and standard frame information to determine the corresponding loss function. When there are multiple standard detection frames in a training sample, each standard detection frame can determine a corresponding positive sample, and then the loss function is calculated based on the positive sample. In this case, the calculated loss functions may be multiple, so multiple loss functions can be fitted to obtain a fitted loss function. The way to fuse the loss functions to form the fitted loss function can be to set different weights for each loss function, take the average value, etc., and the embodiment of the present invention does not make specific restrictions on this.
[0091] S206 , backpropagating the text detection model to be trained based on the loss function to obtain the text detection model to be trained for the next iteration, until the iterative convergence condition is met, and obtaining the target text detection model.
[0092] During the training process of the neural network model, the model is continuously updated and adjusted through backpropagation until the model output converges with the target. After determining the loss function, the training text detection model is backpropagated using this loss function to obtain a target text detection model that meets the iterative convergence conditions. The embodiments of the present invention do not limit the specific backpropagation process and can be configured according to specific circumstances. After model training is completed, the target text detection model can be used to detect text in the image to be detected.
[0093] After the model is trained through S301-S306 to obtain the target text detection model, text detection can be performed using the target text detection model to detect the text in the image to be detected and obtain a target text detection frame.
[0094] S307: Obtain the image to be detected.
[0095] S308: Input the image to be detected into a predetermined target text detection model.
[0096] The target text detection model in this step is a neural network model trained using the training method of S301-S306. The image to be detected is input into the target text detection model, and the target text detection model processes the image to be detected based on the experience or network parameters learned during training.
[0097] S309: Detect the text in the image to be detected according to the output result of the target text detection model, and obtain the target text box corresponding to the text.
[0098] After detecting the image to be detected, the target text detection model obtains the target text box corresponding to each text in the image to be detected. The number of target text boxes can be one or more to realize text detection.
[0099] An embodiment of the present invention provides a text detection method that screens rotated anchor frames by comparing the angular difference between the standard angle of a training sample and the rotation angle of each rotated anchor frame, obtaining at least one anchor frame to be matched. The standard detection frame and the anchor frame to be matched are then horizontally transformed to obtain a horizontal detection frame, and then the intersection-over-union (IoU) ratio is calculated. This method significantly reduces computational effort and saves training time. Furthermore, the number of rotation angles of the rotated anchor frames can be increased to improve the convergence speed of the model, reducing the difficulty of learning the model regression angle. When determining positive samples using the IoU ratio, positive samples can be quickly determined. The loss function of the target text detection model is calculated using the positive samples, and the target text detection model is then adjusted using the loss function to perform text detection on the image to be detected and obtain the target text frame where the text is located. This method solves the problems of long training time and slow training speed caused by the large amount of sample matching computation during model training, significantly reducing training time and improving training speed, thereby achieving fast and efficient text detection. And by rounding the coordinates of the standard center point, the stability of the calculation process can be guaranteed; at the same time, by setting the intersection-over-union ratio threshold to determine invalid samples, invalid samples are prevented from participating in model training, further improving the accuracy of model prediction.
[0100] Example 3
[0101] Figure 5 This is a structural diagram of a text detection device provided in Embodiment 3 of the present invention. The device includes: an image acquisition module 51, an input module 52 and a detection module 53.
[0102] The image acquisition module 51 is used to acquire the image to be detected;
[0103] An input module 52 is configured to input the image to be detected into a predetermined target text detection model, wherein the loss function of the target text detection model is determined based on positive samples, and the positive samples are determined based on angles;
[0104] The detection module 53 is used to detect the text in the image to be detected according to the output result of the target text detection model, and obtain the target text box corresponding to the text.
[0105] An embodiment of the present invention provides a text detection device, which obtains a picture to be detected; inputs the picture to be detected into a predetermined target text detection model, wherein the loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle; and detects the text in the picture to be detected according to the output result of the target text detection model to obtain a target text box corresponding to the text. The positive sample is determined according to the angle, and then the loss function of the target text detection model is calculated using the positive sample. The target text detection model is adjusted using the loss function, and then text detection is performed on the picture to be detected using the target text detection model to obtain the target text box where the text is located. This solves the problems of long training time and slow training speed caused by the large amount of sample matching calculations during model training, greatly reduces the training time, improves the training speed, and thus achieves fast and efficient text detection.
[0106] Furthermore, the device also includes:
[0107] a sample set acquisition module, configured to acquire a training sample set comprising at least one training sample, wherein the training sample comprises standard frame information of a standard detection frame, wherein the standard frame information comprises standard center point coordinates, standard length, standard width, and standard angle;
[0108] A rotation frame generation module is used to input the training samples corresponding to the current iteration into the current text detection model to be trained, and the text detection model to be trained generates at least one rotation anchor frame according to the training samples under the current iteration, and the rotation frame information of the rotation anchor frame includes the coordinates of the rotation center point, the rotation length, the rotation width and the rotation angle;
[0109] A matching frame generation module is used to screen the rotated anchor frames according to the standard angle of the training sample in the current iteration to obtain at least one anchor frame to be matched;
[0110] A positive sample determination module, configured to determine a positive sample based on each of the anchor frames to be matched;
[0111] A loss function determination module, configured to determine a loss function based on a given loss function expression, combined with the rotation box information and the standard box information of the positive sample;
[0112] The target model generation module is used to perform backpropagation on the text detection model to be trained based on the loss function to obtain the text detection model to be trained for the next iteration until the iterative convergence condition is met to obtain the target text detection model.
[0113] Furthermore, the rotation frame generation module includes:
[0114] an information set acquiring unit, configured to acquire a predetermined anchor frame information set, wherein the anchor frame information set includes a preset number of anchor frame information, and the anchor frame information includes length, width, and angle;
[0115] The rotation frame generating unit is configured to use the standard center point coordinates of the training sample in the current iteration as the center point and generate a rotation anchor frame corresponding to each anchor frame information according to each anchor frame information.
[0116] Furthermore, the matching box generation module includes:
[0117] an angle difference determining unit, configured to determine an angle difference between a standard angle of a training sample and a rotation angle of each of the rotation anchor frames;
[0118] an angle difference comparison unit, configured to compare the angle differences and determine a minimum angle difference;
[0119] The matching frame generating unit is configured to determine each of the rotation anchor frames corresponding to the minimum angle difference as an anchor frame to be matched.
[0120] Furthermore, the positive sample determination module includes:
[0121] a standard horizontal conversion unit, configured to perform horizontal conversion on the standard detection frame to obtain a standard horizontal detection frame;
[0122] a to-be-matched horizontal conversion unit, configured to perform horizontal conversion on each of the to-be-matched anchor frames to obtain a to-be-matched horizontal anchor frame;
[0123] an IoU determining unit, configured to calculate an IoU between the standard horizontal detection frame and each of the horizontal anchor frames to be matched;
[0124] The positive sample determination unit is used to determine a maximum intersection-over-union ratio and determine the to-be-matched horizontal anchor frame corresponding to the maximum intersection-over-union ratio as a positive sample.
[0125] Furthermore, the device also includes:
[0126] The IoU judgment module is used to determine the training sample as an invalid sample if the maximum IoU is less than a preset IoU threshold before determining the to-be-matched horizontal anchor frame corresponding to the maximum IoU as a positive sample.
[0127] Furthermore, the device also includes:
[0128] The rounding module is used to round the standard center point coordinates when the standard center point coordinates are non-integers.
[0129] The text detection device provided in the embodiment of the present invention can execute the text detection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0130] Example 4
[0131] Figure 6 A schematic diagram of the structure of a computer device provided in the fourth embodiment of the present invention is shown in FIG. Figure 6 As shown, the device includes a processor 60, a memory 61, an input device 62 and an output device 63; the number of processors 60 in the device can be one or more. Figure 6 In the embodiment, a processor 60 is used as an example; the processor 60, the memory 61, the input device 62 and the output device 63 in the device can be connected by a bus or other means. Figure 6 The bus connection is taken as an example.
[0132] The memory 61, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the text detection method in the embodiments of the present invention (for example, the image acquisition module 51, input module 52, and detection module 53 in the text detection device). The processor 60 executes the software programs, instructions, and modules stored in the memory 61 to execute various functional applications and data processing of the device, thereby implementing the above-mentioned text detection method.
[0133] The memory 61 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data generated based on the use of the terminal. Furthermore, the memory 61 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the memory 61 may further include memory remotely located relative to the processor 60, and these remote memories may be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0134] The input device 62 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 63 may include a display device such as a display screen.
[0135] Example 5
[0136] A fifth embodiment of the present invention further provides a storage medium containing computer-executable instructions. When the computer-executable instructions are executed by a computer processor, the computer-executable instructions are used to perform a text detection method. The method includes:
[0137] Get the image to be detected;
[0138] Inputting the image to be detected into a predetermined target text detection model, wherein a loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle;
[0139] The text in the image to be detected is detected according to the output result of the target text detection model to obtain the target text box corresponding to the text.
[0140] Of course, the computer-executable instructions of the storage medium provided by the embodiment of the present invention are not limited to the operations of the method described above, but can also execute related operations in the text detection method provided by any embodiment of the present invention.
[0141] Through the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented with the help of software and necessary general-purpose hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0142] It is worth noting that in the embodiment of the above-mentioned text detection device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0143] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A text detection method, characterized in that: include: Get the image to be detected; Inputting the image to be detected into a predetermined target text detection model, wherein a loss function of the target text detection model is determined according to a positive sample, and the positive sample is determined according to an angle; Detect the text in the image to be detected according to the output result of the target text detection model to obtain a target text box corresponding to the text; The training steps of the target text detection model include: Acquire a training sample set including at least one training sample, wherein the training sample includes standard frame information of a standard detection frame, wherein the standard frame information includes standard center point coordinates, standard length, standard width, and standard angle; Inputting the training sample corresponding to the current iteration into the current to-be-trained text detection model, the to-be-trained text detection model generates at least one rotation anchor frame according to the training sample under the current iteration, wherein the rotation frame information of the rotation anchor frame includes the coordinates of the rotation center point, the rotation length, the rotation width, and the rotation angle; Screening each of the rotation anchor frames according to the standard angle of the training sample in the current iteration to obtain at least one anchor frame to be matched; Determine a positive sample according to each of the anchor frames to be matched; Based on a given loss function expression, the loss function is determined by combining the rotation box information of the positive sample with the standard box information; Backpropagation is performed on the text detection model to be trained based on the loss function to obtain a text detection model to be trained for the next iteration, until an iterative convergence condition is met, thereby obtaining a target text detection model; The step of screening the rotated anchor frames according to the standard angle of the training sample in the current iteration to obtain at least one anchor frame to be matched includes: Determine the angle difference between the standard angle of the training sample and the rotation angle of each of the rotation anchor frames; comparing the angle differences to determine a minimum angle difference; The rotated anchor frames corresponding to the minimum angle difference are determined as anchor frames to be matched.
2. The method according to claim 1, characterized in that The text detection model to be trained generates at least one rotated anchor frame according to the training sample in the current iteration, including: Acquire a predetermined anchor frame information set, where the anchor frame information set includes a preset number of anchor frame information, and the anchor frame information includes length, width, and angle; The standard center point coordinates of the training sample in the current iteration are used as the center point, and a rotation anchor frame corresponding to each anchor frame information is generated according to each anchor frame information.
3. The method according to claim 1, characterized in that The determining of positive samples according to the anchor frames to be matched includes: Performing a horizontal transformation on the standard detection frame to obtain a standard horizontal detection frame; Performing horizontal transformation on each of the to-be-matched anchor frames to obtain a to-be-matched horizontal anchor frame; Calculating the intersection-over-union ratio of the standard horizontal detection frame and each of the horizontal anchor frames to be matched; The maximum intersection-over-union (IoU) ratio is determined, and the to-be-matched horizontal anchor frame corresponding to the maximum IoU ratio is determined as a positive sample.
4. The method according to claim 3, characterized in that Before determining the to-be-matched horizontal anchor frame corresponding to the maximum IoU ratio as a positive sample, the method includes: If the maximum IoU is less than a preset IoU threshold, the training sample is determined to be an invalid sample.
5. The method according to any one of claims 1 to 4, characterized in that When the standard center point coordinates are non-integers, the standard center point coordinates are rounded.
6. A text detection device, characterized in that: include: Image acquisition module, used to obtain the image to be detected; An input module, configured to input the image to be detected into a predetermined target text detection model, wherein a loss function of the target text detection model is determined based on a positive sample, and the positive sample is determined based on an angle; A detection module, configured to detect the text in the image to be detected based on the output result of the target text detection model, and obtain a target text box corresponding to the text; Wherein, the device further comprises: a sample set acquisition module, configured to acquire a training sample set comprising at least one training sample, wherein the training sample comprises standard frame information of a standard detection frame, wherein the standard frame information comprises standard center point coordinates, standard length, standard width, and standard angle; A rotation frame generation module is used to input the training samples corresponding to the current iteration into the current text detection model to be trained, and the text detection model to be trained generates at least one rotation anchor frame according to the training samples under the current iteration, and the rotation frame information of the rotation anchor frame includes the coordinates of the rotation center point, the rotation length, the rotation width and the rotation angle; A matching frame generation module is used to screen the rotated anchor frames according to the standard angle of the training sample in the current iteration to obtain at least one anchor frame to be matched; A positive sample determination module, configured to determine a positive sample based on each of the anchor frames to be matched; A loss function determination module, configured to determine a loss function based on a given loss function expression, combined with the rotation box information and the standard box information of the positive sample; A target model generation module is used to perform backpropagation on the text detection model to be trained based on the loss function to obtain a text detection model to be trained for the next iteration until an iterative convergence condition is met to obtain a target text detection model; The matching box generation module includes: an angle difference determining unit, configured to determine an angle difference between a standard angle of a training sample and a rotation angle of each of the rotation anchor frames; an angle difference comparison unit, configured to compare the angle differences and determine a minimum angle difference; The matching frame generating unit is configured to determine each of the rotation anchor frames corresponding to the minimum angle difference as an anchor frame to be matched.
7. A computer device, characterized in that: The device comprises: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the text detection method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the text detection method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Scene text detection method for any angle
CN111553347A
OCR character recognition method based on deep learning
CN113688821A