Image processing method, device, equipment and computer readable storage medium
By performing text area recognition, recursive segmentation and image transformation processing on irregular text, the problem of low accuracy and efficiency in correcting irregular text in the existing technology is solved, and accurate correction and recognition of large curvature and long text are achieved.
Patent Information
- Application Number
- CN202210172618.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-24
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-02-24
AI Technical Summary
When the existing technology handles irregular text, the single character detection method has low detection accuracy due to the small target; the network model method has poor correction effect due to the lack of explicit supervision loss, especially for the recognition and recognition of large arc bends and long text. Correction efficiency is low.
Through text area recognition of the image to be processed, the text connected domain is obtained, and recursive segmentation is performed to obtain the upper and lower boundary lines, which are divided into multiple text sub-images, each sub-image is subjected to image transformation processing, and finally spliced to form an accurate Correct text images.
It improves the accuracy and efficiency of correcting irregular text, can handle text of any length and large arc bends, does not require network training, and is highly flexible.
Smart Images

Figure CN114693717B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and relate to but are not limited to an image processing method, device, equipment, and computer-readable storage medium. Background Art
[0002] With the development of artificial intelligence technology in the fields of image processing and text recognition, the use of artificial intelligence technology for scene text recognition has become the mainstream method. However, for various scene texts, there are usually a large number of irregular texts with large arcs and large perspective changes, which greatly increases the difficulty of scene text recognition, which is already complex.
[0003] In the related art, when correcting and recognizing irregular text, one implementation method is to take each character in the text line as the smallest target unit granularity, perform character detection by a single character detection method, and then use a single character classification recognition algorithm to recognize the text; another implementation method is to perform the task of regressing the key points of irregular text through a network model, and correct the irregular text area based on the key point positions output by the network model.
[0004] However, the methods in the related art have low accuracy in single-character detection due to the small size of the single-character target in the image and when the foreground noise and background noise of the image are large; the correction and recognition methods using network models lack explicit supervision loss in the positioning network in the network model, and the correction effect depends on the recognition result. Therefore, the recognition and correction effects of large-arc curved and long curved texts are poor and the efficiency is low. Therefore, the methods in the related art all have the problem of low accuracy and correction efficiency of text detection and recognition. Summary of the invention
[0005] The embodiments of the present application provide an image processing method, apparatus, device and computer-readable storage medium, which are at least applied to the field of artificial intelligence technology, can obtain an accurately corrected spliced text image, achieve accurate correction processing of the text image of the target text in the image to be processed, and can improve the efficiency of text correction.
[0006] The technical solution of the embodiment of the present application is implemented as follows:
[0007] The present application provides an image processing method, the method comprising:
[0008] Performing text region recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed;
[0009] Recursively segmenting the text connected domain to obtain an upper boundary line and a lower boundary line of the text connected domain;
[0010] Based on the distance between the upper boundary line and the lower boundary line, dividing the text image corresponding to the target text to form a plurality of text sub-images;
[0011] Performing image transformation processing on each of the text sub-images to obtain a transformed text sub-image;
[0012] The transformed text sub-images are spliced to form a spliced text image.
[0013] The present application provides an image processing device, the device comprising:
[0014] A recognition module, used for performing text region recognition on the image to be processed, and obtaining a text connected domain corresponding to the target text in the image to be processed;
[0015] A recursive segmentation processing module, used for performing recursive segmentation processing on the text connected domain to obtain an upper boundary line and a lower boundary line of the text connected domain;
[0016] A division module, used for dividing the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images;
[0017] A transformation processing module, used for performing image transformation processing on each of the text sub-images to obtain a transformed text sub-image;
[0018] The splicing module is used to splice the transformed text sub-images to form a spliced text image.
[0019] The present application provides an image processing device, including:
[0020] The memory is used to store executable instructions; the processor is used to implement the above-mentioned image processing method when executing the executable instructions stored in the memory.
[0021] An embodiment of the present application provides a computer program product or a computer program, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; wherein a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor is used to execute the computer instructions to implement the above-mentioned image processing method.
[0022] An embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute the executable instructions to implement the above-mentioned image processing method.
[0023] The embodiments of the present application have the following beneficial effects: an upper boundary line and a lower boundary line are obtained by recursively segmenting the connected domain of the text, and then the text image of the target text is divided based on the spacing between the upper boundary line and the lower boundary line to obtain multiple text sub-images, and then each text sub-image is subjected to image transformation processing, so that an accurately corrected spliced text image can be obtained according to the transformed text sub-image, thereby achieving accurate correction processing of the text image of the target text in the image to be processed, and since the image transformation processing can be performed on multiple text sub-images in parallel, the efficiency of text correction can be greatly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1A and Figure 1B is a schematic diagram of irregular text provided in an embodiment of the present application;
[0025] Figure 2 is an optional architecture diagram of an image processing system provided in an embodiment of the present application;
[0026] Figure 3 is a structural schematic diagram of an image processing device provided in an embodiment of the present application;
[0027] Figure 4 It is an optional flowchart of the image processing method provided in the embodiment of the present application;
[0028] Figure 5 is another optional flowchart of the image processing method provided in the embodiment of the present application;
[0029] Figure 6 This is another optional flowchart of the image processing method provided in the embodiment of the present application;
[0030] Figure 7 This is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0031] Figure 8 This is another application scenario schematic diagram provided by an embodiment of the present application;
[0032] 9A to 9C It is a display diagram of the correction effect of the image processing method provided in the embodiment of the present application on different pictures;
[0033] Fig.10 It is a flowchart of the text correction method of the embodiment of the present application;
[0034] Fig.11 is a schematic diagram of a process for determining an upper boundary line and a lower boundary line provided in an embodiment of the present application;
[0035] Fig.12 is a schematic diagram of a process for obtaining upper and lower boundary lines of an irregular text provided in an embodiment of the present application;
[0036] Fig.13 Respectively represent the length of the cut line when performing the equal division operation for the first time and the second time;
[0037] Fig.14 are the upper and lower boundary lines of the irregular text obtained in the text boundary contour obtaining step of the embodiment of the present application;
[0038] Fig.15 is a schematic diagram of obtaining sampling points provided in an embodiment of the present application;
[0039] Fig.16 It is a schematic diagram of the segmented parallel TPS transformation processing provided by an embodiment of the present application;
[0040] Fig.17A and 17B It is a schematic diagram of the text correction result provided in the embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0042] In the following description, "some embodiments" are referred to, which describe a subset of all possible embodiments, but it is understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meaning as those commonly understood by technicians in the technical field of the embodiments of the present application. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0043] Before describing the solution of the embodiment of the present application, the terms involved in the embodiment of the present application are first explained:
[0044] (1) Optical Character Recognition (OCR): refers to the process of scanning text materials and then analyzing and processing image files to obtain text and layout information.
[0045] (2) Thin Plate Spline (TPS): Thin Plate Spline is a type of interpolation method and is a commonly used 2D interpolation method. Thin Plate Spline assumes that there are N points An in the original shape. These N points correspond to N new points Bn under the new coordinates after deformation. The deformation of a thin steel plate is used to simulate the 2D deformation to ensure that these N points can be correctly matched. Among them, TPS interpolation is a numerical solution to explain what kind of deformation can minimize the bending energy of the steel plate.
[0046] (3) Connected domain: a connected component, which generally refers to an image region consisting of foreground pixels with the same pixel value and adjacent positions.
[0047] (4) Irregular text: usually refers to curved text, text with uncertain direction, widely varying font sizes, and irregular arrangement.
[0048] Before explaining the image processing method of the embodiment of the present application, the method in the related art is first described.
[0049] In the related technology, when correcting and recognizing irregular text, the first implementation method is irregular text recognition technology based on single-word detection. In the text detection part, this technology regards each character in the text line as the smallest target unit granularity, and performs character detection through the single-character detection method, and then uses the single-character classification recognition algorithm to recognize the text, and finally merges the character recognition results belonging to the same text line through the post-processing strategy to obtain a complete result.
[0050] However, compared with the method of detecting the entire text line, the task of locating and detecting a single character is that the character is smaller than the entire text line in the image. Therefore, when the foreground noise and background noise are large, the character detection effect will not be very good; and the model-based character detection method requires additional character annotation, which increases the annotation cost; this scheme makes the recognition algorithm lose the ability to model sequences; after obtaining the single character recognition result, it is necessary to group the characters belonging to the same text line together in order based on certain rule strategies. This post-processing step is usually not robust in complex scenes, especially for curved irregular text.
[0051] When correcting and recognizing irregular text, the second implementation method is a text correction and recognition method based on a key point positioning network model. This method uses a network model to perform the regression task of the key points of irregular text, and corrects the irregular text area based on the key point positions output by the network. The positioning network and the recognition network are learned end-to-end in one model and trained through recognition annotations.
[0052] However, since the text correction network and the recognition network are bound together, the recognition model needs to be retrained, which is not flexible enough and cannot be used out of the box. At the same time, the positioning network lacks explicit supervision loss, and the correction effect depends on the recognition result. The recognition and correction effects are poor for large-arc and very long curved texts.
[0053] In summary, in the related technologies, the irregular Chinese and English characters existing in various scenarios are only effective on horizontal and vertical regular texts, while there are few studies on the correction and recognition of irregular texts, and the results and robustness achieved are also limited. The few correction and recognition technologies for irregular texts are integrated with the recognition network in one model. Although they can be optimized end-to-end, they rely on model training and require a large amount of irregular text data for training. In addition, they have limited effects, lack flexibility, and cannot be used out of the box.
[0054] Based on the above methods in the related art and the above problems, an embodiment of the present application provides an image processing method, which proposes a fast and high-precision irregular text correction and recognition method to solve the problem of poor irregular text correction and recognition effects. From a practical point of view, the irregular text correction module in the embodiment of the present application for irregular text scenes can be directly embedded in the middle of the text detection and recognition module, and the detected irregular text lines are corrected and stretched to obtain regular entries, which are then provided to the sequence recognition model for accurate text recognition. The embodiment of the present application can solve the correction problem of irregular text with large curvature and large degree of perspective transformation, and can process text of any length with extremely low time consumption.
[0055] It should be noted that in the embodiments of the present application, irregular text is relative to regular text. Regular text refers to text with multiple characters arranged completely horizontally or completely vertically; irregular text with a large curvature refers to text with a preset curvature formed by multiple characters, where the angle of the preset curvature is greater than or equal to the angle threshold. Irregular text with a large degree of perspective transformation refers to text with all or part of the characters having a perspective effect, or the degree of perspective of the characters is greater than the perspective threshold.
[0056] Figure 1A and Figure 1B is a schematic diagram of irregular text provided in the embodiment of the present application, such as Figure 1A and Figure 1BAs shown, the image to be processed 11 includes irregular text 111 with a large curvature, and the image to be processed 12 includes irregular text 121 with a large curvature. The method of the embodiment of the present application is used to process the text images corresponding to the irregular text 111 and the irregular text 121, and finally obtain a corrected regular text image, that is, obtain the final spliced text image, so as to perform text recognition based on the regular text image, accurately recognize the text content corresponding to the irregular text, and further improve the efficiency and accuracy of text recognition.
[0057] The image processing method of the embodiment of the present application can solve the following problems: it can be directly embedded between the text detection and recognition modules, and compared with the network model-based method, it does not require network training and is decoupled from the recognition module, solving the problem of the need to train the model and the inflexibility of the image processing process. It can also solve the problem of irregular text correction with large curvature and large perspective transformation; it can process irregular text of any length in any language type.
[0058] In the image processing method provided by the embodiment of the present application, first, the text area recognition is performed on the image to be processed to obtain the text connected domain corresponding to the target text in the image to be processed; then, the text connected domain is recursively segmented to obtain the upper boundary line and the lower boundary line of the text connected domain; based on the spacing between the upper boundary line and the lower boundary line, the text image corresponding to the target text is divided to form a plurality of text sub-images; then, each text sub-image is image transformed to obtain a transformed text sub-image; finally, the transformed text sub-images are spliced to form a spliced text image. In this way, since the upper boundary line and the lower boundary line are obtained by recursively segmenting the text connected domain, and the text image of the target text is divided based on the upper boundary line and the lower boundary line to obtain a plurality of text sub-images, each text sub-image can be image transformed in parallel, thereby greatly improving the efficiency of text correction; and, according to the transformed text sub-image, an accurately corrected spliced text image can be obtained, so that the text image of the target text in the image to be processed can be accurately corrected.
[0059] The following describes an exemplary application of the image processing device of the embodiment of the present application. The image processing device provided by the embodiment of the present application can be implemented as a terminal or a server. In one implementation, the image processing device provided by the embodiment of the present application can be implemented as a laptop, a tablet computer, a desktop computer, a mobile device (e.g., a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable gaming device), an intelligent robot, an intelligent home appliance, and a vehicle-mounted terminal, etc., any terminal with image display function, image recognition function, and text processing function; in another implementation, the image processing device provided by the embodiment of the present application can also be implemented as a server, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (CDN, Content Delivery Network), and big data and artificial intelligence platforms. The terminal and the server can be directly or indirectly connected by wired or wireless communication, which is not limited in the embodiment of the present application. Below, an exemplary application of the image processing device when it is implemented as a server will be described.
[0060] See also Figure 2 , Figure 2It is an optional architecture diagram of the image processing system 10 provided in the embodiment of the present application. In order to support an image processing application and correct and recognize irregular text in the image to be processed through the image processing application, in the embodiment of the present application, the image processing system 10 includes at least a terminal 100, a network 200 and a server 300, wherein the server 300 constitutes the image processing device of the embodiment of the present application. The terminal 100 is connected to the server 300 through the network 200, and the network 200 can be a wide area network or a local area network, or a combination of the two. At least one image processing application is installed on the terminal 100, and the image processing application can be any application with an image display function. The server 300 can obtain the image to be processed sent by the terminal 100 through the network 200; and perform text area recognition on the image to be processed, and obtain a text connected domain corresponding to the target text in the image to be processed; wherein the target text can be an irregular text. In addition, the server also recursively segments the text connected domain to obtain the upper boundary line and the lower boundary line of the text connected domain; divides the text image corresponding to the target text based on the spacing between the upper boundary line and the lower boundary line to form a plurality of text sub-images; and performs image transformation processing on each text sub-image to obtain a transformed text sub-image; and splices the transformed text sub-images to form a spliced text image. After obtaining the spliced text image, the server 300 can perform text recognition based on the obtained spliced text image to obtain the text content corresponding to the irregular text, or send the spliced text image to the terminal 100 through the network 200, and the terminal performs text recognition on the spliced text image to obtain the text content corresponding to the irregular text, or display the spliced text image on the terminal to analyze the accuracy of this image processing process.
[0061] In some embodiments, when the image processing device is implemented as a terminal, the terminal can obtain the image to be processed displayed on the current interface, or the terminal can receive an image processing request, which includes the image to be processed, and further use the image processing method provided in the embodiment of the present application to correct the image to be processed to obtain a spliced text image. In addition, after obtaining the spliced text image, the terminal can also perform text recognition on the spliced text image to obtain the text content corresponding to the irregular text, and output the text content.
[0062] The image processing method provided in the embodiment of the present application can also be implemented based on a cloud platform and through cloud technology. For example, the above-mentioned server 300 can be a cloud server, and the image to be processed is identified by the cloud server, or the text connected domain is recursively segmented by the cloud server, or the text image corresponding to the target text is divided by the cloud server to form a plurality of text sub-images, or each text sub-image is subjected to image transformation processing by the cloud server, or the transformed text sub-images are spliced by the cloud server. In some embodiments, a cloud storage can also be provided, and the spliced text image can be stored in the cloud storage, or the image to be processed and the spliced text image can be mapped and stored in the cloud storage. In this way, when the image to be processed is subsequently subjected to text recognition, the spliced text image corresponding to the image to be processed can be directly obtained from the cloud storage, and text recognition can be performed based on the spliced text image to obtain the text content of the irregular text corresponding to the image to be processed, so as to realize rapid and accurate recognition of the image to be processed.
[0063] It should be noted here that cloud technology refers to a hosting technology that unifies hardware, software, network and other resources in a wide area network or local area network to achieve data calculation, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark, and all need to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system backing support, which can only be achieved through cloud computing.
[0064] Figure 3 is a schematic diagram of the structure of an image processing device provided in an embodiment of the present application, Figure 3 The image processing device shown includes: at least one processor 310, a memory 350, at least one network interface 320 and a user interface 330. The various components in the image processing device are coupled together via a bus system 340. It is understood that the bus system 340 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 340 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 340 is not described in detail. Figure 3 Various buses are labeled as bus system 340 .
[0065] The processor 310 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0066] The user interface 330 includes one or more output devices 331 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 330 also includes one or more input devices 332, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0067] The memory 350 may be removable, non-removable or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drive, optical disk drive, etc. The memory 350 may optionally include one or more storage devices physically away from the processor 310. The memory 350 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 350 described in the embodiment of the present application is intended to include any suitable type of memory. In some embodiments, the memory 350 can store data to support various operations, and examples of these data include programs, modules, and data structures or subsets or supersets thereof, as exemplified below.
[0068] Operating system 351, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0069] A network communication module 352, used to reach other computing devices via one or more (wired or wireless) network interfaces 320, exemplary network interfaces 320 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0070] The input processing module 353 is used to detect one or more user inputs or interactions from one of the one or more input devices 332 and translate the detected inputs or interactions.
[0071] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 3 An image processing device 354 stored in a memory 350 is shown. The image processing device 354 may be an image processing device in an image processing device, which may be software in the form of a program or a plug-in, and includes the following software modules: a recognition module 3541, a recursive segmentation processing module 3542, a division module 3543, a transformation processing module 3544, and a splicing module 3545. These modules are logical, and therefore may be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0072] In other embodiments, the device provided in the embodiments of the present application can be implemented in hardware. As an example, the device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the image processing method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field programmable gate arrays (FPGAs) or other electronic components.
[0073] The image processing method provided in the embodiment of the present application will be described below in combination with the exemplary application and implementation of the image processing device provided in the embodiment of the present application, wherein the image processing device can be any terminal with image display function, image recognition function and text processing function, or it can also be a server, that is, the image processing method of the embodiment of the present application can be executed by the terminal, or it can be executed by the server, or it can also be executed by the interaction between the terminal and the server.
[0074] See also Figure 4 , Figure 4 This is an optional flow chart of the image processing method provided in the embodiment of the present application. Figure 4 The steps shown are explained, and it should be noted that Figure 4 The image processing method in the present invention is realized by using the server as the execution subject.
[0075] Step S401 , performing text region recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed.
[0076] Here, the image to be processed may be an image with text information, wherein the text information on the image to be processed includes irregular text and regular text. Irregular text refers to text with a certain degree of text direction curvature or a certain degree of perspective. For example, irregular text may be curved text, text with uncertain direction, widely different font sizes, irregular arrangement, etc.; regular text refers to text with text arranged horizontally or vertically.
[0077] Text area recognition refers to identifying the area where the target text is located. In the embodiment of the present application, it can be implemented by the grayscale binary method in the image processing technology, or it can be extracted by a method based on a deep neural network, such as Mask-RCNN, PixelLink and other detection methods to extract the foreground connected domain of the text (i.e., the text connected domain). Among them, in the grayscale binary method, the grayscale value of each pixel in the pixel matrix of the image can be 0 (black) or 1 (white), that is, the entire image is presented with only black and white effects. The range of grayscale values in the grayscale image is 0 to 255, and the range of grayscale values in the binarized image is 0 or 1. When the grayscale value of any pixel is 1, it indicates that the pixel is a pixel in the text connected domain, and when the grayscale value of any pixel is 0, it indicates that the pixel is not a pixel in the text connected domain.
[0078] In the embodiment of the present application, the text connected domain can be understood as the area where the text is located. The text connected domain is the area after binarization, that is, the text connected domain is the area where the foreground pixels are located.
[0079] Since we know the text connected domain, we know the complete outline of the text, but we don’t know which part of the outline is the upper boundary and which part is the lower boundary, because when we get the text connected domain, we can only get a complete outline, but in the image processing method of the embodiment of the present application, we need to split the complete outline into the upper boundary and the lower boundary, so we need to recursively segment the text connected domain through subsequent steps. In the embodiment of the present application, the outline of the text connected domain can be understood as a closed curve of any shape, but which part of this curve, that is, which points belong to the upper boundary and which points belong to the lower boundary is unknown.
[0080] Step S402: recursively segment the text connected domain to obtain the upper boundary line and the lower boundary line of the text connected domain.
[0081] Here, recursive segmentation processing refers to performing multiple segmentation processing on the text connected domain corresponding to the target text. The recursive segmentation processing can be based on the circumscribed polygon corresponding to the text connected domain. The circumscribed polygon has at least one side that is tangent to the contour line of the text connected domain. The area of the circumscribed polygon is greater than or equal to the area of the text connected domain.
[0082] In the recursive segmentation process, the circumscribed polygon of the current connected domain to be segmented needs to be determined before each segmentation process. That is to say, in the first segmentation process, the text connected domain corresponding to the target text in the image to be processed is segmented. From the second to the last segmentation process, the connected domain after the previous segmentation process is re-segmented.
[0083] For example, during the Nth segmentation process, the connected domain obtained after the N-1th segmentation process is obtained, and then the circumscribed polygon of the connected domain is determined, and the connected domain is segmented based on the determined circumscribed polygon, where N is an integer greater than 1.
[0084] In each segmentation process, a pair of segmentation points and the coordinates of the segmentation point pairs are obtained, wherein the segmentation point pairs include at least two segmentation points, and the segmentation points are points on the contour line of the text connected domain corresponding to the target text. After completing the recursive segmentation process, two polygons at the two ends of the contour line of the text connected domain are finally obtained. In the embodiment of the present application, the upper boundary line and the lower boundary line of the text connected domain can be determined based on the two polygons finally obtained and the coordinates of the segmentation point pairs obtained in each segmentation process.
[0085] Step S403 : dividing the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images.
[0086] Here, when the upper boundary line is parallel to the lower boundary line, the spacing between the upper boundary line and the lower boundary line may be the distance between the upper boundary line and the lower boundary line; when the upper boundary line and the lower boundary line are not parallel, or when part of the upper boundary line and the lower boundary line are parallel and part of them are not parallel, the spacing between the upper boundary line and the lower boundary line may be the average value of the distances between multiple corresponding point pairs on the upper boundary line and the lower boundary line.
[0087] In an embodiment of the present application, the sampling spacing of the text image can be determined according to the spacing between the upper boundary line and the lower boundary line, and the text image is sampled based on the sampling spacing to obtain multiple sampling point pairs, and then the text image is divided based on the sampling point pairs to form multiple text sub-images.
[0088] Step S404: performing image transformation processing on each text sub-image to obtain a transformed text sub-image.
[0089] Here, the image transformation process is used to correct the text sub-image so that the transformed text sub-image is easier to identify. The image transformation process can be any image correction process, such as horizontal stretching, vertical stretching, reverse bending, reverse distortion, local deformation, overall deformation, etc. In the embodiment of the present application, the TPS transformation process can be used to correct and stretch the text sub-image.
[0090] In the embodiment of the present application, each text sub-image has an irregularity, and the irregularity is used to characterize the degree of deformation or perspective of the irregular text in the corresponding text sub-image relative to the same regular text in the regular image. The higher the irregularity, the greater the degree of deformation or perspective of the corresponding text sub-image, the greater the difficulty of text recognition for the text sub-image, and the lower the recognition accuracy; the lower the irregularity, the smaller the degree of deformation or perspective of the corresponding text sub-image, the closer the text sub-image is to the regular image, the smaller the difficulty of text recognition for the text sub-image, and the higher the recognition accuracy.
[0091] The irregularities of multiple text sub-images in the same text image may be the same or different. Therefore, when performing image transformation processing, the degree of transformation processing may be the same or different. The degree of transformation processing is determined based on the irregularity of the text sub-image. The higher the irregularity of the text sub-image, the higher the degree of transformation processing; the lower the irregularity of the text sub-image, the lower the degree of transformation processing.
[0092] Step S405 , splicing the transformed text sub-images to form a spliced text image.
[0093] In the embodiment of the present application, the transformed text sub-images may be spliced in sequence according to the order of the character sub-images in the text image to form a spliced text image.
[0094] The image processing method provided in the embodiment of the present application obtains an upper boundary line and a lower boundary line by recursively segmenting the text connected domain, thereby dividing the text image of the target text based on the spacing between the upper boundary line and the lower boundary line to obtain multiple text sub-images, and then performing image transformation processing on each text sub-image, so that an accurately corrected spliced text image can be obtained based on the transformed text sub-image, thereby achieving accurate correction processing of the text image of the target text in the image to be processed, and since the image transformation processing can be performed on multiple text sub-images in parallel, the efficiency of text correction can be greatly improved.
[0095] In some embodiments, the image processing system includes at least a terminal and a server, wherein the terminal is used to collect images to be processed, and the server is used to perform image processing on the images to be processed. Figure 5 is another optional flow chart of the image processing method provided in the embodiment of the present application, such as Figure 5 As shown, the method comprises the following steps:
[0096] Step S501: The terminal collects an image to be processed.
[0097] In the embodiment of the present application, the terminal may be provided with an image acquisition device, which acquires the image to be processed in real time through the image acquisition device, and processes the image to be processed acquired in real time through the server to obtain the final spliced text image. Alternatively, the terminal may acquire the image to be processed by downloading the image to be processed from the network through an image browsing or image downloading client on the terminal, or the terminal may acquire the image to be processed by receiving pictures sent by other users through an instant messaging application on the terminal to obtain the image to be processed.
[0098] Step S502: the terminal generates an image processing request based on the image to be processed.
[0099] The terminal may be installed with an image processing application, and the user may operate on the client of the image processing application to trigger the generation of an image processing request. For example, the image to be processed may be selected on the client and an image processing button may be selected, so that the terminal generates an image processing request based on the image to be processed selected by the user.
[0100] In an embodiment of the present application, the image to be processed may be encapsulated into an image processing request, and the image processing request is used to request a server of an image processing application to perform correction processing on the image to be processed.
[0101] Step S503: the terminal sends an image processing request to the server.
[0102] Step S504: the server performs text region recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed.
[0103] In an embodiment of the present application, the server responds to an image processing request and parses the image processing request to obtain an image to be processed, and performs text area recognition on the image to be processed, wherein text area recognition refers to identifying the area where the target text is located. In an embodiment of the present application, the grayscale binary method in the image processing technology can be used to implement it, or the text area recognition of the image to be processed can be implemented by a method based on a deep neural network.
[0104] Step S505: the server determines the circumscribed polygon corresponding to the text connected domain.
[0105] Here, the circumscribed polygon refers to a polygon that is outside the text connected domain and completely surrounds the text connected domain. The circumscribed polygon has at least one side that is tangent to the outline of the text connected domain. The area of the circumscribed polygon is greater than or equal to the area of the text connected domain. When the area of the circumscribed polygon is equal to the area of the text connected domain, the outline of the text connected domain coincides with each side of the circumscribed polygon. When the circumscribed polygon is a circumscribed rectangle, if the area of the circumscribed polygon is equal to the area of the text connected domain, it indicates that the target text is a regular text.
[0106] Step S506: The server calculates the ratio between the area of the text connected domain and the area of the circumscribed polygon.
[0107] The ratio between the area of the text connected domain and the area of the circumscribed polygon is greater than 0 and less than or equal to 1.
[0108] Step S507, determining whether the ratio is less than a preset threshold.
[0109] Here, the preset threshold may be a manually preset value or an empirical value.
[0110] If the judgment result is yes, the target text is determined to be irregular text; if the judgment result is no, the target text is determined to be regular text. When the target text is regular text, the method of the embodiment of the present application is not used to correct the target text.
[0111] Step S508: When the target text is irregular text, the server uses a circumscribed polygon to recursively segment the text connected domain to obtain an upper boundary line and a lower boundary line of the text connected domain.
[0112] In some embodiments, the circumscribed polygon may be a circumscribed rectangle, and step S508 may be implemented by the following steps:
[0113] Step S5081: in each segmentation process of the recursive segmentation process, determine the bisector of the circumscribed rectangle corresponding to the current text connected domain.
[0114] It should be noted that, during the first segmentation process, the current text connected domain is the text connected domain corresponding to the target text; during the Nth (N is an integer greater than 1) segmentation process, the current text connected domain is the connected domain corresponding to a sub-contour obtained after the N-1th segmentation process.
[0115] Step S5082, determine the intersection of the bisector of the circumscribed rectangle and the text connected domain.
[0116] The bisector of the circumscribed rectangle is a line perpendicular to the long side of the circumscribed rectangle and bisects the long side of the circumscribed rectangle. There are two intersection points between the bisector of the circumscribed rectangle and the text connected domain. After the intersection points are determined, the coordinates of each intersection point can be determined.
[0117] Step S5083: Divide the text connected domain into two sub-contours based on the coordinates of the intersection points.
[0118] In the embodiment of the present application, a line between two intersection points may be used to divide the text connected domain into two sub-contours.
[0119] Step S5084: determine a sub-contour outside the text connected domain of the target text in the two sub-contours as the text connected domain for the next recursive segmentation process.
[0120] In the embodiment of the present application, when the recursive segmentation process has not ended, the above steps S5081 to S5084 can be looped until the end condition of the recursive segmentation process is reached.
[0121] Step S5085, when the aspect ratio of the circumscribed rectangle of the sub-contour obtained after any segmentation process is less than 1, stop the recursive segmentation process.
[0122] Here, the termination condition of the recursive segmentation process is that the aspect ratio of the circumscribed rectangle of the sub-contour obtained after the current segmentation process is less than 1.
[0123] Step S5086, determining the upper boundary line and the lower boundary line of the text connected domain of the target text according to the coordinates of the intersection points obtained in each segmentation process.
[0124] In some embodiments, two intersection points are obtained during each segmentation process; when determining the upper boundary line and the lower boundary line, the following steps can be performed:
[0125] Step S11, based on the two end point sub-contours obtained in the last segmentation process of the recursive segmentation process, the coordinates of the four endpoints of the text connected domain of the target text are determined.
[0126] In some embodiments, step S11 may be implemented by the following steps:
[0127] Step S111, obtaining four rectangular endpoints of the circumscribed rectangle of each end point sub-contour.
[0128] Since there are two end point sub-contours, the circumscribed rectangle of each end point sub-contour has four rectangle endpoints, so a total of eight rectangle endpoints are obtained.
[0129] Step S112, obtaining the intersection point between the bisecting line and the text connected domain in the last segmentation process.
[0130] Step S113, determining the distance between each rectangle endpoint and the intersection point.
[0131] In an embodiment of the present application, for the four rectangular endpoints of the circumscribed rectangle of each endpoint sub-contour, two of the rectangular endpoints coincide with the intersection point, so the distance between these two rectangular endpoints and the intersection point is 0; and the other two rectangular endpoints do not coincide with the intersection point, so the distance between these two rectangular endpoints and the intersection point is greater than 0.
[0132] Step S114, determining the coordinates of the two rectangular endpoints with the largest distance in the circumscribed rectangle of each endpoint subcontour as the endpoint coordinates of the text connected domain of the target text.
[0133] Here, the two rectangular endpoints with the largest distance in the circumscribed rectangle of each endpoint subcontour are the two rectangular endpoints that do not coincide with the intersection point.
[0134] Step S12, based on the coordinates of the four endpoints, the two intersection points obtained in each segmentation process are divided to form two groups of intersection points.
[0135] In an embodiment of the present application, the two intersection points obtained in each segmentation process are respectively divided into an intersection group, that is, the two intersection points obtained in each segmentation process are not in the same intersection group, and the two intersection points obtained in the segmentation process are respectively a point in the upper boundary line and a point in the lower boundary line.
[0136] Step S13, determining the upper boundary line and the lower boundary line of the text connected domain of the target text according to the coordinates of the intersection points in the two groups of intersection points respectively.
[0137] In an embodiment of the present application, after obtaining the coordinates of the four endpoints, the four endpoints of the upper boundary line and the lower boundary line can be known. Therefore, based on the coordinates of the intersection points in the two groups of intersection points, the four endpoints can be connected in sequence to form four curves, and the two curves that coincide with the intersection points in the two groups of intersection points can be respectively determined as the upper boundary line and the lower boundary line.
[0138] Step S509: the server divides the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images.
[0139] Step S510: the server performs image transformation processing on each text sub-image to obtain a transformed text sub-image.
[0140] Step S511: the server splices the transformed text sub-images to form a spliced text image.
[0141] Step S512: the server performs text recognition on the spliced text image to obtain the text content of the target text.
[0142] In the embodiment of the present application, the spliced text image is a text image that has been corrected, so compared with the image to be processed, the text recognition process is easier to perform and the recognition result is more accurate.
[0143] Step S513: the server sends the text content to the terminal.
[0144] The image processing method provided in the embodiment of the present application uses an external matrix to recursively segment the text connected domain, so that the upper boundary line and the lower boundary line of the text connected domain can be accurately obtained, and the text image corresponding to the target text is divided based on the upper boundary line and the lower boundary line to form multiple text sub-images, so that image transformation processing can be performed on multiple text sub-images in parallel, thereby improving the efficiency of the correction processing. Since the embodiment of the present application can accurately obtain the spliced text image after the correction processing, when it is necessary to perform text recognition on the irregular text in the image to be processed, text recognition can be performed based on the spliced text image, thereby improving the accuracy of text recognition.
[0145] Figure 6 is another optional flow chart of the image processing method provided in the embodiment of the present application, such as Figure 6 As shown, the method comprises the following steps:
[0146] Step S601: The terminal collects an image to be processed.
[0147] Step S602: the terminal generates an image processing request based on the image to be processed.
[0148] Step S603: the terminal sends an image processing request to the server.
[0149] Step S604: the server performs text region recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed.
[0150] Step S605: the server recursively segments the text connected domain using a circumscribed rectangle to obtain an upper boundary line and a lower boundary line of the text connected domain.
[0151] Step S606: the server obtains the length of the cutoff line between two intersection points of the bisector and the text connected domain in each segmentation process.
[0152] Here, the cut-off length refers to the length of the line segment between two intersection points of the bisector and the text connected domain during the segmentation process.
[0153] Step S607: The server determines the average value of all the cut lengths to obtain the average cut length.
[0154] Step S608: The server determines the average intercept length as the distance between the upper boundary line and the lower boundary line.
[0155] In the embodiment of the present application, by averaging the lengths of all the cut lines, it is possible to ensure that the text image can be accurately divided even when the font sizes of multiple characters in the irregular text are inconsistent, or when the predicted text connected domain is not a smooth extended curve. In other words, when the determined upper boundary line is not parallel to the lower boundary line, or when the upper boundary line is partially parallel to the lower boundary line and the other partially not parallel, the text image can also be accurately divided.
[0156] In some embodiments, when the font sizes of multiple characters in the irregular text are consistent and the predicted text connected domain is a smooth extended curve, at this time, the determined upper boundary line is parallel to the lower boundary line, and the length of the section between the two intersection points of the bisector and the text connected domain in each segmentation process is the same, then the average section length is equal to the length of the section between the two intersection points of the bisector and the text connected domain in each segmentation process.
[0157] Step S609: The server performs equidistant sampling on the upper boundary line and the lower boundary line based on the distance between the upper boundary line and the lower boundary line to obtain a plurality of sampling point pairs.
[0158] In some embodiments, step S609 may be implemented by the following steps:
[0159] Step S6091, determining a first length of the upper boundary line and a second length of the lower boundary line.
[0160] Step S6092, determining the number of sampling segments according to the first length, the second length and the spacing.
[0161] Step S6093, determining the length of the first equally divided interval of the upper boundary line according to the first length and the number of sampling segments.
[0162] Step S6094, determining the second equally divided interval length of the lower boundary line according to the second length and the number of sampling segments.
[0163] In an embodiment of the present application, the length of the first equally divided interval and the length of the second equally divided interval can be the same or different. When the first length of the upper boundary line and the second length of the lower boundary line are the same, the length of the first equally divided interval and the length of the second equally divided interval are the same; when the first length of the upper boundary line and the second length of the lower boundary line are different, the length of the first equally divided interval and the length of the second equally divided interval are different.
[0164] Step S6095, according to the first equally divided interval length and the second equally divided interval length, the coordinates of each sampling point on the upper boundary line and the lower boundary line are determined by the nearest neighbor interpolation method to obtain multiple sampling point pairs.
[0165] Here, the pixel points on the upper boundary line and the lower boundary line can be traversed in the order of the pixel points on the upper boundary line and the lower boundary line according to the first equal division interval length and the second equal division interval length, and the cumulative distance traversed by the traversed pixel points can be calculated.
[0166] For the pixel points on the upper boundary line, when traversing to any first target pixel point, if the cumulative distance corresponding to the first target pixel point is greater than the first product of the determined number of sampling points and the first equally divided interval length, and the cumulative distance corresponding to the previous pixel point of the first target pixel point is less than the first product, the coordinates of the current sampling point of the upper boundary line are determined by the nearest neighbor interpolation method.
[0167] For the pixel points on the lower boundary line, when traversing to any second target pixel point, if the cumulative distance corresponding to the second target pixel point is greater than the second product of the number of determined sampling points and the second equally divided interval length, and the cumulative distance corresponding to the previous pixel point of the second target pixel point is less than the second product, the coordinates of the current sampling point of the lower boundary line are determined by the nearest neighbor interpolation method. Finally, the current sampling point of the upper boundary line and the current sampling point of the lower boundary line are determined as a pair of sampling points.
[0168] Step S610: The server divides the text image corresponding to the target text based on a plurality of sampling point pairs to form a plurality of text sub-images.
[0169] Step S611: the server performs image transformation processing on each text sub-image to obtain a transformed text sub-image.
[0170] Step S612: the server splices the transformed text sub-images to form a spliced text image.
[0171] Step S613: the server performs text recognition on the spliced text image to obtain the text content of the target text.
[0172] Step S614: the server sends the text content to the terminal.
[0173] The image processing method provided in the embodiment of the present application accurately calculates the distance between the upper boundary line and the lower boundary line through a given algorithm, and accurately divides the text image corresponding to the target text based on the distance to form multiple text sub-images, and then performs parallel image transformation processing on the multiple text sub-images, thereby improving the efficiency of the correction processing of the processed image.
[0174] It should be noted that the image processing method provided in the embodiment of the present application can be used as an independent module to realize the correction of the target text, that is, the image processing method of the embodiment of the present application can be realized by an independent correction module without being bound to the text positioning network and the text recognition network. Therefore, any text positioning network can be used to locate the target text and determine the text connectivity domain of the target text; and any text recognition network can also be used for text recognition. That is, the text correction process can be completed as an independent unit. After the correction process is completed, a spliced text image is obtained, and any text recognition network can be used to perform text recognition on the spliced text image. In this way, both the text positioning network and the text recognition network can be trained independently of the correction module, and the correction result of the correction model can be used out of the box, making the text processing process for the image to be processed more flexible.
[0175] Below, an exemplary application of an embodiment of the present application in an actual application scenario will be described. An embodiment of the present application provides an image processing method, which can be directly embedded between a text detection module and a recognition module, does not require network model training and is decoupled from the recognition module, solving the problem of the need to train a model and lack of flexibility. In addition, the problem of irregular text correction with large curvature and large perspective transformation can be solved, and irregular text of any length in any type of language text scenario can be processed.
[0176] The image processing method provided in the embodiment of the present application can be applied to text recognition tools and systems in different scenarios. Figure 7 It is a schematic diagram of an application scenario provided by an embodiment of the present application. A user inputs a picture 701, and an OCR detection 703 is performed on the irregular text 702 in the picture 701 using the method of the embodiment of the present application. The position of the irregular text is framed, and then OCR recognition 704 is performed to identify each character in the picture 701, and a recognition result sequence 705 of the characters in the picture is obtained and output.
[0177] Figure 8 is another application scenario diagram provided by the embodiment of the present application, in which curved text detection, correction and recognition are supported, such as Figure 8 As shown, for an input image to be processed 801, the image is processed using the method provided in an embodiment of the present application, and then text recognition is performed to obtain the text content 802 of the curved text in the image to be processed.
[0178] 9A to 9C is a diagram showing the correction effect of the image processing method provided in the embodiment of the present application on different pictures, such as Fig. 9AAs shown, the English target text 901 "NORTHWESTERN" is irregular text with a large arc bend. After correction using the method of the embodiment of the present application, the corrected image 902 is obtained, and the corrected image 902 is horizontally arranged regular text; as Fig. 9B shown, the Chinese target text 903 "Quickly repay the credit card" is irregular text with a large arc bend and a large degree of perspective. After correction using the method of the embodiment of the present application, the corrected image 904 is obtained, and the corrected image 904 is horizontally arranged regular text; as Fig. 9C shown, the Chinese target text 905 "Appreciate the德云大戏鉴领誉精品" is irregular text with a large arc bend. After correction using the method of the embodiment of the present application, the corrected image 906 is obtained, and the corrected image 906 is horizontally arranged regular text.
[0179] Text correction technology is the key to identifying irregular text. The role of text correction technology is to correct the irregular text output by the text detection module, and transform the curved and deformed irregular text into regular horizontal or vertical text. The method proposed in the embodiment of the present application is applicable to text with large arc bends and large degree of perspective transformation, and can process text of any length. The method of the embodiment of the present application generally adopts the process of generating text key control points plus TPS transformation interpolation, searches for text key control points through image processing methods, and improves the thin strip sample interpolation transformation algorithm for long text scenarios. The embodiment of the present application can be applied to scenarios with the need for identifying irregular text, such as advertising art word recognition, document seal recognition, street view billboard recognition, network picture art word recognition, etc.
[0180] The text correction method (i.e., image processing method) of the embodiment of the present application will be described below.
[0181] Fig.10 is a schematic flowchart of the text correction method of the embodiment of the present application, as Fig.10As shown, the text correction method can be divided into three core steps, namely, the text boundary contour acquisition step S1001, the boundary key control point generation step S1002 and the multi-segment parallel TPS interpolation step S1003. First, the contour and the minimum circumscribed rectangle of the text foreground connected domain (i.e., the text connected domain) 1001 of the image to be processed 1000 output by the text detection module are obtained, and the minimum circumscribed rectangle is recursively divided equally to both ends to locate the four endpoints and divide the upper and lower boundary lines. Then, the two determined boundary lines are sampled at equal distances by the key control point generation module 1002, and the sampling point positions are obtained by the nearest neighbor interpolation method. Finally, the TPS transformation module 1003 is used to process multiple groups of control points in parallel by the TPS interpolation method, and finally the processed sub-images are spliced together in sequence to form a corrected text image 1004 (corresponding to the above-mentioned spliced text image).
[0182] The text boundary contour acquisition step S1001, the boundary key control point generation step S1002 and the multi-segment parallel TPS interpolation step S1003 are described below respectively.
[0183] In the text boundary contour acquisition step, based on the text connected domain obtained by the text detection module, two separated text boundary lines (i.e., the upper boundary line and the lower boundary line) of the irregular text are generated. For example, the text connected domain can be extracted by the Mask branch prediction result output by the instance segmentation algorithm Mask-RCNN.
[0184] It should be noted here that the text connected domain is the pixel area after binarization, that is, the area where the foreground pixel is located. Since the text connected domain is known, only the complete outline of the text is known, but it is unknown which part of the outline is the upper boundary and which part is the lower boundary, because only a complete outline can be obtained, but it must be split into the upper boundary and the lower boundary. Therefore, it is necessary to further determine the upper boundary and the lower boundary of the text connected domain.
[0185] In the embodiment of the present application, the algorithm idea used to determine the upper boundary line and the lower boundary line is to recursively divide the contour points of the text connected domain toward both sides by equally dividing the circumscribed rectangle to approximate the two ends to obtain the four outermost vertices of the text, and at the same time determine the starting point and the end point of the upper and lower boundary lines, and divide the complete text contour into two to obtain the upper and lower boundary lines. Fig.11 , is a schematic diagram of a flow chart for determining an upper boundary line and a lower boundary line provided in an embodiment of the present application, and the specific steps are as follows:
[0186] Step S101, determine whether the entry (i.e., the target text) in the image to be processed is an irregular text. Here, the area of the connected domain can be denoted as S c, the area of the circumscribed rectangle is S r , calculate the area ratio r=S between the text connected domain 1101 and the circumscribed rectangle 1102 c / S r , if r is less than the threshold t, it is determined to be an irregular text entry and the subsequent correction steps are performed.
[0187] Step S102, by using the bisector l1 of the long side of the minimum circumscribed rectangle calculated in step S101, calculate the intersection point between l1 and the contour C of the text connected domain, and divide the contour C into sub-contour C1 and sub-contour C2. The contour segmentation can adopt the idea of polygon intersection based on the Sutherland–Hodgman algorithm, and use the bisector or circumscribed rectangle to intersect with the contour of the text to obtain the sub-contour divided into two parts.
[0188] Step S103: Repeat step S102 for the newly obtained sub-contours C1 and C2, respectively, to obtain the minimum bounding rectangle and to obtain the bisector l2 of the long side by bisecting the bounding rectangle along the long side. At this time, only the text contour close to the outside is retained. Repeat this process until the aspect ratio of the rotated bounding rectangle is less than 1. At this time, the minimum bounding rectangle R at the outermost ends of the entire entry is retained. left and R right .
[0189] Step S104: circumscribe the rectangular frames R at both ends. left and R right The four coordinate points of each are recorded as the four outermost endpoints of the entire irregular text contour according to the distance to the final bisector intersection.
[0190] Step S105, dividing all contour points into two groups based on the four outer endpoints, and obtaining two orderly upper and lower separation boundary lines.
[0191] Here, when dividing, since the 4 outermost endpoints are already known and the entire complete contour is known, then, knowing the 4 outermost endpoints, we can divide the entire text connected domain into 4 segments based on the 4 outermost endpoints. At the same time, since the order between the 4 outermost endpoints is known, the upper boundary line is the segment between the upper left endpoint and the upper right endpoint, and the lower boundary line is the segment between the lower left endpoint and the lower right endpoint. Fig.12 is a schematic diagram of the process of obtaining the upper and lower boundary lines of the irregular text provided in the embodiment of the present application, such as Fig.12 As shown, according to the external rectangular box R left and R right, four outermost endpoints 121 , 122 , 123 , and 124 may be determined, and then, an upper boundary line 125 and a lower boundary line 126 are obtained based on the four outermost endpoints 121 , 122 , 123 , and 124 .
[0192] In the step of generating boundary key control points, the upper and lower boundary lines of the target text are sampled at equal intervals, and the generated points are recorded as key control points of irregular text. The sampling process is to divide the contours of the upper and lower boundary lines of the target text equally with the height h as the interval length, and the sampling points use the nearest neighbor interpolation method. In the implementation process, the following steps can be used:
[0193] Step S201, while recursively dividing the minimum circumscribed rectangle in both sides in steps S102 and S103, record the length h of the intercept between the dividing line and the contour each time i Finally, the distance h between the upper and lower boundaries of the irregular text contour is approximated by taking the average value, that is, the upper and lower boundary distances can be determined by the following formula (1):
[0194]
[0195] Here, n means that the operation of equally dividing the minimum circumscribed rectangle is performed n times.
[0196] Fig.13 The solid line 131 is the outline of the text connected domain of the irregular text, the solid line 132 is the minimum circumscribed rectangle of the text connected domain of the irregular text, the solid line 133 is the dividing line for each equal division operation (i.e., the dividing line l), and the thick solid line 134 is the length of the cut-off line h between the dividing line of the circumscribed rectangle of the equal division operation and the outline of the text connected domain. i .
[0197] Step S202, calculating the curve length len1 of the upper boundary line and the curve length len2 of the lower boundary line of the irregular text.
[0198] Step S203, calculate the number of equally divided segments N that need to be sampled. Fig.14 As shown in the figure, the upper and lower boundary lines of the irregular text obtained in the text boundary contour acquisition step, and the estimated equal division length of the sampling point is set to h. The equal division length of the sampling point is set to the distance h between the upper and lower boundary lines because most Chinese characters are of equal width and height, and bending often occurs between characters. Segmentation and correction operations based on character granularity achieve the best results. Therefore, the number of equal divisions N of the sampling can be calculated by the following formula (2):
[0199]
[0200] Where: k is the lower limit, for example, it can be set to 10, that is, at least 10 segments are sampled; It represents the number of segments calculated with h as the equal division length, rounded down.
[0201] Step S204, the upper and lower boundary lines of the irregular text are uniformly sampled at equal distances, and the coordinates of the sampling points are calculated by the nearest neighbor interpolation method. The specific sampling process is as follows:
[0202] 1) Calculate the lengths of the equally divided intervals d1 and d2 required for sampling respectively through the curve lengths len1 and len2 of the upper and lower boundary lines and the number of sampling segments N, that is:
[0203] 2) Traverse the points p on the upper and lower boundary contours in order respectively i (i=1,2,3…) and calculate the cumulative distance and D i , when traversing to point p n If condition D is met n >K*d and D n-1 <K*d, K∈(1,N), K is the number of determined sampling points, and the coordinates of the current Kth sampling point are calculated by the nearest neighbor interpolation method.
[0204] The nearest neighbor interpolation method refers to finding the nearest integer point after matching the points in the target image to the original image as the interpolated output. The purpose of interpolation is to obtain the pixel value of the unknown target image based on the pixel value of the known image, that is, to assign the gray value of the nearest pixel of the original pixel in the transformed image to the original pixel. The nearest neighbor interpolation algorithm formula (3) is as follows:
[0205]
[0206] Among them, src_x and src_y represent the x and y coordinates of the original image respectively; dst_x and dst_y represent the x and y coordinates of the target image respectively; src_width and src_height represent the width and height of the original image respectively; dst_width and dst_height represent the width and height of the target image respectively.
[0207] Because the sampling points are obtained by sampling the original image size, the width and height of the target image are consistent with those of the original image. For floating point coordinates, the nearest neighbor interpolation sampling is performed by rounding. Fig.15, which is a schematic diagram of obtaining sampling points provided in an embodiment of the present application. After obtaining sampling points for the upper and lower boundary lines 151, multiple sampling points 152 are obtained and mapped to the image to be processed, namely, sampling points 153.
[0208] In the multi-segment parallel TPS interpolation step, the TPS interpolation algorithm is used for segment correction. Here, the target text can be divided into N segments, and TPS processing is performed in parallel. Then, the transformed results of the N segments are spliced as the final complete result. This segment processing strategy enables the algorithm to achieve a good stretching effect even when the text is very long or has a large curvature. Specifically, the following steps are included:
[0209] Step S301 , according to the number of sampling segments N, the adjacent sampling points of the two boundary lines can be divided into N groups of ordered point pairs, each group of upper and lower boundary lines each consisting of two adjacent points, corresponding to N sections of text image areas.
[0210] Step S302, the N text image regions are processed by TPS transformation respectively. This operation can be performed in parallel to correct and stretch the irregular text. Fig.16 As shown, it is a schematic diagram of the segmented parallel TPS transformation processing provided in an embodiment of the present application, in which multiple text image regions 161 after the original image to be processed is segmented and fitted, and then TPS transformation processing is performed in parallel and then spliced to obtain a spliced text image 162.
[0211] Step S303, stitching the N segments of the corrected and stretched output results in order to form a complete text image, that is, the regular text line image after the stretching operation (that is, the stitched text image). Fig.17A and 17B shown.
[0212] Since the defect of TPS transformation is that it has poor effect on curved text with large curvature and long length, the method adopted in the embodiment of the present application is to first divide the text area into image segments with small curvature and length, and then perform TPS transformation in parallel, and then splice the transformed results. This improved algorithm can effectively avoid the defect of TPS transformation, achieve a good correction and stretching effect, and improve the results of subsequent text recognition.
[0213] The image processing method provided in the embodiment of the present application is a new method for correcting irregular curved text, which is suitable for scenes with large curvatures and large perspective transformations. The method is plug-and-play, and can achieve good results for irregular texts in Chinese and English scenes, with a wider range of applicable scenes and high speed. Since the irregular text has been corrected by the method of the embodiment of the present application, the text recognition model based on the sequence recognition method can be directly used to recognize the corrected text entries and obtain better recognition results, without the need to collect a large amount of irregular text annotation data and retrain the recognition model.
[0214] It should be noted that the method of initially obtaining the text connected domain in the method of the embodiment of the present application can be implemented by a grayscale binary method of image processing, or by a method based on a deep neural network, such as Mask-RCNN, PixelLink and other detection methods to extract the text foreground connected domain. In addition, the step of using a bisector to segment the text contour can not only use the Sutherland-Hodgman algorithm, but also other polygon cutting algorithm ideas, such as the Vatti clipping algorithm.
[0215] It is understandable that in the embodiments of the present application, if the content involves user information, such as information such as images to be processed, target text or text content, and if data related to user information is involved, when the embodiments of the present application are applied to specific products or technologies, user permission or consent must be obtained, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0216] The following is a description of an exemplary structure of the image processing device 354 provided in the embodiment of the present application implemented as a software module. In some embodiments, Figure 3 As shown, the image processing device 354 includes:
[0217] The recognition module 3541 is used to perform text area recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed; the recursive segmentation processing module 3542 is used to perform recursive segmentation processing on the text connected domain to obtain the upper boundary line and the lower boundary line of the text connected domain; the division module 3543 is used to divide the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images; the transformation processing module 3544 is used to perform image transformation processing on each of the text sub-images to obtain a transformed text sub-image; the splicing module 3545 is used to splice the transformed text sub-images to form a spliced text image.
[0218] In some embodiments, the device also includes: a circumscribed polygon determination module, used to determine the circumscribed polygon corresponding to the text connected domain; a calculation module, used to calculate the ratio between the area of the text connected domain and the area of the circumscribed polygon; a determination module, used to determine that the target text is irregular text when the ratio is less than a preset threshold; the recursive segmentation processing module is also used to: when the target text is irregular text, use the circumscribed polygon to recursively segment the text connected domain to obtain the upper boundary line and the lower boundary line of the text connected domain.
[0219] In some embodiments, the circumscribed polygon is a circumscribed rectangle; the recursive segmentation processing module is also used to: determine the bisector of the circumscribed rectangle corresponding to the current text connected domain during each segmentation process of the recursive segmentation processing; determine the intersection of the bisector of the circumscribed rectangle and the text connected domain; divide the text connected domain into two sub-contours based on the coordinates of the intersection; determine a sub-contour of the two sub-contours that is close to the outside of the text connected domain of the target text as the text connected domain of the next recursive segmentation processing; stop the recursive segmentation processing when the aspect ratio of the circumscribed rectangle of the sub-contour obtained after any segmentation processing is less than 1; determine the upper boundary line and the lower boundary line of the text connected domain of the target text according to the coordinates of the intersection obtained during each segmentation processing.
[0220] In some embodiments, two intersection points are obtained during each segmentation process; the recursive segmentation processing module is also used to: determine the four endpoint coordinates of the text connected domain of the target text based on the two end point sub-contours obtained in the last segmentation process of the recursive segmentation process; divide the two intersection points obtained in each segmentation process based on the four endpoint coordinates to form two groups of intersection points; determine the upper boundary line and the lower boundary line of the text connected domain of the target text according to the coordinates of the intersection points in the two groups of intersection points.
[0221] In some embodiments, the recursive segmentation processing module is also used to: obtain the four rectangular endpoints of the circumscribed rectangle of each of the terminal sub-contours; obtain the intersection of the bisector and the text connected domain during the last segmentation processing; determine the distance between each of the rectangular endpoints and the intersection; and determine the coordinates of the two rectangular endpoints with the largest distance in the circumscribed rectangle of each of the terminal sub-contours as the endpoint coordinates of the text connected domain of the target text.
[0222] In some embodiments, the division module is also used to: based on the spacing between the upper boundary line and the lower boundary line, respectively perform equidistant sampling on the upper boundary line and the lower boundary line to obtain multiple sampling point pairs; based on the multiple sampling point pairs, divide the text image corresponding to the target text to form the multiple text sub-images.
[0223] In some embodiments, the device also includes: a cut-off length acquisition module, used to obtain the cut-off length between the two intersection points of the bisector and the text connected domain during each segmentation process; an average value determination module, used to determine the average value of all cut-off lengths to obtain an average cut-off length; and a spacing determination module, used to determine the average cut-off length as the spacing between the upper boundary line and the lower boundary line.
[0224] In some embodiments, the division module is also used to: determine the first length of the upper boundary line and the second length of the lower boundary line; determine the number of sampling segments based on the first length, the second length and the spacing; determine the first equally divided interval length of the upper boundary line based on the first length and the number of sampling segments; determine the second equally divided interval length of the lower boundary line based on the second length and the number of sampling segments; determine the coordinates of each sampling point on the upper boundary line and the lower boundary line by the nearest neighbor interpolation method based on the first equally divided interval length and the second equally divided interval length, and obtain multiple sampling point pairs.
[0225] In some embodiments, the division module is also used to: traverse the pixel points on the upper boundary line and the lower boundary line respectively according to the first equal division interval length and the second equal division interval length, and calculate the cumulative distance traversed by the traversed pixel points; for the pixel points on the upper boundary line, when traversing to any first target pixel point, if the cumulative distance corresponding to the first target pixel point is greater than the first product of the determined number of sampling points and the first equal division interval length, and the cumulative distance corresponding to the previous pixel point of the first target pixel point is less than the first product, determine the coordinates of the current sampling point of the upper boundary line by the nearest neighbor interpolation method; for the pixel points on the lower boundary line, when traversing to any second target pixel point, If the cumulative distance corresponding to the second target pixel point is greater than the second product of the determined number of sampling points and the second equally divided interval length, and the cumulative distance corresponding to the previous pixel point of the second target pixel point is less than the second product, the coordinates of the current sampling point of the lower boundary line are determined by the nearest neighbor interpolation method; the current sampling point of the upper boundary line and the current sampling point of the lower boundary line are determined as a pair of sampling points.
[0226] In some embodiments, the device further includes: a text recognition module, configured to perform text recognition on the spliced text image to obtain text content of the target text.
[0227] It should be noted that the description of the device of the embodiment of the present application is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment, so it is not repeated. For technical details not disclosed in the embodiment of the device, please refer to the description of the method embodiment of the present application for understanding.
[0228] The embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned method of the embodiment of the present application.
[0229] The embodiment of the present application provides a storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the method provided by the embodiment of the present application, for example, Figure 4 The method shown.
[0230] In some embodiments, the storage medium can be a computer-readable storage medium, for example, a ferroelectric random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disk, or a compact disk read-only memory (CD-ROM), etc.; it can also be various devices including one or any combination of the above memories.
[0231] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0232] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions). As an example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one location, or on multiple computing devices distributed at multiple locations and interconnected by a communication network.
[0233] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. An image processing method, It is characterized in that The method comprises: Performing text region recognition on the image to be processed to obtain a text connected domain corresponding to the target text in the image to be processed; Determine the circumscribed polygon corresponding to the text connected domain; Calculating the ratio between the area of the text connected domain and the area of the circumscribed polygon; When the ratio is less than a preset threshold, determining that the target text is an irregular text; When the target text is an irregular text, the circumscribed polygon is used to recursively segment the text connected domain to obtain an upper boundary line and a lower boundary line of the text connected domain; wherein the recursive segmentation process is to perform multiple segmentation processes on the text connected domain corresponding to the target text; Based on the distance between the upper boundary line and the lower boundary line, dividing the text image corresponding to the target text to form a plurality of text sub-images; Performing image transformation processing on each of the text sub-images to obtain a transformed text sub-image; The transformed text sub-images are spliced to form a spliced text image.
2. The method according to claim 1, It is characterized in that The circumscribed polygon is a circumscribed rectangle; The recursive segmentation process of the text connected domain by using the circumscribed polygon to obtain the upper boundary line and the lower boundary line of the text connected domain includes: In each segmentation process of the recursive segmentation process, determining a bisector of the circumscribed rectangle corresponding to the current text connected domain; Determine the intersection point of the bisector of the circumscribed rectangle and the text connected domain; Dividing the text connected domain into two sub-contours based on the coordinates of the intersection point; Determine a sub-contour outside the text connected domain of the target text in the two sub-contours as the text connected domain for the next recursive segmentation process; When the aspect ratio of the circumscribed rectangle of the sub-contour obtained after any segmentation process is less than 1, the recursive segmentation process is stopped; The upper boundary line and the lower boundary line of the text connected domain of the target text are determined according to the coordinates of the intersection points obtained in each segmentation process.
3. The method according to claim 2, It is characterized in that Two intersection points are obtained during each segmentation process; Determining the upper boundary line and the lower boundary line of the text connected domain of the target text according to the coordinates of the intersection points obtained in each segmentation process includes: Determine the coordinates of four endpoints of the text connected domain of the target text based on the two end point sub-contours obtained in the last segmentation process of the recursive segmentation process; Based on the four endpoint coordinates, two intersection points obtained in each segmentation process are divided to form two groups of intersection points; The upper boundary line and the lower boundary line of the text connected domain of the target text are determined according to the coordinates of the intersection points in the two groups of intersection points respectively.
4. The method according to claim 3, It is characterized in that The method of determining the coordinates of four endpoints of the text connected domain of the target text based on the two endpoint sub-contours obtained in the last segmentation process of the recursive segmentation process comprises: Obtain four rectangular endpoints of the circumscribed rectangle of each of the end point sub-contours; Obtaining the intersection of the bisector and the text connected domain in the last segmentation process; Determine the distance between each of the rectangle endpoints and the intersection point; The coordinates of the two rectangular endpoints with the largest distance in the circumscribed rectangle of each of the end point sub-contours are determined as the endpoint coordinates of the text connected domain of the target text.
5. The method according to claim 2, It is characterized in that The dividing the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images includes: Based on the distance between the upper boundary line and the lower boundary line, sampling the upper boundary line and the lower boundary line at equal distances respectively to obtain a plurality of sampling point pairs; Based on the multiple sampling point pairs, the text image corresponding to the target text is divided to form the multiple text sub-images.
6. The method according to claim 5, It is characterized in that The method further comprises: Obtaining the length of the cutoff line between the two intersection points of the bisector and the text connected domain during each segmentation process; Determine the average value of all the cut lengths to obtain the average cut length; The average intercept length is determined as the distance between the upper boundary line and the lower boundary line.
7. The method according to claim 6, It is characterized in that Based on the distance between the upper boundary line and the lower boundary line, the upper boundary line and the lower boundary line are sampled at equal distances to obtain multiple sampling point pairs, including: determining a first length of the upper boundary line and a second length of the lower boundary line; Determine the number of sampling segments according to the first length, the second length and the spacing; Determine the length of the first equally divided interval of the upper boundary line according to the first length and the number of sampling segments; Determine the length of the second equally divided interval of the lower boundary line according to the second length and the number of sampling segments; According to the first equally divided interval length and the second equally divided interval length, the coordinates of each sampling point on the upper boundary line and the lower boundary line are determined by the nearest neighbor interpolation method to obtain a plurality of sampling point pairs.
8. The method according to claim 7, It is characterized in that The coordinates of each sampling point on the upper boundary line and the lower boundary line are determined by the nearest neighbor interpolation method according to the first equally divided interval length and the second equally divided interval length to obtain a plurality of sampling point pairs, including: According to the first equally divided interval length and the second equally divided interval length, the pixel points on the upper boundary line and the pixel points on the lower boundary line are traversed in order, and the cumulative distances traversed by the traversed pixel points are calculated; For the pixel points on the upper boundary line, when traversing to any first target pixel point, if the cumulative distance corresponding to the first target pixel point is greater than the first product of the determined number of sampling points and the first equally divided interval length, and the cumulative distance corresponding to the previous pixel point of the first target pixel point is less than the first product, the coordinates of the current sampling point of the upper boundary line are determined by the nearest neighbor interpolation method; For the pixel points on the lower boundary line, when traversing to any second target pixel point, if the cumulative distance corresponding to the second target pixel point is greater than the second product of the determined number of sampling points and the second equally divided interval length, and the cumulative distance corresponding to the previous pixel point of the second target pixel point is less than the second product, the coordinates of the current sampling point of the lower boundary line are determined by the nearest neighbor interpolation method; The current sampling point of the upper boundary line and the current sampling point of the lower boundary line are determined as a pair of sampling points.
9. The method according to any one of claims 1 to 8, It is characterized in that The method further comprises: Perform text recognition on the spliced text image to obtain the text content of the target text.
10. An image processing device, It is characterized in that The device comprises: A recognition module, used for performing text region recognition on the image to be processed, and obtaining a text connected domain corresponding to the target text in the image to be processed; A circumscribed polygon determination module, used to determine the circumscribed polygon corresponding to the text connected domain; A calculation module, used for calculating the ratio between the area of the text connected domain and the area of the circumscribed polygon; A determination module, configured to determine that the target text is an irregular text when the ratio is less than a preset threshold; A recursive segmentation processing module, used for, when the target text is an irregular text, using the circumscribed polygon to perform recursive segmentation processing on the text connected domain to obtain an upper boundary line and a lower boundary line of the text connected domain; wherein the recursive segmentation processing is to perform multiple segmentation processing on the text connected domain corresponding to the target text; A division module, used for dividing the text image corresponding to the target text based on the distance between the upper boundary line and the lower boundary line to form a plurality of text sub-images; A transformation processing module, used for performing image transformation processing on each of the text sub-images to obtain a transformed text sub-image; The splicing module is used to splice the transformed text sub-images to form a spliced text image.
11. An image processing device, It is characterized in that include: A memory for storing executable instructions; A processor, configured to implement the image processing method according to any one of claims 1 to 9 when executing the executable instructions stored in the memory.
12. A computer-readable storage medium, It is characterized in that Executable instructions are stored, which are used to cause a processor to execute the executable instructions to implement the image processing method according to any one of claims 1 to 9.
