Text image processing method, device, electronic device and readable storage medium
By automatically detecting the text area bounding box in the text image, the problem of low efficiency and non-standard frame selection in the existing technology is solved, fast and accurate text area annotation is achieved, and the application efficiency of OCR technology is improved.
Patent Information
- Application Number
- CN202110097423.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-25
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-01-25
AI Technical Summary
The text area frame selection in existing OCR technology is inefficient and non-standard, making the annotation process cumbersome and time-consuming. It cannot closely follow the text area and affects the annotation effect.
Provides a text image processing method that obtains the text image to be processed, generates an initial bounding box in response to user operations, determines the critical point between the target text area and the background area based on the initial bounding box, and generates a final bounding box to achieve automated text processing. Region bounding box detection.
It improves the efficiency and accuracy of text area box selection, reduces the need for manual adjustment, and improves the efficiency and accuracy of text box annotation.
Smart Images

Figure CN113591827B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence and cloud technology. Specifically, the present application relates to a text image processing method, device, electronic device and readable storage medium. Background Art
[0002] With the further development of OCR (Optical Character Recognition) technology, there is a large gap in the demand for annotated corpus. In the existing technical solutions, when annotating corpus with OCR technology, it is usually necessary to first draw a box for the target content with one click, and then manually adjust the box boundary according to the size of the target text area. After repeated adjustments, the correct text content is selected. However, this method has a complicated operation process and is very time-consuming. At the same time, due to the different sizes of manual adjustments, the boxed area may not be standard, and it may not fit closely to the text area or may cover part of the text area. Figure 1 In the image containing the text “Time is a bird that is always flying” shown in , the framed area (such as Figure 1 The A area in the middle presses down part of the text area. It can be seen that the existing text area selection method is inefficient and the selection effect cannot be guaranteed. Summary of the invention
[0003] The embodiments of the present application provide a text image processing method, device, electronic device and readable storage medium, which can quickly and accurately determine the boundary box of a text area in a text image.
[0004] On the one hand, an embodiment of the present application provides a method for processing a text image, the method comprising:
[0005] Get the text image to be processed;
[0006] In response to a text area selection operation by a user on a text image to be processed, generating an initial bounding box of a target text area corresponding to the text area selection operation;
[0007] Based on the initial bounding box, determining the critical point between the target text area and the background area in the text image to be processed;
[0008] Generate the final bounding box of the target text area based on the critical points.
[0009] In another aspect, an embodiment of the present application provides a text image processing device, the device comprising:
[0010] An image acquisition module, used to acquire the text image to be processed;
[0011] An initial bounding box generation module, used to generate an initial bounding box of a target text area corresponding to the text area selection operation in response to a text area selection operation by a user on a text image to be processed;
[0012] The final bounding box generation module is used to determine the critical point between the target text area and the background area in the text image to be processed based on the initial bounding box; and to generate the final bounding box of the target text area according to the critical point.
[0013] On the other hand, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory is configured to store a computer program, and when the computer program is executed by the processor, the processor executes the text image processing method provided in the embodiment of the present application.
[0014] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program. When the computer program runs on a computer, the computer can execute the text image processing method provided by the embodiment of the present application.
[0015] The beneficial effects of the technical solution provided by the embodiment of the present application are:
[0016] In the embodiment of the present application, based on the solution provided in the embodiment of the present application, the bounding box of the text area in the text image can be intelligently detected, and the appropriate bounding box of the text area can be more accurately selected without multiple manual adjustments, thereby improving the selection efficiency and effectively solving the problem of non-standard selection area caused by manual adjustment. Therefore, when applied to text box annotation, the efficiency and accuracy of text box annotation are effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.
[0018] Figure 1 A schematic diagram of a frame selection area in the prior art;
[0019] Figure 2 A flowchart of a text image processing method provided by an embodiment of the present application;
[0020] Figure 3 A schematic diagram of a candidate bounding box provided in an embodiment of the present application;
[0021] Figure 4 A flowchart of a text image processing method provided by another embodiment of the present application;
[0022] Figure 5 A schematic diagram of a text image to be processed provided in an embodiment of the present application;
[0023] Figure 6 A schematic diagram of an initial bounding box of a target text area provided in an embodiment of the present application;
[0024] Figure 7 A schematic diagram of a binary image provided in an embodiment of the present application;
[0025] Figure 8 A schematic diagram of the boundary of a text area provided in an embodiment of the present application;
[0026] Fig. 9 A schematic diagram of each initial critical point provided in an embodiment of the present application;
[0027] Fig.10 A schematic diagram of a final bounding box of a target text area provided in an embodiment of the present application;
[0028] Fig.11 A schematic diagram of the structure of a text image processing device provided in an embodiment of the present application;
[0029] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0031] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0032] Long ago, countries around the world began to study OCR. In the early stages of the research, the focus was on the recognition method of text, and the recognized text was only the numbers from 0 to 9. China started late in the research of OCR technology. It was not until the 1970s that it began to study the recognition of numbers, English letters and symbols. In the late 1970s, it began to study the recognition of Chinese characters and entered a substantial stage. For early OCR software, due to factors such as recognition rate and productization, it could not meet the actual requirements. At the same time, due to the high cost of hardware equipment and slow running speed, it did not reach the level of practicality. Only a few departments used OCR software, such as news and publishing units. Gradually, with the widespread application of flatbed scanners and the popularization of information automation and office automation in my country, the further development of OCR technology has been greatly promoted. While OCR technology is developing rapidly, there is also a large gap in the demand for annotated corpus.
[0033] Currently, the way to annotate OCR corpus is to first draw a box on the target text content on the image with one click, and then manually adjust the border of the box according to the size of the target text content area. After repeated adjustments, the correct text content is selected. However, this operation process is complicated and time-consuming, which reduces the annotation efficiency. At the same time, the manual adjustment of the size may cause the selected area to be non-standard, such as not being able to fit the text area closely or partially pressing the text area, which affects the annotation effect.
[0034] Based on this, the embodiments of the present application provide a text image processing method, device, electronic device and readable storage medium, aiming to solve the problems of non-standard frame selection area and complicated operation.
[0035] It is understandable that the solution provided by the embodiment of the present application can be applied to the field of text annotation, and can also be applied to any other scenarios that require text annotation. For example, in the field of text recognition, it is necessary to identify the text in a specified area (which can be understood as the target text area) in an image selected by a user. Based on the solution provided by the embodiment of the present application, the specified area can be processed accordingly to determine the accurate final bounding box of the area. After that, only the text area within the final bounding box can be processed for text recognition, which can effectively reduce the amount of data processing.
[0036] Optionally, the solution provided in the embodiment of the present application can be applied to the annotation scenario of the training image of the text processing model in the artificial intelligence technology. The method based on the embodiment of the present application can determine the text area range in the training image, so that the text area can be automatically annotated. It can also be applied to other text processing scenarios. For example, before using the text processing model to process the text image, the specified area can be processed accordingly based on the solution provided in the embodiment of the present application to determine the accurate final bounding box of the area, and then only the text area within the final bounding box is processed.
[0037] Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0038] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0039] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question answering, knowledge graph and other technologies.
[0040] Optionally, the data processing / computation involved in the embodiments of the present application can be obtained based on cloud computing. Cloud computing is a computing model that distributes computing tasks on a resource pool composed of a large number of computers, so that various application systems can obtain computing power, storage space and information services as needed. The network that provides resources is called a "cloud". The resources in the "cloud" are infinitely expandable in the eyes of users, and can be obtained at any time, used on demand, expanded at any time, and paid for by use.
[0041] As a provider of basic cloud computing capabilities, a cloud computing resource pool (referred to as a cloud platform, generally referred to as an IaaS (Infrastructure as a Service) platform) will be established, and various types of virtual resources will be deployed in the resource pool for external customers to choose to use. The cloud computing resource pool mainly includes: computing devices (virtualized machines, including operating systems), storage devices, and network devices.
[0042] According to the logical function division, the PaaS (Platform as a Service) layer can be deployed on the IaaS (Infrastructure as a Service) layer, and the SaaS (Software as a Service) layer can be deployed on the PaaS layer. SaaS can also be deployed directly on IaaS. PaaS is a platform for software operation, such as databases, web containers, etc. SaaS is a variety of business software, such as web portals, SMS mass senders, etc. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.
[0043] Optionally, the text image to be processed involved in the embodiments of the present application can be a text image stored in the cloud. Cloud storage is a new concept extended and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of storage devices of various types (storage devices are also called storage nodes) in the network through application software or application interfaces to work together and provide external data storage and business access functions.
[0044] At present, the storage method of the storage system is: create a logical volume, and when creating a logical volume, allocate physical storage space for each logical volume. The physical storage space may be composed of disks of a storage device or several storage devices. The client stores data on a logical volume, that is, stores the data on the file system. The file system divides the data into many parts, each of which is an object. The object contains not only data but also additional information such as data identification (ID, ID entity). The file system writes each object into the physical storage space of the logical volume, and the file system records the storage location information of each object, so that when the client requests to access the data, the file system can allow the client to access the data according to the storage location information of each object.
[0045] The process of allocating physical storage space to a logical volume by the storage system. Specifically, the physical storage space is divided into stripes in advance according to the estimated capacity of the objects stored in the logical volume (this estimate is often relatively large compared to the actual capacity of the objects to be stored) and the group of independent redundant disk arrays (RAID). A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.
[0046] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0047] The method provided in the embodiment of the present application can be executed by a terminal device or a server or a server interacting with a terminal device. Among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.
[0048] Figure 2 A flowchart of a text image processing method provided in an embodiment of the present application is shown. Optionally, the method can be executed by any electronic device, or can be completed interactively between different devices, such as by a terminal device or a server, or can be executed interactively between a terminal device and a server. It can be understood that the method can also be completed interactively between a terminal device and a server, such as Figure 2 As shown, the method may include:
[0049] Step S101, obtaining a text image to be processed.
[0050] The text image to be processed may refer to an image that needs to be annotated with text, and the text image to be processed includes a text area, which may be a single image acquired by an image acquisition device, or a frame image in a video. The embodiment of the present application does not limit the type of the text image to be processed. Optionally, after acquiring the text image to be processed, the text image to be processed may be displayed by the terminal device.
[0051] As an optional embodiment, the text image to be processed is obtained in the following manner:
[0052] Obtaining an image acquisition operation, wherein the image acquisition operation includes an acquisition path of a text image to be processed;
[0053] Accessing the image database according to the acquisition path;
[0054] Acquire the text image to be processed corresponding to the acquisition path from the image database.
[0055] Among them, when a user (such as a developer) wants to perform text annotation on a text image to be processed, the text image to be processed can be obtained first. When the user obtains the text image to be processed, an image acquisition operation including an acquisition path of the text image to be processed can be triggered; accordingly, when the terminal device receives the image acquisition operation triggered by the user, the image database can be accessed based on the acquisition path included in the image acquisition operation, and the text image to be processed corresponding to the acquisition path can be obtained from the image database, and the obtained text image to be processed can be displayed in the interface.
[0056] Optionally, the specific form of the user triggering the image acquisition operation can be configured as needed, for example, it can be a trigger action of the user specifying the operation position on the application interface. In actual applications, the image acquisition operation can be triggered by a related trigger mark in the client, wherein the specific form of the trigger mark can be configured according to actual needs, for example, it can be a virtual button of "image" displayed on the application interface, and the user's operation of clicking the button is considered as the user triggering the image acquisition operation.
[0057] In an optional embodiment of the present application, the acquisition path includes a URL (Uniform Resource Locator) or a local storage path, and acquiring a to-be-processed text image corresponding to the acquisition path from an image database includes:
[0058] If the acquisition path is a local storage path, the text image to be processed is acquired according to the local storage path;
[0059] If the acquisition path is a URL, the text image to be processed is obtained according to the URL.
[0060] Among them, the embodiment of the present application does not limit the source of obtaining the text image to be processed. For example, the image database can be an image database on the server side. In this case, the text image to be processed is a text image stored on the server side. In this case, the storage path for obtaining the text image to be processed can be the URL of the text image to be processed. Correspondingly, the acquisition path included in the image acquisition operation triggered by the user is the URL of the text image to be processed. The terminal device can obtain the text image to be processed from the image database on the server according to the URL, and display the text image to be processed after obtaining the text image to be processed. Of course, the image database can also be an image database stored locally on the terminal device. In this case, the text image to be processed is a text image stored locally on the terminal device. In this case, the acquisition path for obtaining the text image to be processed is the local storage path. Correspondingly, when the terminal device knows the local storage path, the text image to be processed can be obtained from the image database stored locally on the terminal device based on the local storage path.
[0061] Optionally, if the text image to be processed is a text image stored locally on the terminal device, and the text annotation of the text image to be processed is performed by the server, the server does not know the specific text image to be processed at this time, so after the terminal device obtains the text image to be processed according to the local storage path, it can send the text image to be processed to the server. Correspondingly, when the obtained text image to be processed is displayed by the terminal device, the user can also trigger an image deletion operation, and when the terminal device receives the image deletion operation, it can delete the text image to be processed from the display interface.
[0062] Step S102 : In response to a text region selection operation by a user on a text image to be processed, an initial bounding box of a target text region corresponding to the text region selection operation is generated.
[0063] Among them, the text area selection operation refers to the action of the user selecting the target text area, and the specific form of triggering the text area selection operation can be configured as needed, and is not limited by the embodiments of the present application. For example, a designated trigger button can be set on the application interface for the user to trigger the text area selection trigger operation. When the user clicks the designated trigger button to trigger the text area selection trigger operation, the user can select the text area by using a mouse or a stylus pen. When the selection is completed, it is considered that the user has triggered the text area selection operation. At this time, the corresponding area in the box is the target text area corresponding to the text area selection operation.
[0064] Accordingly, the terminal device can respond to the user's text area selection operation for the text image to be processed, and use the text box corresponding to the user's triggering of the text area selection operation as the initial bounding box of the target text area and display it. Optionally, the position of the edge of the initial bounding box can also be in the middle of the target text area.
[0065] Step S103: determining a critical point between the target text area and the background area in the text image to be processed based on the initial bounding box.
[0066] Step S104: Generate a final bounding box of the target text area based on the critical points
[0067] Wherein, critical point refers to the pixel point between the target text area and the background area, and the critical point can be determined according to the value of each pixel point in the initial bounding box of the target text area. For example, when the pixel values of two adjacent pixels of a certain pixel point in the initial bounding box are different, it means that the pixel point is between the target text area and the background area, and the pixel point is the critical point. Further, the final bounding box of the target text area can be generated according to the determined critical point. Wherein, when the final bounding box of the target text area is generated according to the determined critical point, it can be determined by the pixel value of the pixel point belonging to the text, and optionally, the user can trigger the text content selection operation, which refers to the action that the user wants to determine the final bounding box of the target text area and the action of informing the position of the pixel point of the text in the text image to be processed, and the specific form of triggering the text content selection operation can be configured as needed, and the embodiment of the present application is not limited. For example, the user clicks on any text included in the target text area, which can be regarded as the user triggering the text content selection operation, and the pixel point of the clicked position is the pixel point of the text at this time.
[0068] Accordingly, when the terminal device receives a text content selection operation of the user for the target text area, the terminal device can generate a final bounding box of the target text area according to the determined critical point in response to the text content selection operation and display it to the user. Optionally, the final bounding box is not larger than the initial bounding box.
[0069] It can be understood that when the final bounding box of the target text area is determined by the server, the terminal device can send a text content selection request to the server in response to the user's text content selection operation for the target text area. When the server receives the text content selection request, it can know the position of the pixel points of the text in the text image to be processed, and determine the final bounding box of the target text area, and return the determined final bounding box to the terminal device, so that the terminal device displays the final bounding box to the user.
[0070] In an optional embodiment of the present application, the method further includes:
[0071] The text region of the text image to be processed is annotated according to the final bounding box, so that the annotated text image to be processed is used as a training sample image of the text processing model.
[0072] As an optional embodiment, after obtaining the final bounding box of the target text area, the text image to be processed can be annotated according to the obtained final bounding box, and the annotated text image to be processed is used as a training sample image to train the initial text processing model, thereby obtaining the final text processing model. Among them, the specific implementation method of performing text annotation on the text image to be processed based on the final bounding box can be configured according to actual needs, and the embodiment of the present application is not limited. For example, when the text processing model is a text recognition model, the text included in the final bounding box in the text image to be processed can be annotated to obtain the annotated text image to be processed, and then the initial text recognition model is trained based on the annotated text image to be processed until the corresponding training conditions are met.
[0073] Optionally, when the scheme provided by the embodiment of the present application is interactively executed by a terminal device and a server, the above-mentioned acquisition of the text image to be processed can be that the terminal acquires the text image to be processed, and then sends the text image to be processed to the server, and the server generates an initial bounding box of the target text area corresponding to the text area selection operation in response to the user's text area selection operation for the text image to be processed, and determines the critical point of the target text area in the text image to be processed based on the initial bounding box, and then generates the final bounding box of the target text area according to the critical point. Optionally, when the text image to be processed is acquired, the text image to be processed can be displayed in the terminal device, and after generating the initial bounding box of the target text area and generating the final bounding box of the target text area, the generated initial bounding box and the final bounding box of the target text area can also be displayed to the user through the terminal device, so that the user can perform subsequent processing based on the displayed initial bounding box or final bounding box. Wherein, when the method is executed by the server, the text image to be processed, the initial bounding box of the target text area, and the final bounding box of the target text area can be displayed to the user through the display device corresponding to the server.
[0074] Based on the solution provided in the embodiment of the present application, the bounding box of the text area in the text image can be intelligently detected, and the appropriate bounding box of the text area can be more accurately selected without multiple manual adjustments, thereby improving the selection efficiency and effectively solving the problem of non-standard selection area caused by manual adjustment. Therefore, when applied to text box annotation, the efficiency and accuracy of text box annotation are effectively improved.
[0075] In an optional embodiment of the present application, based on the initial bounding box, determining the critical point between the target text area and the background area in the text image to be processed includes:
[0076] If the text image to be processed is not an image in the target format, the text image to be processed is processed into an image in the target format, and the image in the target format is a binary image or a grayscale image;
[0077] For the target format image, determine the target text area and background area based on the initial bounding box;
[0078] According to the pixel value of each pixel point in the target text area and the background area, the critical point between the target text area and the background area is determined.
[0079] Optionally, when generating the final bounding box of the target text area, it can be determined whether the text image to be processed is an image in the target format. If the text image to be processed is not an image in the target format, the text image to be processed can be converted into an image in the target format, and then the final bounding box of the target text area is generated based on the processed text image to be processed. The target format image can be a binary image or a grayscale image, that is, when the target format image is a binary image, if the text image to be processed is not a binary image, the text image to be processed is converted into a binary image; and when the target format image is a grayscale image, if the text image to be processed is not a grayscale image, the text image to be processed is converted into a grayscale image.
[0080] Among them, processing the text image to be processed into the target format image refers to adjusting the RGB (Red Green Blue) three primary colors of the pixels in the text image to be processed. For example, when the target format image is a binary image, it can refer to converting the pixel values of the pixels in the text image to be processed into black or white, such as converting the pixel values of the pixels of the text in the text image to be processed into white, and converting the pixel values of the background pixels in the text image to be processed into black, or converting the pixel values of the pixels of the text in the text image to be processed into black, and converting the pixel values of the background pixels in the text image to be processed into white, etc. When the target format image is a grayscale image, an external script can be used to grayscale the text image to be processed, that is, converting the RGB values of the pixels in the text image to be processed into gray, that is, uniformly replacing the RGB values of the pixels with gray (Gray) to form a new RGB (Gray, Gray, Gray), thereby achieving a grayscale effect.
[0081] Optionally, when converting the text image to be processed into the target format image and obtaining the initial bounding box of the target text area, the target text area and the background area can be determined based on the determined initial bounding box, such as the target text area and the background area within the initial bounding box can be determined. In this case, compared with determining all the text areas and background areas in the text image to be processed, the amount of data processing can be effectively reduced and the data processing efficiency can be improved. Optionally, when determining the target text area and the background area, the critical point between the target text area and the background area can be determined based on the pixel value of each pixel point in the target text area and the background area, and then the final bounding box of the target text area can be generated based on the critical point.
[0082] In an optional embodiment of the present application, the critical points include critical points in a first direction and critical points in a second direction, the first direction is the writing direction of the text in the target text area, the second direction is a direction perpendicular to the first direction, and the critical points in each of the first direction and the second direction include critical points located on both sides of the text area in the direction;
[0083] Based on the critical points, the final bounding box of the target text area is generated, including:
[0084] For each side of each direction in the first direction and the second direction, based on the critical point of the side, a boundary connection line corresponding to the side is obtained;
[0085] Connect each boundary line to generate the final bounding box of the target text area.
[0086] In the embodiment of the present application, the critical point may include a critical point in a first direction and a critical point in a second direction, and the first direction may refer to the writing direction of the text in the target text area, and the second direction is a direction perpendicular to the first direction. For example, when the writing direction of the text in the target text area is from left to right, the first direction is from left to right, and the second direction is from top to bottom, and when the writing direction of the text in the target text area is from top to bottom, the first direction is from top to bottom, and the second direction is from left to right.
[0087] Optionally, for the critical points in the first direction and the critical points in the second direction, the critical points in each direction of the first direction and the second direction include the critical points located on both sides of the text area in that direction, that is, the critical points in each direction include the critical points on both sides of the text area. For example, assuming that the writing direction of the text in the target text area is from left to right, the first direction is from left to right, and the second direction is from top to bottom. The critical points in the first direction include the critical points located on the upper and lower sides of the text area, and the critical points in the second direction include the critical points located on the left and right sides of the text area.
[0088] Accordingly, when determining the final bounding box of the target text area based on the critical points, for each side of each direction in the first direction and the second direction, the critical points belonging to the side can be first determined from the critical points, and based on the critical points belonging to the side, the boundary connection line corresponding to the side can be obtained. Furthermore, when the boundary connection line corresponding to each side in the first direction and the second direction is obtained, the boundary connection lines can be connected to generate the final bounding box of the target text area.
[0089] In one example, assuming that the critical points in the first direction include critical points located on the upper and lower sides of the text area, and the critical points in the second direction include critical points located on the left and right sides of the text area, each adjacent pixel point belonging to the upper side of the text area is determined respectively, and then based on each adjacent pixel point belonging to the upper side of the text area, a boundary connection line corresponding to the upper side of the text area is obtained. Similarly, the boundary connection line corresponding to the lower side of the text area, the boundary connection line corresponding to the left side of the text area, and the boundary connection line corresponding to the right side of the text area can be obtained, and then the boundary connection line corresponding to the upper side of the text area, the boundary connection line corresponding to the lower side of the text area, the boundary connection line corresponding to the left side of the text area, and the boundary connection line corresponding to the right side of the text area are connected to generate a final bounding box of the target text area.
[0090] In an optional embodiment of the present application, determining the critical point between the target text area and the background area according to the pixel value of each pixel point in the target text area and the background area includes:
[0091] Determine the pixel value of each pixel in the target text area and the background area;
[0092] Determine each initial critical point between the target text area and the background area according to the difference between the pixel values of each pixel point;
[0093] According to each initial critical point, the critical point between the target text area and the background area is determined.
[0094] Among them, since the text image to be processed is a text image of the target format image, the pixel values of the pixels in the background area of the text image to be processed are the same, and the pixel values of the pixels in the text area of the text image to be processed are the same, but the pixel values of the pixels in the background area are different from the pixel values of the pixels in the text area. When determining the difference between the pixel values of each pixel, if the pixels belong to the same area (i.e., the background area or the text area), the difference between the pixel values is 0, and when the pixels do not belong to the same area (such as one pixel belongs to the background area and one pixel belongs to the text area), the difference between the pixel values will not be 0.
[0095] Accordingly, when determining the critical point, the pixel value of each pixel in the target text area and the background area can be determined, and then the initial critical points between the target text area and the background area can be determined based on the difference between the pixel values of each pixel, and then the critical point can be determined from the initial critical points. If the difference between the pixel values of two pixels is not 0, it means that the two pixels are respectively in the background area and the target text area, and since the position of the pixel of the text in the text image to be processed can be known based on the pixel value of the pixel at this position, the pixel value of the pixel belonging to the text can be known at this time, and then the pixel belonging to the text can be determined from the pixel value of the pixel belonging to the text, and the pixel belonging to the text can be used as the initial adjacent pixel.
[0096] In an optional embodiment of the present application, determining the critical point between the target text area and the background area according to each initial critical point includes:
[0097] For each side of each of the first direction and the second direction, at least one final pixel point is determined from the initial critical points according to the distance of the initial critical points belonging to the side in the vertical direction of the direction.
[0098] Optionally, for each side of each direction in the first direction and the second direction, the distance of each initial critical point belonging to that side in the vertical direction of that direction can be determined, and then at least one final critical point can be determined from each initial critical point based on the distance of each initial critical point in the vertical direction of that direction.
[0099] In one example, assuming that the first direction is from left to right, the two sides in the first direction are the upper and lower sides of the text area, and each initial pixel point can be represented by an (x, y) coordinate. At this time, for each initial pixel point belonging to the upper side of the text area, the distance of each initial pixel point in the y-axis direction can be determined, and then at least two critical points are determined from each initial pixel point belonging to the upper side of the text area according to the distance of each initial pixel point in the y-axis direction. Similarly, for each initial pixel point belonging to the left side of the text area, the distance of each initial pixel point in the x-axis direction can be determined, and then at least one final critical point is determined from each initial pixel point belonging to the left side of the text area according to the distance of each initial pixel point in the x-axis direction.
[0100] In an optional embodiment of the present application, determining a final critical point from each initial critical point includes:
[0101] If the distances between the initial critical points on the same side are all less than or equal to the set value, at least one of the initial critical points is determined as the final critical point;
[0102] If the distance between the initial critical points on the same side is greater than a set value, at least two final critical points are determined from the initial critical points, and the at least two critical points include the initial critical point that is farthest from the other side corresponding to the side.
[0103] Optionally, for each initial critical point belonging to the same side, if it is determined that the distance between each initial critical point in the vertical direction of the direction is less than or equal to the set value, it means that the initial critical points are close to each other and can be regarded as being on the same horizontal line. At this time, any at least one initial critical point can be selected from the initial critical points to be determined as the final critical point. On the contrary, if the distance between each initial critical point in the vertical direction of the direction is greater than the set value, it means that there are initial critical points that are close to each other and far away. At this time, at least two final critical points can be determined from each initial critical point to ensure the accuracy of the final bounding box determined by each critical point.
[0104] Among them, the initial critical point farthest from the other side corresponding to the side among the initial critical points of the at least two critical points determined. For example, if the two initial critical points corresponding to the distance greater than the set value belong to the left side of the text area, the distances of the initial critical points belonging to the left side of the text area from the right side of the text area can be determined respectively, and then the initial critical point farthest from the right side of the area is determined as one of the at least two final critical points. Of course, in practical applications, the two initial critical points corresponding to the distance greater than the set value can also be determined as critical points.
[0105] In an optional embodiment of the present application, based on the critical point of the side, a boundary connection line corresponding to the side is obtained, including:
[0106] If there is only one critical point on the side, a boundary connection line corresponding to the side is determined based on the critical point on the side and the direction to which the side belongs, and the direction to which the side belongs is the first direction or the second direction;
[0107] If there are at least two critical points on the side, a boundary connection line corresponding to the side is determined based on the at least two critical points on the side.
[0108] Optionally, if there is one critical point belonging to the same side, the boundary connection line corresponding to the side can be determined based on the one critical point and the direction to which the side belongs; correspondingly, if there are at least two critical points belonging to the same side, the boundary connection line corresponding to the side can be determined based on the at least two critical points.
[0109] In one example, assuming that the first direction is from left to right, the two sides of the first direction are the upper and lower sides of the text area, the second direction is from top to bottom, the two sides of the second direction are the left and right sides of the text area, and there is only one critical point located on the upper side of the text area, then the critical point can be used as a reference, the first direction can be used as a horizontal direction, and the second direction can be used as a vertical direction to extend to the left and right sides, so as to obtain the boundary connection line on the upper side of the text area; if there are at least two critical points located on the upper side of the text area, the at least two critical points are connected, and the first direction can be used as a horizontal direction and the second direction can be used as a vertical direction to extend to the left and right sides, so as to obtain the boundary connection line on the upper side of the text area.
[0110] In an optional embodiment of the present application, generating a final bounding box of the target text area according to the critical point includes:
[0111] Based on the critical points, generate candidate bounding boxes corresponding to the target text area;
[0112] If there is only one candidate bounding box, the candidate bounding box is determined as the final bounding box of the target text area;
[0113] If there are at least two candidate bounding boxes, the at least two candidate bounding boxes are filtered according to their heights to obtain a final bounding box of the target text area, wherein the height is a height in a vertical direction corresponding to a writing direction of the text in the target text area.
[0114] Optionally, when the initial bounding box of the target text area corresponding to the text area selection operation only includes the text area that needs to be annotated, the candidate bounding box corresponding to the target text area determined according to the critical point will be one, and the candidate bounding box can be directly determined as the final bounding box of the target text area.
[0115] However, in actual applications, sometimes the initial bounding box of the target text area corresponding to the text area selection operation may include other parts of the text area except those that need to be annotated, such as the situation where other parts of the text area are pressed. At this time, according to the critical points in the target text area, the candidate bounding boxes corresponding to the target text area may be at least two. At this time, at least two candidate bounding boxes can be filtered according to the height of the candidate bounding boxes to obtain the final bounding box of the target text area. Among them, the height of the first bounding box refers to the height in the vertical direction corresponding to the writing direction of the text in the target text area. Optionally, when filtering at least two candidate bounding boxes according to the heights of at least two candidate bounding boxes to obtain the final bounding box of the target text area, the candidate bounding box with the largest height can be retained as the final bounding box of the target text area.
[0116] In one example, assuming that the writing direction of the text in the target text area is from left to right, the height of the candidate bounding box is the vertical direction of the writing direction, that is, the upper and lower widths of the candidate bounding box, and according to the critical points in the target text area, the candidate bounding box corresponding to the target text area is determined as follows: Figure 3 As shown, two candidate bounding boxes are determined (ie, candidate bounding box A and candidate bounding box B). At this time, the upper and lower heights of each first bounding box can be determined, and then the candidate bounding box with the largest height is retained as the final bounding box of the target text area.
[0117] In an optional embodiment of the present application, after generating a final bounding box of the target text area according to the critical points, the method further includes:
[0118] Crop the text area from the text image to be processed according to the final bounding box;
[0119] Perform text recognition on the cropped text area to obtain a text recognition result;
[0120] Display the text recognition result in the text annotation area of the image to be processed;
[0121] In response to the approval operation of the text recognition result in the text annotation area, a text image annotation corpus is generated according to the approved text recognition result and the text image to be processed.
[0122] Optionally, after generating the final bounding box of the target text area, a cropped text area can be cropped from the text image to be processed using the final bounding box as the cropping frame, wherein the size of the cropped text area is greater than or equal to the size of the area enclosed by the final bounding box. Accordingly, text recognition can be performed on the cropped text to obtain a text recognition result, and the text recognition result can be displayed in the text annotation area of the image to be processed so that the user knows the text recognition result obtained by the text recognition; accordingly, the user can verify the text recognition result obtained by the recognition, that is, verify whether the text recognition result obtained by the recognition is consistent with the text included in the cropped text area, and the verification operation of the text recognition result can be triggered when the verification is completed. Furthermore, in response to the verification operation of the text recognition result, a text image annotation corpus can be generated based on the verified text recognition result and the text image to be processed, and other subsequent processing can be performed based on the generated text image annotation corpus.
[0123] Among them, when the user verifies the text recognition result obtained, if the text recognition result obtained is consistent with the text included in the cropped text area, it means that the text recognition result is accurate. At this time, the verification operation triggered by the user is the verification confirmation operation, and the verified text recognition result is still the text recognition result obtained; correspondingly, if the text recognition result obtained is inconsistent with the text included in the cropped text area, it means that there is an error in the text recognition result. The user can correct the text recognition result obtained according to the text included in the cropped text area, and trigger the verification operation after the correction is completed. At this time, the text recognition result after the correction is completed is the verified text recognition result.
[0124] In order to better understand the text image processing method provided in the embodiment of the present application, the text image processing method is described in detail below in conjunction with a specific application scenario. The application scenario in this example is to determine the final bounding box of the target text area in the text image to be processed according to the text image processing method, and then annotate the text area of the text image to be processed according to the generated final bounding box, and use the annotated text image to be processed as a training sample image for the text processing model. The acquisition path of the text image to be processed is a URL, and the final bounding box of the target text area in the text image to be processed is determined by the server, and the target format image is a binary image, such as a black and white image. Figure 4 A method for determining a final bounding box of a target text area in a text image to be processed is described.
[0125] Step S401, the terminal device obtains and displays the text image to be processed;
[0126] Specifically, the user can trigger an image acquisition operation on the terminal device, and the image acquisition operation includes the URL of the text image to be processed. The terminal device responds to the image acquisition operation and sends the URL of the text image to be processed to the server. The server accesses the image database according to the URL of the text image to be processed to obtain the text image to be processed and returns it to the terminal device. When the terminal device receives the text image to be processed, it loads the text image to be processed and displays the text image to be processed in the application interface. For example, the obtained text image to be processed is as follows: Figure 5 As shown, the text image to be processed is an RGB image, and includes a text area "Time is a bird that is always flying" and a background area (such as Figure 5 area other than the text area).
[0127] Step S402, the terminal device displays an initial bounding box of the target text area corresponding to the text area selection operation;
[0128] Specifically, when the user wants to annotate the text in the text area to be processed, the text area selection operation can be triggered to select the specific text area to be annotated (i.e., the target text area). In response to the text area selection operation, the terminal device determines and displays the initial bounding box of the target text area corresponding to the text area selection operation, and at the same time, the initial bounding box of the target text area can be sent to the server to inform the server that the user wants to annotate the text in the initial bounding box. When the terminal device sends the initial bounding box of the target text area to the server, the coordinates of the initial bounding box of the target text area in the text image to be processed can be sent to the server, and the server can determine the initial bounding box of the target text area based on the received coordinates.
[0129] In one example, suppose that the user wants to annotate the text "birds flying" included in the text image to be processed. At this time, the text "birds flying" is the target text area. When the user triggers the text area selection operation, he can use the mouse to select the text "birds flying". Correspondingly, in response to the text area selection operation, the terminal device can use the boundary of the user-selected area as the initial boundary box of the target text area and display it. Specifically, it can be as follows Figure 6 As shown in the black rectangle.
[0130] Step S403, the terminal device receives the text content selection operation of the user on the target text area, and sends a text content selection request to the server;
[0131] Specifically, after the initial bounding box of the target text area is displayed to the user, the user can trigger a text content selection operation for the target text area. When the terminal device receives the text content selection operation, it means that the user wants to determine the final bounding box of the target text area. At this time, a text content selection request can be sent to the server. When the server receives the text content selection request, it can know the position of the pixel points of the text in the text image to be processed.
[0132] Step S404, the server responds to the text content selection request and determines whether the text image to be processed is a binary image. If so, step S406 is executed, otherwise, step S405 is executed;
[0133] Step S405: converting the text image to be processed into a binary image;
[0134] Specifically, when the server receives a text content selection request sent by a terminal device, it can determine whether the text image to be processed is a black and white image. If the text image to be processed is not a black and white image, each pixel in the text image to be processed can be binarized to obtain a processed text image to be processed, and then the final bounding box of the target text area can be determined based on the processed image. Figure 5 The text image to be processed is binarized into a black and white image. Specifically, Figure 7 shown.
[0135] Step S406, the server determines each initial critical point between the target text area and the background area;
[0136] Among them, since the text image to be processed is a black and white image, the pixel values of the pixels in the background area of the text image to be processed are the same (that is, the RGB values are all black), and the pixel values of the pixels in the text area are the same (that is, the RGB values are all white), and since the position of the pixel points of the text in the text image to be processed can be known based on the text content selection operation, the pixel value of the pixel point belonging to the text can be known according to the pixel value of the pixel point at this position (that is, the RGB value of the pixel point of the text is white), and then the pixel points belonging to the text and the pixel points belonging to the background area in the text image to be processed can be determined according to the pixel values of the pixel points belonging to the text, and the area where the target text area is located can be determined according to the pixel points belonging to the text, and the area where the target text area is located can be framed and selected, which can be specifically as follows Figure 8 As shown in the white line in FIG. 1 , it can be understood that the white line should coincide with the border of the text “a bird in flight”, but for the convenience of description, the white line is Figure 8 The border does not overlap with the text "Birds in Flight".
[0137] Furthermore, each initial critical point between the target text area and the background area can be determined based on the difference between the pixel values of each pixel. For example, when the difference between the pixel values of two pixels is not 0, it means that the two pixels are respectively in the background area and the target text area, and then the pixel belonging to the text of the two pixels can be determined based on the pixel value of the pixel belonging to the text, and the pixel belonging to the text is used as the initial critical point.
[0138] Step S407, the server determines the critical point between the target text area and the background area according to each initial critical point;
[0139] Optionally, the critical point may include a critical point in a first direction and a critical point in a second direction, and the first direction may refer to the writing direction of the text in the target text area, and the second direction is a direction perpendicular to the first direction. Further, for each side of each of the first direction and the second direction, the distance of each initial critical point in the vertical direction of the direction may be determined, and then the critical point of the side may be determined from each initial critical point according to the distance of each initial critical point in the vertical direction of the direction.
[0140] Among them, when determining the critical point from each initial critical point according to the distance between each initial critical point in the vertical direction of the direction, for each initial critical point belonging to the same side, if it is determined that the distance between each initial critical point in the vertical direction of the direction is less than or equal to the set value, it means that each initial critical point is close to each other and can be regarded as being on the same horizontal line. At this time, at least one initial critical point can be selected from each initial critical point to be determined as the critical point. On the contrary, if the distance between each initial critical point in the vertical direction of the direction is greater than the set value, it means that there is an initial critical point that is far away from each other. At this time, at least two critical points can be determined from each initial critical point to ensure the accuracy of the final bounding box determined according to each critical point.
[0141] In one example, suppose that the initial critical points determined in the text image to be processed are as follows: Fig. 9 As shown, the initial critical points A to C are on the same side in the same direction, the initial critical points D and the initial critical points E are on one side alone, and the initial critical points F to I are on the same side in the same direction. At this time, for the initial critical points A to C, since the distances between the initial critical points A to C in the vertical text writing direction are all less than the set value, the initial critical point A can be selected from the initial critical points A to C to be determined as the critical point; and for the initial critical points F to H, since the distances between the initial critical points F to H in the vertical text writing direction are all less than the set value, the initial critical point F can be selected from the initial critical points F to H to be determined as the critical point; and for the initial critical points D and E, since the initial critical points D and E are on one side alone, the initial critical points D and E can be directly determined as the critical points.
[0142] Step S408: The server generates a final bounding box of the target text area according to the critical points.
[0143] Specifically, for the same side in each of the first direction and the second direction, the critical points belonging to the same side can be first determined from each adjacent pixel point, and based on the critical points belonging to the same side, the boundary connection line corresponding to the side can be obtained. Furthermore, when the boundary connection line corresponding to each side in the first direction and the second direction is obtained, the boundary connection lines can be connected to obtain the final bounding box of the target text area.
[0144] In one example, suppose that the critical points on the same side of each direction determined in the text image to be output are as follows: Fig.10As shown, it specifically includes critical point A, critical point F, critical point D and critical point E. At this time, the boundary connection line corresponding to the side can be obtained based on the critical points belonging to the same side. For example, the boundary connection line on the upper side of the target text area is obtained according to critical point A, the boundary connection line on the lower side of the target text area is obtained according to critical point F, the boundary connection line on the left side of the target text area is obtained according to critical point D, and the boundary connection line on the right side of the target text area is obtained according to critical point F. Then, the boundary connection lines on the upper, lower, left and right sides of the target text area are connected to obtain the final bounding box of the target text area, as shown in FIG. Fig.10 As shown in the white rectangle.
[0145] Step S409: sending the final bounding box of the target text area to the terminal device, so that the terminal device displays the final bounding box of the target text area to the user.
[0146] In an embodiment of the present application, the text content annotation of the image area is completed through the final bounding box of the target text area, and the accuracy of the final bounding box of the target text area is ensured through intelligent boundary detection. At this time, the determined final bounding box is adapted to the size of the target text area in the target text area, which can effectively solve the problem of manual selection of text areas and improve the annotation efficiency and accuracy.
[0147] The present application embodiment provides a text image processing device, such as Fig.11 As shown, the text image processing device 60 may include: an image acquisition module 601, an initial bounding box generation module 602 and a final bounding box generation module 603, wherein:
[0148] An image acquisition module 601 is used to display the text image to be processed;
[0149] An initial bounding box generating module 602 is used to generate an initial bounding box of a target text area corresponding to the text area selection operation in response to a text area selection operation by a user on a text image to be processed;
[0150] The final bounding box generation module 603 is used to determine the critical points between the target text area and the background area in the text image to be processed based on the initial bounding box; and to generate the final bounding box of the target text area according to the critical points.
[0151] Optionally, when determining the critical point between the target text area and the background area in the text image to be processed based on the initial bounding box, the final bounding box generation module is specifically used to:
[0152] If the text image to be processed is not an image in the target format, the text image to be processed is processed into an image in the target format, and the image in the target format is a binary image or a grayscale image;
[0153] For the target format image, determine the target text area and background area based on the initial bounding box;
[0154] According to the pixel value of each pixel point in the target text area and the background area, the critical point between the target text area and the background area is determined.
[0155] Optionally, the critical points include critical points in a first direction and critical points in a second direction, the first direction is a writing direction of the text in the target text area, the second direction is a direction perpendicular to the first direction, and the critical points in each of the first direction and the second direction include critical points located on both sides of the text area in the direction;
[0156] The final bounding box generation module is specifically used to generate the final bounding box of the target text area according to the critical point between the text area and the background area in the target text area:
[0157] For each side of each direction in the first direction and the second direction, based on the critical point of the side, a boundary connection line corresponding to the side is obtained;
[0158] Connect each boundary line to generate the final bounding box of the target text area.
[0159] Optionally, when the final bounding box generation module determines the critical point between the target text area and the background area according to the pixel value of each pixel point in the target text area and the background area, it is specifically used to:
[0160] Determine the pixel value of each pixel in the target text area and the background area;
[0161] Determine each initial critical point between the target text area and the background area according to the difference between the pixel values of each pixel point;
[0162] According to each initial critical point, the critical point between the target text area and the background area is determined.
[0163] Optionally, when determining the critical point between the target text area and the background area according to each initial critical point, the final bounding box generation module is specifically used to:
[0164] For each side of each of the first direction and the second direction, at least one final critical point is determined from the initial critical points according to the distance of the initial critical points belonging to the side in the perpendicular direction of the direction.
[0165] Optionally, when determining at least one final critical point from each initial critical point, the final bounding box generation module is specifically used to:
[0166] If the distance between the initial critical points on the same side is less than or equal to the set value, any initial critical point among the initial critical points is determined as the critical point;
[0167] If the distances between the initial critical points on the same side are all less than or equal to the set value, at least one of the initial critical points is determined as the final critical point;
[0168] If the distance between the initial critical points on the same side is greater than a set value, at least two final critical points are determined from the initial critical points, and the at least two critical points include the initial critical point that is farthest from the other side corresponding to the side.
[0169] Optionally, when the final bounding box generation module obtains the boundary connection line corresponding to the side based on the critical point of the side, it is specifically used to:
[0170] If there is only one critical point on the side, a boundary connection line corresponding to the side is determined based on the critical point on the side and the direction to which the side belongs, and the direction to which the side belongs is the first direction or the second direction;
[0171] If there are at least two critical points on the side, a boundary connection line corresponding to the side is determined based on the at least two critical points on the side.
[0172] Optionally, when determining the final bounding box of the target text area according to the critical point, the final bounding box generation module is specifically used to:
[0173] Based on the critical points, generate candidate bounding boxes corresponding to the target text area;
[0174] If there is only one candidate bounding box, the candidate bounding box is determined as the final bounding box of the target text area;
[0175] If there are at least two candidate bounding boxes, the at least two candidate bounding boxes are filtered according to their heights to obtain a final bounding box of the target text area, wherein the height is a height in a vertical direction corresponding to a writing direction of the text in the target text area.
[0176] Optionally, the device further comprises a marking module, which is used to:
[0177] The text region of the text image to be processed is annotated according to the final bounding box, so that the annotated text image to be processed is used as a training sample image of the text processing model.
[0178] Optionally, the device further includes an image acquisition module, specifically used for:
[0179] Obtaining an image acquisition operation, wherein the image acquisition operation includes an acquisition path of a text image to be processed;
[0180] Accessing the image database according to the acquisition path;
[0181] Acquire the text image to be processed corresponding to the acquisition path from the image database.
[0182] Optionally, the device further comprises a display module.
[0183] Optionally, the device further includes a marked corpus generation module, which is used to:
[0184] After generating a final bounding box of the target text area according to the critical points, cropping the text area from the text image to be processed according to the final bounding box;
[0185] Perform text recognition on the cropped text area to obtain a text recognition result;
[0186] Display the text recognition result in the text annotation area of the image to be processed;
[0187] In response to the approval operation of the text recognition result in the text annotation area, a text image annotation corpus is generated according to the approved text recognition result and the text image to be processed.
[0188] The text image processing device of the embodiment of the present application can execute a text image processing method provided in the embodiment of the present application. The implementation principle is similar and will not be repeated here.
[0189] Optionally, the text image processing device can be a computer program (including program code) running in a computer device, for example, the text image processing device is an application software; the device can be used to execute the corresponding steps in the method provided in the embodiment of the present application.
[0190] In some embodiments, the text image processing device provided in the embodiments of the present application can be implemented in a combination of software and hardware. As an example, the text image processing 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 de-interference 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.
[0191] In other embodiments, the text image processing device provided in the embodiments of the present application may be implemented in a software manner. Fig.11 A text image processing device 60 is shown, which can be software in the form of a program and a plug-in, and includes a series of modules, including an image acquisition module 601, an initial bounding box generation module 602, and a final bounding box generation module 603; wherein the image acquisition module 601, the initial bounding box generation module 602, and the final bounding box generation module 603 are used to implement the text image processing method provided in the embodiment of the present application.
[0192] The present application embodiment provides an electronic device, such as Fig.12 As shown, Fig.12 The electronic device 2000 shown includes: a processor 2001 and a memory 2003. The processor 2001 and the memory 2003 are connected, such as through a bus 2002. Optionally, the electronic device 2000 may also include a transceiver 2004. It should be noted that in actual applications, the transceiver 2004 is not limited to one, and the structure of the electronic device 2000 does not constitute a limitation on the embodiments of the present application.
[0193] The processor 2001 is used in the embodiment of the present application to implement Fig.11 The functions of each module are shown.
[0194] Processor 2001 may be a CPU, a general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a transistor logic device, a hardware component or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 2001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0195] The bus 2002 may include a path to transmit information between the above components. The bus 2002 may be a PCI bus or an EISA bus, etc. The bus 2002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.12 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0196] Memory 2003 may be ROM or other types of static storage devices that can store static information and computer programs, RAM or other types of dynamic storage devices that can store information and computer programs, or may be EEPROM, CD-ROM or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store or in the form of a data structure the desired computer program and can be accessed by a computer, but is not limited thereto.
[0197] The memory 2003 is used to store a computer program for executing the application program of the present application solution, and the execution is controlled by the processor 2001. The processor 2001 is used to execute the computer program of the application program stored in the memory 2003 to implement Fig.11 The illustrated embodiment provides actions of the apparatus for processing text images.
[0198] An embodiment of the present application provides an electronic device, including a processor and a memory: the memory is configured to store a computer program, and when the computer program is executed by the processor, the processor performs any one of the methods in the above embodiments.
[0199] An embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program. When the computer program runs on a computer, the computer can execute any one of the methods in the above embodiments.
[0200] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A 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 methods provided in the above-mentioned various optional implementations.
[0201] The nouns and implementation principles involved in a computer-readable storage medium in the present application can be specifically referred to a text image processing method in an embodiment of the present application, and will not be repeated here.
[0202] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0203] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A text image processing method, characterized in that: include: Get the text image to be processed; In response to a text area selection operation by a user on the text image to be processed, generating an initial bounding box of a target text area corresponding to the text area selection operation; Based on the initial bounding box, determining a critical point between the target text area and the background area in the text image to be processed; Generating a final bounding box of the target text area according to the critical points; Wherein, determining the critical point between the target text area and the background area in the text image to be processed based on the initial bounding box includes: For the target format image of the text image to be processed, determining the target text area and the background area based on the initial bounding box; Determine the pixel value of each pixel in the target text area and the background area; Determining each initial critical point between the target text area and the background area according to the difference between the pixel values of each pixel point; The critical points include critical points in a first direction and critical points in a second direction, the first direction is the writing direction of the text in the target text area, the second direction is a direction perpendicular to the first direction, and the critical points in each of the first direction and the second direction include critical points located on both sides of the text area in the direction; For each side of each of the first direction and the second direction, according to the distance between the initial critical points belonging to the side in the vertical direction of the direction, if the distances between the initial critical points on the same side are all less than or equal to the set value, at least one of the initial critical points is determined as the final critical point; if the distances between the initial critical points on the same side are greater than the set value, at least two final critical points are determined from the initial critical points, and the at least two critical points include the initial critical point that is farthest from the other side corresponding to the side.
2. The method according to claim 1, characterized in that Before determining the target text area and the background area based on the initial bounding box, the method further includes: If the text image to be processed is not an image in a target format, the text image to be processed is processed into an image in a target format, and the image in the target format is a binary image or a grayscale image.
3. The method according to claim 2, characterized in that Generating a final bounding box of the target text area according to the critical point includes: For each side of each direction in the first direction and the second direction, based on the critical point of the side, a boundary connection line corresponding to the side is obtained; The boundary connection lines are connected to generate a final boundary box of the target text area.
4. The method according to claim 3, characterized in that The step of obtaining a boundary connection line corresponding to the side based on the critical point of the side includes: If there is one critical point on the side, a boundary connection line corresponding to the side is determined based on the critical point on the side and the direction to which the side belongs, where the direction to which the side belongs is the first direction or the second direction; If there are at least two critical points on the side, a boundary connection line corresponding to the side is determined based on the at least two critical points on the side.
5. The method according to any one of claims 1 to 3, characterized in that Generating a final bounding box of the target text area according to the critical point includes: Generating a candidate bounding box corresponding to the target text area according to the critical point; If there is one candidate bounding box, determining the candidate bounding box as the final bounding box of the target text area; If there are at least two candidate bounding boxes, the at least two candidate bounding boxes are filtered according to their heights to obtain a final bounding box of the target text area, wherein the height is a height in a vertical direction corresponding to a writing direction of the text in the target text area.
6. The method according to any one of claims 1 to 3, characterized in that Also includes: The text region of the text image to be processed is annotated according to the final bounding box, so that the annotated text image to be processed is used as a training sample image of a text processing model.
7. The method according to claim 1, characterized in that The text image to be processed is obtained by: Acquire an image acquisition operation, wherein the image acquisition operation includes an acquisition path of a text image to be processed; accessing an image database according to the acquisition path; The to-be-processed text image corresponding to the acquisition path is acquired from the image database.
8. The method according to claim 1, characterized in that After generating the final bounding box of the target text area according to the critical points, the method further includes: Cropping a text area from the text image to be processed according to the final bounding box; Perform text recognition on the cropped text area to obtain a text recognition result; Displaying the text recognition result in the text annotation area of the image to be processed; In response to the approval operation of the text recognition result in the text annotation area, a text image annotation corpus is generated according to the approved text recognition result and the text image to be processed.
9. A text image processing device, characterized in that: include: An image acquisition module, used to acquire the text image to be processed; An initial bounding box generating module, configured to generate an initial bounding box of a target text area corresponding to a text area selection operation by a user for the text image to be processed; A final bounding box generation module, used to determine the critical point between the target text area and the background area in the text image to be processed based on the initial bounding box; and generating a final bounding box of the target text area according to the critical points; The final bounding box generation module, when determining the critical point between the target text area and the background area in the text image to be processed based on the initial bounding box, is specifically used to: For the target format image of the text image to be processed, determining the target text area and the background area based on the initial bounding box; Determine the pixel value of each pixel in the target text area and the background area; Determining each initial critical point between the target text area and the background area according to the difference between the pixel values of each pixel point; The critical points include critical points in a first direction and critical points in a second direction, the first direction is the writing direction of the text in the target text area, the second direction is a direction perpendicular to the first direction, and the critical points in each of the first direction and the second direction include critical points located on both sides of the text area in the direction; For each side of each of the first direction and the second direction, according to the distance between the initial critical points belonging to the side in the vertical direction of the direction, if the distances between the initial critical points on the same side are all less than or equal to the set value, at least one of the initial critical points is determined as the final critical point; if the distances between the initial critical points on the same side are greater than the set value, at least two final critical points are determined from the initial critical points, and the at least two critical points include the initial critical point that is farthest from the other side corresponding to the side.
10. An electronic device, characterized in that: including a processor and a memory; The memory is configured to store a computer program, which, when executed by the processor, causes the processor to perform the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and when the computer program is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method and device for positioning text in image, electronic device and storage medium
CN109753953A
Character detection method, system and device for natural scene picture and storage medium
CN110032998A
Method and device for detecting text region in image, equipment and medium
CN110147786A
Image detection method and device
CN111429396A
Image processing method and device, electronic equipment and readable storage medium
CN111709956A
