Label sample generation method and device based on rectangular pattern and image processing method and device

By determining the coordinates of three scene points on the target image to generate a rectangular text box, the problems of low text labeling efficiency and difficult to determine text direction in the prior art are solved, and high-quality text area slicing is achieved.

CN118898850AActive Publication Date: 2024-11-05SAIC GM WULING AUTOMOBILE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410964087.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-11-05
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

The existing text annotation methods are inefficient and cannot accurately determine the text direction, resulting in poor quality of text area slices.

Method used

By determining the coordinates of three scene points on the target image, an automatically generated rectangular text box is generated to ensure that the top and bottom edges of the rectangular text box are accurate, and then the text direction is determined and perspective transformation is performed to maintain the shape and direction of the text.

Benefits of technology

It improves the efficiency and accuracy of text labeling, ensures the quality of text area slices, and is suitable for the training dataset of text recognition models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118898850A_ABST
    Figure CN118898850A_ABST
Patent Text Reader

Abstract

The invention discloses an annotation sample generation method and device based on a rectangular pattern, and an image processing method and device, and belongs to the technical field of image recognition, and the method comprises the steps: responding to the operation of a user on a target image, and determining the coordinates of three scene points on the target image; determining a first straight line where the top edge of the rectangular textbox is located and a second straight line where the bottom edge of the rectangular textbox is located according to the position relation of the first scene point, the second scene point and the third scene point; according to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, determining perpendicular feet, corresponding to the first straight line, of the three scene points, and according to the position relation among the perpendicular feet, the first straight line and the second straight line, determining coordinates of four vertexes of the rectangular textbox so as to generate the rectangular textbox; according to the rectangular textbox and the target image, the annotation sample is generated, the text boundary rectangular box is automatically generated, the annotation efficiency of the image is improved, the direction of the text in the image is determined, and the quality of the text region slice is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image recognition technology, and in particular to a method for generating labeled samples based on rectangular patterns, an image processing method, a device, a terminal and a storage medium. Background Art

[0002] Text annotation is a process of drawing text bounding boxes and attaching text content in an image based on text detection and recognition technology, and using perspective transformation to cut out the text area from the original image, and using the obtained text area slices as training data sets for the text recognition model. Among them, text detection aims to accurately locate the position of text in an image, and text recognition refers to identifying text information from the position of the located text. The text in the text area slice needs to be ensured to be positive.

[0003] There are two existing methods for text annotation. One is to use a horizontal rectangular box to mark the position of the text, and then manually drag the rotating rectangular box to a suitable rotation angle to obtain the annotation of the rotated rectangular box. This method of text annotation requires first marking the horizontal rectangle and then manually rotating it. If the target text area deviates greatly from the horizontal rectangular area, it is necessary to manually drag the horizontal rectangular box little by little to a suitable rotation angle, and the annotation efficiency is low.

[0004] Another existing text annotation method is to set the four vertices of the box, generate a corresponding quadrilateral around the text area, and generate an annotation for the quadrilateral box; when the quadrilateral area is subsequently perspectively transformed into a horizontal rectangle, the text in the area will be deformed, and the quality of the obtained text area slices will be poor; in addition, this text annotation method cannot determine the direction of the text area during the annotation process, and then after the text area is cut out from the image, the direction of the text cannot be guaranteed, and the quality of the obtained text area slices will be poor. Summary of the invention

[0005] The present application provides a method for generating annotation samples based on rectangular patterns, an image processing method, a device, a terminal and a storage medium, which can realize automatic generation of text boundary rectangular frames, improve the efficiency of image annotation, determine the direction of text in an image, and improve the quality of text area slices.

[0006] The present application provides a method for generating a label sample based on a rectangular pattern, comprising:

[0007] In response to a user's operation on a target image, coordinates of three scene points on the target image are determined; wherein a first scene point and a second scene point of the three scene points are located above an area of ​​text content in the target image; and the third scene point is used to constrain a bottom boundary, or to constrain a bottom boundary and correct left and right boundaries;

[0008] Determine, according to the positional relationship among the first scene point, the second scene point, and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located;

[0009] According to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars corresponding to the three scene points of the first straight line are respectively determined, and according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, the coordinates of the four vertices of the rectangular text box are determined to generate the rectangular text box;

[0010] Generate a labeled sample according to the rectangular text box and the target image.

[0011] The implementation of the rectangular pattern-based annotation sample generation method of the present application has the following effects: the present application uses the coordinates of the three scene points at the preset positions to determine the positions of the four vertices of the four rectangular text boxes, and then automatically generates a text box in the shape of a rotated rectangle (including a special horizontal rectangle), thereby improving the efficiency of image annotation. In addition, the present application determines the top and bottom sides of the rectangular text box, and then determines the direction of the text in the rectangular text box in the process of generating the rectangular text box.

[0012] Further, determining the coordinates of three scene points on the target image also includes:

[0013] If the user inputs the coordinates of more than three scene points, the coordinates of the first three scene points input by the user are obtained according to the order in which the user inputs;

[0014] Wherein, the first scene point and the second scene point are located on the top edge of the initial rectangular frame;

[0015] The initial rectangular frame is set by the user according to the target text of the target image;

[0016] The top edge of the initial rectangular frame is the edge above the target text when looking directly at the target text;

[0017] The distance between the first scene point and the vertex at one end of the top edge is not greater than a first distance;

[0018] The third scene point is located on the bottom edge of the initial rectangular frame;

[0019] The position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge;

[0020] The bottom edge of the initial rectangular frame is the edge below the target text when the target text is viewed face-on.

[0021] Further, the position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge, specifically:

[0022] If the distance between the second scene point and the vertex at the other end of the top edge is not greater than the first distance, the setting range of the third scene point is: any point on the target projection line segment of the bottom edge of the initial rectangular frame; the target projection line segment is a line segment between the projection points of the first scene point and the second scene point on the bottom edge;

[0023] If the distance between the second scene point and the vertex at the other end of the top edge is greater than the first distance, the setting range of the third scene point is: located on the bottom edge of the initial rectangular frame, and the distance from the target vertex is not greater than the second distance; the target vertex and the vertex at one end of the top edge are diagonal vertices of the initial rectangular frame.

[0024] The user of this application sets three scene points according to the above conditions, wherein the first scene point and the second scene point jointly constrain the top boundary of the rectangular text box, and the third scene point constrains the bottom boundary of the rectangular text box. The first scene point, the second scene point and the third scene point jointly constrain the left and right boundaries of the rectangular text box. Therefore, the four vertices of the rectangular text box can be completed according to the three scene points set by the user, and then a rotated rectangular text box that meets the text area requirements can be automatically generated, without manually dragging the horizontal rectangular box to the appropriate rotation angle, thereby improving the efficiency of labeling the target image.

[0025] Further, according to the positional relationship among the first scene point, the second scene point and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located are determined, specifically:

[0026] Connect the first scene point and the second scene point to obtain a first straight line where the top edge of the rectangular text box is located;

[0027] A line parallel to the first straight line is drawn through the third scene point to obtain a second straight line where the bottom edge of the rectangular text box is located.

[0028] Further, according to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars of the three scene points corresponding to the first straight line are determined respectively, specifically:

[0029] Draw a first perpendicular line through the first scene point to the first straight line, and the foot of the perpendicular line is the first foot of the perpendicular line;

[0030] Draw a second perpendicular line through the second scene point to the first straight line, and the foot of the perpendicular line is the second foot of the perpendicular line;

[0031] Draw a third perpendicular line to the first straight line through the third scene point, and the foot of the perpendicular line is the third foot of the perpendicular line.

[0032] Furthermore, the coordinates of the four vertices of the rectangular text box are determined according to the positional relationship between the perpendicular feet, the first straight line and the second straight line, specifically:

[0033] Determine a first vertex and a second vertex on the top edge of the rectangular text box according to the positional relationship between each of the perpendicular feet and the first straight line;

[0034] According to the positional relationship between the first vertex, the second vertex and the second straight line, a third vertex and a fourth vertex on the bottom side of the rectangular text box are determined.

[0035] Further, according to the positional relationship between each of the perpendicular feet and the first straight line, the first vertex and the second vertex on the top edge of the rectangular text box are determined, specifically:

[0036] If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, the longitudinal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0037] The first vertex is the foot of the perpendicular with the largest ordinate value, and the second vertex is the foot of the perpendicular with the smallest ordinate value;

[0038] Or the first vertex is the foot of the perpendicular with the smallest ordinate value, and the second vertex is the foot of the perpendicular with the largest ordinate value;

[0039] If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, the horizontal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0040] The first vertex is the foot of the perpendicular with the largest horizontal coordinate value, and the second vertex is the foot of the perpendicular with the smallest horizontal coordinate value;

[0041] Alternatively, the first vertex is the foot of the perpendicular with the smallest abscissa value, and the second vertex is the foot of the perpendicular with the largest abscissa value.

[0042] Further, according to the positional relationship between the first vertex, the second vertex and the second straight line, the third vertex and the fourth vertex on the bottom side of the rectangular text box are determined, specifically:

[0043] Taking the perpendicular line of the first vertex relative to the first straight line as the third straight line;

[0044] Taking the perpendicular line of the second vertex relative to the first straight line as the fourth straight line;

[0045] Taking the intersection of the second straight line and the third straight line as the third vertex, and obtaining the coordinates of the third vertex;

[0046] The intersection point of the second straight line and the fourth straight line is taken as a fourth vertex, and the coordinates of the fourth vertex are obtained.

[0047] The rectangular pattern-based annotation sample generation method provided in the present application first determines the first straight line where the top edge of the rectangular text box is located and the second straight line where the bottom edge is located according to the three scene points set by the user; then, in combination with the preset rectangular coordinate system, the feet of the perpendiculars of the first straight lines corresponding to the three scene points are respectively determined; according to the positional relationship between each of the perpendicular feet, the first straight line and the second straight line, the four vertices of the rectangular text box are completed to generate the rectangular text box; and then a rotated rectangular text box that meets the text area requirements is automatically generated, and at the same time, the direction of the text in the rectangular text box is determined according to the top edge and the bottom edge of the rectangular text box.

[0048] Furthermore, after determining the third vertex and the fourth vertex on the bottom side of the rectangular text box, the method further includes:

[0049] The distance between the first vertex and the second vertex is taken as the length of the rectangular text box;

[0050] The distance between the first and third vertices is used as the width of the rectangular text box.

[0051] Furthermore, the rectangular text box is generated as follows:

[0052] According to the positional relationship between the first vertex, the second vertex, the third vertex and the fourth vertex of the rectangular text box, the first vertex, the second vertex, the third vertex and the fourth vertex are sorted to obtain a first coordinate point, a second coordinate point, a third coordinate point and a fourth coordinate point in sequence;

[0053] Connecting the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point using a preset component to generate a path;

[0054] The path is instantiated to obtain a rectangular text box.

[0055] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0056] In response to the user's drag modification of the rectangular text box, the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point, the length of the rectangular text box and the width of the rectangular text box are updated.

[0057] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0058] Taking the first coordinate point as the starting point, the first straight line generates a text editing box of a preset size;

[0059] Instantiate the text edit box and monitor whether the text content in the text edit box changes; the text content in the text edit box is input by the user in the text edit box;

[0060] If there is a change, the latest input text content is obtained and displayed in the text edit box;

[0061] The latest input text content is saved as text annotation content.

[0062] The present application allows the generated rectangular text box to be modified by dragging the mouse, and manual fine-tuning can be performed based on the automatically generated rectangular text box, and the coordinate data and size data of the rectangular text box can be updated, thereby improving the efficiency and accuracy of target image annotation.

[0063] Accordingly, the present application also provides an image processing method based on a rectangular pattern, comprising: obtaining a target image, and obtaining a labeled sample corresponding to the target image according to the method for generating a labeled sample based on a rectangular pattern as described in the present application;

[0064] According to the labeled samples, a perspective transformation is performed on the text area within the rectangular text box on the target image to obtain a picture slice.

[0065] Furthermore, according to the annotated sample, a perspective transformation is performed on the text area in the rectangular text box on the target image to obtain a picture slice, specifically:

[0066] The height of the rectangular text box is used as the height of the target rectangle, and the width of the rectangular text box is used as the width of the target rectangle, to generate a coordinate list of the target rectangle;

[0067] The coordinate list includes the coordinates of the four vertices of the target rectangle; the coordinates of the preset vertices of the target rectangle are the origin coordinates; the order relationship of the four vertices is strongly related to the order relationship of the four vertices of the rectangular text box;

[0068] Calculating a perspective transformation matrix according to the coordinate list and the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point to perform perspective transformation on the target image to obtain a text area image within the rectangular text box;

[0069] The text area image is used as a picture slice.

[0070] Furthermore, after performing perspective transformation on the text area in the rectangular text box on the target image to obtain image slices, the method further includes:

[0071] Get the text annotation content corresponding to the image slice;

[0072] Associate the text annotation content with the image slice and save it.

[0073] The implementation of the rectangular pattern-based image processing method of the present application has the following effects: since the text box generated by the present application is a rectangle, the area within the rectangular text box is perspectively transformed into a horizontal rectangle, and the text in the generated image slice can maintain its original shape. In addition, since the present application determines the top and bottom sides of the rectangular text box, when the area within the rectangular text box in the target image is perspectively transformed and sliced, the text in the image slice can maintain the correct direction, thereby improving the quality of the text area slice, so that the obtained text area slice and text annotation content can be used as text recognition data to produce a training data set for the text recognition model.

[0074] Accordingly, the present application also provides a rectangular pattern-based annotation sample generation device, comprising: a scene point data acquisition module, a data processing module and an annotation module;

[0075] The scene point data acquisition module is used to respond to the user's operation on the target image and determine the coordinates of three scene points on the target image; wherein the first scene point and the second scene point of the three scene points are located above the area of ​​the text content in the target image; the third scene point is used to constrain the bottom edge boundary, or to constrain the bottom edge boundary and correct the left and right edges;

[0076] The data processing module is used to determine a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located according to the positional relationship among the first scene point, the second scene point and the third scene point;

[0077] The annotation module is used to determine the feet of the perpendiculars corresponding to the three scene points respectively according to the first straight line and the second straight line in combination with a preset rectangular coordinate system, and determine the coordinates of the four vertices of the rectangular text box according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, so as to generate the rectangular text box;

[0078] Generate a labeled sample according to the rectangular text box and the target image.

[0079] The use of the rectangular pattern-based annotation sample generation device of the present application has the following effects: the present application device uses the coordinates of three scene points at preset positions to determine the positions of the four vertices of four rectangular text boxes, and then automatically generates a text box in the shape of a rotated rectangle, thereby improving the efficiency of image annotation. In addition, the present application device determines the top and bottom sides of the rectangular text box, and then determines the direction of the text in the rectangular text box in the process of generating the rectangular text box.

[0080] Accordingly, the present application also provides an image processing device based on a rectangular pattern, comprising: a labeling data acquisition module and a perspective transformation module;

[0081] The annotation data acquisition module is used to acquire a target image, and acquire an annotation sample corresponding to the target image according to the annotation sample generation method based on a rectangular pattern as described in the present invention;

[0082] The perspective transformation module is used to perform perspective transformation on the text area in the rectangular text box on the target image according to the labeled sample to obtain a picture slice.

[0083] The use of the rectangular pattern-based image processing device of the present application has the following effects: since the text box in the annotation sample obtained by the annotation data acquisition module of the present application is a rectangle, the perspective transformation module perspectively transforms the area within the rectangular text box into a horizontal rectangle, and the text in the generated image slice can maintain its original shape. In addition, since the present application determines the top and bottom sides of the rectangular text box, when the perspective transformation module performs perspective transformation slicing on the area within the rectangular text box in the target image, the text in the image slice can maintain the correct direction, thereby improving the quality of the text area slice, so that the obtained text area slice and text annotation content can be used as text recognition data to produce a training data set for the text recognition model.

[0084] Accordingly, the present application also provides a terminal device, comprising: at least one processor and a memory; the memory is used to store program instructions; the processor is used to call and execute the program instructions stored in the memory, so that the terminal device executes the method for generating labeled samples based on rectangular patterns as described in the content of the present invention, or executes the image processing method based on rectangular patterns as described in the content of the present invention.

[0085] Accordingly, the present application also provides a computer-readable storage medium, characterized in that the computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, it controls the device where the computer-readable storage medium is located to execute the method for generating labeled samples based on rectangular patterns as described in the content of the present invention, or to execute the image processing method based on rectangular patterns as described in the content of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0086] Figure 1 It is a flowchart of an embodiment of a method for generating a labeled sample based on a rectangular pattern provided by the present application;

[0087] Figure 2 It is a schematic diagram I of the settings of three scene points provided by this application;

[0088] Figure 3 It is a schematic diagram II of the settings of three scene points provided by this application;

[0089] Figure 4 It is a schematic diagram of the settings of three scene points provided by this application III;

[0090] Figure 5 It is a schematic diagram of calculating the vertices of a rectangular text box provided by this application;

[0091] Figure 6 is a schematic diagram of an existing labeled sample of a rectangular pattern I;

[0092] Figure 7 is a schematic diagram of an existing labeled sample of a rectangular pattern II;

[0093] Figure 8 is a schematic diagram of an existing labeled sample of a rectangular pattern III;

[0094] Fig. 9 is a schematic diagram of an existing labeled sample of a rectangular pattern IV;

[0095] Fig.10 Schematic diagram I of the annotation software interface provided by this application;

[0096] Fig.11 It is a schematic diagram II of the annotation software interface provided by this application;

[0097] Fig.12 is a flow chart of an embodiment of an image processing method based on rectangular patterns provided by the present application;

[0098] Fig.13 It is a structural schematic diagram of an embodiment of a rectangular pattern-based annotation sample generation device provided by the present application;

[0099] Fig.14 It is a structural schematic diagram of an embodiment of an image processing device based on a rectangular pattern provided in the present application. DETAILED DESCRIPTION

[0100] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0101] Embodiment 1

[0102] The method for generating a labeling sample based on a rectangular pattern provided in the embodiment of the present application is applied to labeling software in certain preferred embodiments. The image area in the labeling software is divided into an inner layer and a surface layer, the inner layer is used to store the target image to be labeled, and the surface layer is used to observe the image in the image area. The image area in the labeling software is set with a preset coordinate system.

[0103] In certain preferred embodiments, the annotation software is implemented using PySide6; wherein the inner layer is created using the QGraphicsScene scene, and the surface layer is created using the QGraphicsView view class; and the annotated image is displayed using QGraphicsPixmapItem.

[0104] In certain preferred embodiments, the coordinates used in the internal calculations of the annotation software are all scene coordinates, and the saved annotation data are converted into annotation coordinates. If the coordinate systems corresponding to the annotation coordinates of the target image and the scene coordinates of the target image are different, the mapToItem method is used to calculate the scene coordinates relative to the annotation coordinates of the target image, wherein the coordinate system of the annotation coordinates uses the vertex in the upper left corner of the target image as the origin, with the positive x direction to the right horizontally and the positive y direction to the bottom vertically.

[0105] Please refer to Figure 1 , a method for generating a label sample based on a rectangular pattern provided in an embodiment of the present application, comprising steps S101-S104:

[0106] Step S101: In response to a user's operation on a target image, coordinates of three scene points on the target image are determined; wherein a first scene point and a second scene point of the three scene points are located above an area of ​​text content in the target image; and the third scene point is used to constrain a bottom boundary, or to constrain a bottom boundary and correct left and right boundaries;

[0107] Furthermore, the determining the coordinates of three scene points on the target image further includes:

[0108] If the user inputs the coordinates of more than three scene points, the coordinates of the first three scene points input by the user are obtained according to the order in which the user inputs;

[0109] Wherein, the first scene point and the second scene point are located on the top edge of the initial rectangular frame;

[0110] The initial rectangular frame is set by the user according to the target text of the target image;

[0111] The top edge of the initial rectangular frame is the edge above the target text when looking directly at the target text;

[0112] The distance between the first scene point and the vertex at one end of the top edge is not greater than a first distance;

[0113] The third scene point is located on the bottom edge of the initial rectangular frame;

[0114] The position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge;

[0115] The bottom edge of the initial rectangular frame is the edge below the target text when the target text is viewed face-on.

[0116] Further, the position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge, specifically:

[0117] If the distance between the second scene point and the vertex at the other end of the top edge is not greater than the first distance, the setting range of the third scene point is: any point on the target projection line segment of the bottom edge of the initial rectangular frame; the target projection line segment is a line segment between the projection points of the first scene point and the second scene point on the bottom edge;

[0118] If the distance between the second scene point and the vertex at the other end of the top edge is greater than the first distance, the setting range of the third scene point is: located on the bottom edge of the initial rectangular frame, and the distance from the target vertex is not greater than the second distance; the target vertex and the vertex at one end of the top edge are diagonal vertices of the initial rectangular frame.

[0119] In certain preferred embodiments, the user's operation on the target image is that the user clicks the target image with a mouse, and the scene coordinates of the click position are used as the scene coordinates input by the user, and the scene coordinates of the user's click position are obtained by the scenePos method of the mouse event of PySide6.

[0120] The annotation software obtains the first three user's mouse click events and obtains the three scene coordinates generated by the mouse click events. If the user clicks the target image more than three times with the mouse, that is, the user inputs more than three scene coordinates, the first three scene coordinates are selected.

[0121] The positions and input order of the coordinates of the three scene points set by the user of this application need to meet the preset requirements. In certain preferred embodiments, before the user clicks the target image with the mouse, an imaginary rectangular area for the text area in the target image is the initial rectangle. The initial rectangle is set by the user according to the target text of the target image and is not constructed in the annotation software. Among them, the edge close to the top of the text when looking at the text is the top edge of the initial rectangle, and the edge close to the bottom of the text is the bottom edge of the initial rectangle.

[0122] The three scene points set by the user are the first scene point, the second scene point and the third scene point in sequence.

[0123] The first scene point and the second scene point are on a straight line where the top edge of the initial rectangle is located, and are used to constrain the top edge boundary of the rectangular text box; the order of the first scene point and the second scene point can be interchanged.

[0124] The third scene point is on the straight line where the bottom edge of the initial rectangle is located, and is used to constrain the bottom edge boundary of the rectangular text box and to correct the left and right edges of the rectangular text box.

[0125] In some preferred embodiments, the first scene point and the second scene point are on a straight line where the top edge of the initial rectangle is located, the distance between the first scene point and the vertex at one end of the top edge is not greater than the first distance, and the distance between the second scene point and the vertex at the other end of the top edge is not greater than the first distance, that is, the first scene point and the second scene point are respectively close to the two vertices of the top edge. In this case, any point on the target projection line segment of the bottom edge of the initial rectangular frame can be selected as the third scene point; the target projection line segment is the line segment between the projection points of the first scene point and the second scene point on the bottom edge.

[0126] For example, please refer to Figure 2 and Figure 3 , Figure 2 and Figure 3 Provide a specific example of setting a first scene point a, a second scene point b, and a third scene point c, respectively, wherein the first scene point a is close to the initial rectangle ( Figure 2 and Figure 3 The left vertex on the top edge of the initial rectangle is not drawn, and the second scene point b is close to the right vertex on the top edge; the third scene point c is one of the points in the line segment between the projection points of the first scene point a and the second scene point b on the bottom edge.

[0127] As a preferred implementation scheme, the first scene point and the second scene point jointly constrain the top edge of the rectangular text box, and at the same time, constrain the left and right edges of the rectangular text box; the third scene point constrains the bottom edge of the rectangular text box.

[0128] In some preferred embodiments, the first scene point and the second scene point are on the straight line where the top edge of the initial rectangle is located, the distance between the first scene point and the vertex at one end of the top edge is not greater than the first distance, and the distance between the second scene point and the vertex at the other end of the top edge is greater than the first distance, that is, the first scene point is close to one of the vertices in the top edge, and the second scene point is not close to the other vertex in the top edge. It should be noted that it is required that at least one of the first scene point and the second scene point is close to one of the two vertices of the top edge. In this case, it is required that the distance between the third scene point and the target vertex is not greater than the second distance; the target vertex and the vertex at one end of the top edge are diagonal vertices of the initial rectangular box.

[0129] For example, please refer to Figure 4 ( Figure 4 The initial rectangle is not drawn), Figure 4 Another specific implementation scheme for setting the first scene point a, the second scene point b, and the third scene point c is provided, wherein the first scene point a is close to the left vertex on the top edge, but the second scene point b is not close to the right vertex on the top edge. The third scene point c is required to be as close to the right vertex on the bottom edge as possible to constrain the bottom edge of the rectangular text box and correct the right edge of the rectangular text box at the same time.

[0130] As one of the preferred implementation schemes, the first scene point and the second scene point jointly constrain the top boundary of the rectangular text box, and at the same time, the first scene point constrains the left boundary of the rectangular text box; the third scene point constrains the bottom boundary of the rectangular text box, and at the same time, the third scene point corrects the right boundary of the rectangular text box.

[0131] The user of this application sets three scene points according to the above conditions, wherein the first scene point and the second scene point jointly constrain the top boundary of the rectangular text box, and the third scene point constrains the bottom boundary of the rectangular text box. The first scene point, the second scene point and the third scene point jointly constrain the left and right boundaries of the rectangular text box. Therefore, the four vertices of the rectangular text box can be completed according to the three scene points set by the user, and then a rotated rectangular text box that meets the text area requirements can be automatically generated, without manually dragging the horizontal rectangular box to the appropriate rotation angle, thereby improving the efficiency of labeling the target image.

[0132] Step S102: determining a first straight line on which the top edge of the rectangular text box is located and a second straight line on which the bottom edge is located according to the positional relationship among the first scene point, the second scene point and the third scene point;

[0133] Further, according to the positional relationship among the first scene point, the second scene point and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located are determined, specifically:

[0134] Connect the first scene point and the second scene point to obtain a first straight line where the top edge of the rectangular text box is located;

[0135] A line parallel to the first straight line is drawn through the third scene point to obtain a second straight line where the bottom edge of the rectangular text box is located.

[0136] Step S103: according to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars corresponding to the three scene points are respectively determined, and according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, the coordinates of the four vertices of the rectangular text box are determined to generate the rectangular text box;

[0137] Further, according to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars of the three scene points corresponding to the first straight line are determined respectively, specifically:

[0138] Draw a first perpendicular line through the first scene point to the first straight line, and the foot of the perpendicular line is the first foot of the perpendicular line;

[0139] Draw a second perpendicular line through the second scene point to the first straight line, and the foot of the perpendicular line is the second foot of the perpendicular line;

[0140] Draw a third perpendicular line to the first straight line through the third scene point, and the foot of the perpendicular line is the third foot of the perpendicular line.

[0141] Furthermore, the coordinates of the four vertices of the rectangular text box are determined according to the positional relationship between the perpendicular feet, the first straight line and the second straight line, specifically:

[0142] Determine a first vertex and a second vertex on the top edge of the rectangular text box according to the positional relationship between each of the perpendicular feet and the first straight line;

[0143] According to the positional relationship between the first vertex, the second vertex and the second straight line, a third vertex and a fourth vertex on the bottom side of the rectangular text box are determined.

[0144] Further, according to the positional relationship between each of the perpendicular feet and the first straight line, the first vertex and the second vertex on the top edge of the rectangular text box are determined, specifically:

[0145] If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, the longitudinal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0146] The first vertex is the foot of the perpendicular with the largest ordinate value, and the second vertex is the foot of the perpendicular with the smallest ordinate value;

[0147] Or the first vertex is the foot of the perpendicular with the smallest ordinate value, and the second vertex is the foot of the perpendicular with the largest ordinate value;

[0148] If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, the horizontal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0149] The first vertex is the foot of the perpendicular with the largest horizontal coordinate value, and the second vertex is the foot of the perpendicular with the smallest horizontal coordinate value;

[0150] Alternatively, the first vertex is the foot of the perpendicular with the smallest abscissa value, and the second vertex is the foot of the perpendicular with the largest abscissa value.

[0151] Further, according to the positional relationship between the first vertex, the second vertex and the second straight line, the third vertex and the fourth vertex on the bottom side of the rectangular text box are determined, specifically:

[0152] Taking the perpendicular line of the first vertex relative to the first straight line as the third straight line;

[0153] Taking the perpendicular line of the second vertex relative to the first straight line as the fourth straight line;

[0154] Taking the intersection of the second straight line and the third straight line as the third vertex, and obtaining the coordinates of the third vertex;

[0155] The intersection point of the second straight line and the fourth straight line is taken as a fourth vertex, and the coordinates of the fourth vertex are obtained.

[0156] Furthermore, after determining the third vertex and the fourth vertex on the bottom side of the rectangular text box, the method further includes:

[0157] The distance between the first vertex and the second vertex is taken as the length of the rectangular text box;

[0158] The distance between the first and third vertices is used as the width of the rectangular text box.

[0159] In certain preferred embodiments, please refer to Figure 5 The preset rectangular coordinate system takes the vertex of the upper left corner of the target image as the origin, the horizontal axis is horizontal to the right, and the vertical axis is vertically downward.

[0160] A first scene point a, a second scene point b, and a third scene point c are known, and the first scene point a and the second scene point b are connected to obtain a first straight line where the top edge of the rectangular text box is located.

[0161] A line parallel to the first straight line is drawn through the third scene point c to obtain a second straight line where the bottom edge of the rectangular text box is located.

[0162] A first perpendicular line is drawn through the first scene point a to the first straight line, and the foot of the perpendicular line is the first perpendicular foot P1.

[0163] A second perpendicular line is drawn to the first straight line through the second scene point b, and the foot of the perpendicular line is the second foot of the perpendicular line P2.

[0164] A third perpendicular line is drawn through the third scene point c to the first straight line, and the foot of the perpendicular line is the third perpendicular foot P3.

[0165] If the first straight line is parallel to the longitudinal axis, then among the first perpendicular foot, the second perpendicular foot and the third perpendicular foot, the perpendicular foot with the largest longitudinal coordinate value is taken as the first vertex, and the perpendicular foot with the smallest longitudinal coordinate value is taken as the second vertex.

[0166] If the first straight line is not parallel to the longitudinal axis, then among the first perpendicular foot, the second perpendicular foot and the third perpendicular foot, the perpendicular foot with the largest horizontal coordinate value is taken as the first vertex, and the perpendicular foot with the smallest horizontal coordinate value is taken as the second vertex.

[0167] exist Figure 5 In the figure, the first straight line where the top edge is located is not parallel to the longitudinal axis. Among the first perpendicular foot P1, the second perpendicular foot P2 and the third perpendicular foot P3, the vertical coordinate value of the first perpendicular foot P1 is the largest. The first perpendicular foot P1 is taken as the first vertex P_MAX, that is, Figure 5 Point b in the middle; the ordinate value of the second perpendicular foot P2 is the smallest, and the second perpendicular foot P2 is taken as the second vertex P_MIN, that is Figure 5 Point a in .

[0168] The perpendicular line of the first perpendicular foot P1 relative to the first straight line is the third straight line, and the perpendicular line of the second perpendicular foot P2 relative to the first straight line is the fourth straight line.

[0169] This application uses the intersection of the second straight line where the bottom edge is located and the third straight line as the third vertex P_PA_MAX, that is, Figure 5 In this application, the intersection of the second straight line where the bottom edge is located and the fourth straight line is taken as the fourth vertex P_PA_MIN, that is, Figure 5 Point e in .

[0170] The rectangular pattern-based annotation sample generation method provided in the present application first determines the first straight line where the top edge of the rectangular text box is located and the second straight line where the bottom edge is located according to the three scene points set by the user; then, in combination with the preset rectangular coordinate system, the feet of the perpendiculars of the first straight lines corresponding to the three scene points are respectively determined; according to the positional relationship between each of the perpendicular feet, the first straight line and the second straight line, the four vertices of the rectangular text box are completed to generate the rectangular text box; and then a rotated rectangular text box that meets the text area requirements is automatically generated, and at the same time, the direction of the text in the rectangular text box is determined according to the top edge and the bottom edge of the rectangular text box.

[0171] Furthermore, the rectangular text box is generated as follows:

[0172] According to the positional relationship between the first vertex, the second vertex, the third vertex and the fourth vertex of the rectangular text box, the first vertex, the second vertex, the third vertex and the fourth vertex are sorted to obtain a first coordinate point, a second coordinate point, a third coordinate point and a fourth coordinate point in sequence;

[0173] Connecting the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point using a preset component to generate a path;

[0174] The path is instantiated to obtain a rectangular text box.

[0175] In some preferred embodiments, QPainterPath is used to load the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point. When instantiating QPainterPath, the parameter (startPoint) is passed in as the fourth coordinate point, and the lineTo method is used to connect the four coordinate points in sequence starting from the first coordinate point to generate a path. The setPath method of QGraphicsPathItem is used to load the generated path.

[0176] In addition to the QGraphicsPathItem component in the software interface library PySide, tools for loading the path formed by four coordinate points include but are not limited to: loading tools in PyQt, etc. PySide and PyQt are both Python implementations of QT, which is a cross-platform C++ library that can be used to develop GUI applications.

[0177] In certain preferred embodiments, the preset rectangular coordinate system takes the vertex at the upper left corner of the target image as the origin, with the horizontal axis pointing horizontally to the right and the vertical axis pointing vertically downward.

[0178] According to the positional relationship between the first vertex, the second vertex, the third vertex and the fourth vertex of the rectangular text box, the first vertex, the second vertex, the third vertex and the fourth vertex are sorted to obtain the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point in sequence, specifically:

[0179] If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, and the abscissa value of the second vertex is greater than the abscissa value of the fourth vertex, then the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point are, in order: the second vertex, the fourth vertex, the third vertex and the first vertex;

[0180] If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, and the abscissa value of the second vertex is less than the abscissa value of the fourth vertex, then the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point are, in order: the first vertex, the third vertex, the fourth vertex and the second vertex;

[0181] If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, and the longitudinal coordinate value of the second vertex is less than the longitudinal coordinate value of the fourth vertex, then the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point are: the second vertex, the fourth vertex, the third vertex and the first vertex in sequence;

[0182] If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, and the longitudinal coordinate value of the second vertex is greater than the longitudinal coordinate value of the fourth vertex, then the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point are respectively: the second vertex, the fourth vertex, the third vertex and the first vertex.

[0183] For example, please refer to Figure 5 , Figure 5 The four vertices of the provided rectangular text box are point a, point b, point e and point f.

[0184] The order of the four vertices of the rectangular text box, that is, the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point of the rectangular text box are: point a, point e, point f and point b.

[0185] It should be noted that the above-mentioned vertex sorting method is only used as a sorting method in certain preferred implementation schemes. The present application can set different vertex sorting methods, for example, a vertex sorting method that takes one of the vertices as the starting point and sorts clockwise or counterclockwise.

[0186] The present application sorts the four vertices of the rectangular text box so that when the rectangular text box is instantiated, the four vertices can be connected in order.

[0187] In addition, the coordinate list of the target rectangle generated in the rectangular pattern-based image processing method provided by the present application includes the coordinates of the four vertices of the target rectangle.

[0188] This application needs to set a one-to-one correspondence between the four vertices of the rectangular text box and the four vertices of the target rectangle, so the four vertices of the rectangular text box need to be sorted to correspond to the order of the four vertices of the target rectangle in the coordinate list of the target rectangle. Furthermore, the rectangular pattern-based image processing method provided by this application performs perspective transformation on the area within the rectangular text box according to the order of the four vertices of the rectangular text box and the coordinate list of the target rectangle, so that the text in the generated image slice is not deformed and the correct direction of the text is guaranteed.

[0189] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0190] In response to the user's drag modification of the rectangular text box, the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point, the length of the rectangular text box and the width of the rectangular text box are updated.

[0191] In certain preferred embodiments, the present application allows the generated rectangular text box to be modified by dragging the mouse, and manual fine-tuning can be performed based on the automatically generated rectangular text box, specifically by QGraphicsItem to implement the modification of the rectangular text box by dragging the mouse.

[0192] After the rectangular text box is modified by dragging the mouse, a new rectangular text box is obtained, and four new scene coordinates are obtained. The annotation software needs to convert the four new scene coordinates into annotation coordinates to obtain the four annotation coordinates of the rectangular text box. The annotation software updates the coordinates of the first coordinate point, the second coordinate point, the third coordinate point, and the fourth coordinate point, the length of the rectangular text box, and the width of the rectangular text box according to the four annotation coordinates of the rectangular text box.

[0193] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0194] Taking the first coordinate point as the starting point, the first straight line generates a text editing box of a preset size;

[0195] Instantiate the text edit box and monitor whether the text content in the text edit box changes; the text content in the text edit box is input by the user in the text edit box;

[0196] If there is a change, the latest input text content is obtained and displayed in the text edit box;

[0197] The latest input text content is saved as text annotation content.

[0198] In some preferred embodiments, this application uses its setPos method, and the incoming parameter is the first coordinate point of the four scene coordinates, and the position of the first coordinate point is used as the starting point to instantiate the text editing box QTextDocument. After instantiation, monitor whether the text content in the QTextDocument changes. If it changes, get the new text content. The default value is empty. The monitoring method is provided by the contentsChanged signal of QTextDocument.

[0199] Step S104: Generate a labeled sample according to the rectangular text box and the target image.

[0200] Please refer to Figure 6 The prior art uses a horizontal rectangular frame to mark the sample and records the text content above the horizontal rectangular frame. However, the text in the sample is tilted, and the horizontal rectangular area deviates greatly from the text area.

[0201] Please refer to Figure 7 In the prior art, a sample of annotating a rectangular pattern is firstly marked with a horizontal rectangular frame, and then the rotating rectangular frame is dragged little by little to a suitable rotation angle to obtain a rotated rectangular annotation. However, the text in the sample is tilted, and the prior art requires manual adjustment of the rotation angle of the rectangular frame, resulting in low annotation efficiency.

[0202] Please refer to Figure 8 The existing rectangular pattern annotation sample is a prior art that sets four points around the text area to obtain a quadrilateral text box. If the obtained quadrilateral text box is not a rectangle, the perspective transformation of the text area in the quadrilateral text box will transform the quadrilateral into a horizontal rectangle, resulting in text deformation.

[0203] Please refer to Fig. 9 The prior art first sets four points around the text area to obtain a quadrilateral text box, and then finds the minimum circumscribed rectangle of the quadrilateral as the rectangular text box. The prior art cannot guarantee the direction of the text in the text area within the text box.

[0204] The present application generates a rectangular text box at the position of the target image text area in the annotation software interface to identify the area where the text is located in the image, so that the image processing method based on rectangular patterns provided by the present application performs perspective transformation on the area within the rectangular text box to generate image slices.

[0205] In addition, the present application sets a text editing box at the vertex of the upper left corner of the rectangular text box in the annotation software interface, and monitors the text content in the text editing box to obtain the text annotation content corresponding to the image slice, so as to use the obtained text area slice as text recognition data to produce a training data set for the text recognition model.

[0206] Please refer to Fig.10 If the annotation software detects that the text content in the text edit box is "railway height 320mm", the text edit box will display the text content in the text edit box, and the text in the text edit box will not be empty.

[0207] Please refer to Fig.11 If the annotation software does not detect any text content in the text edit box, the text in the text edit box is empty.

[0208] Implementing the embodiments of the present application has the following effects:

[0209] The implementation of the rectangular pattern-based annotation sample generation method of the present application has the following effects: the present application uses the coordinates of three scene points at preset positions to determine the positions of the four vertices of the four rectangular text boxes, and then automatically generates a text box in the shape of a rotated rectangle, thereby improving the efficiency of image annotation. In addition, the present application determines the top and bottom sides of the rectangular text box, and then determines the direction of the text in the rectangular text box in the process of generating the rectangular text box.

[0210] Embodiment 2

[0211] Please refer to Fig.12 , an image processing method based on a rectangular pattern provided in an embodiment of the present application, comprising steps S201-S202:

[0212] Step S201: acquiring a target image, and acquiring a labeled sample corresponding to the target image according to the method for generating a labeled sample based on a rectangular pattern as described in the first embodiment;

[0213] Step S202: performing perspective transformation on the text area within the rectangular text box on the target image according to the labeled sample to obtain image slices.

[0214] Furthermore, according to the annotated sample, a perspective transformation is performed on the text area in the rectangular text box on the target image to obtain a picture slice, specifically:

[0215] The height of the rectangular text box is used as the height of the target rectangle, and the width of the rectangular text box is used as the width of the target rectangle, to generate a coordinate list of the target rectangle;

[0216] The coordinate list includes the coordinates of the four vertices of the target rectangle; the coordinates of the preset vertices of the target rectangle are the origin coordinates; the order relationship of the four vertices is strongly related to the order relationship of the four vertices of the rectangular text box;

[0217] Calculating a perspective transformation matrix according to the coordinate list and the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point to perform perspective transformation on the target image to obtain a text area image within the rectangular text box;

[0218] The text area image is used as a picture slice.

[0219] In some preferred embodiments, the present application uses the getPerspectiveTransform method of opencv-python to calculate the perspective transformation matrix.

[0220] The order of the coordinate points in the coordinate list is strongly related to the order of the coordinates of the four vertices of the rectangular text box obtained in the first embodiment.

[0221] For example, please refer to Figure 5 , Figure 5 The four vertices of the provided rectangular text box are point a, point e, point f and point b in order.

[0222] Then the list of the four coordinate points of the target rectangle is [[0,0],[0,rect_height],[rect_width,rect_height],[rect_width,0]].

[0223] Among them, rect_height is the height of the rectangular text box, and rect_width is the width of the rectangular text box.

[0224] Furthermore, after performing perspective transformation on the text area in the rectangular text box on the target image to obtain image slices, the method further includes:

[0225] Get the text annotation content corresponding to the image slice;

[0226] Associate the text annotation content with the image slice and save it.

[0227] Implementing the embodiments of the present application has the following effects:

[0228] The implementation of the rectangular pattern-based image processing method of the present application has the following effects: since the text box generated by the present application is a rectangle, the area within the rectangular text box is perspectively transformed into a horizontal rectangle, and the text in the generated image slice can maintain its original shape. In addition, since the present application determines the top and bottom sides of the rectangular text box, when the area within the rectangular text box in the target image is perspectively transformed and sliced, the text in the image slice can maintain the correct direction, thereby improving the quality of the text area slice, so that the obtained text area slice can be used as text recognition data to produce a training data set for the text recognition model.

[0229] Embodiment 3

[0230] Please refer to Fig.13 , a rectangular pattern-based annotation sample generation device provided in an embodiment of the present application, comprising: a scene point data acquisition module 301, a data processing module 302 and an annotation module 303;

[0231] The scene point data acquisition module 301 is used to respond to the user's operation on the target image and determine the coordinates of three scene points on the target image; wherein the first scene point and the second scene point of the three scene points are located above the area of ​​the text content in the target image; the third scene point is used to constrain the bottom boundary, or to constrain the bottom boundary and correct the left and right boundaries;

[0232] The data processing module 302 is used to determine a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located according to the positional relationship among the first scene point, the second scene point and the third scene point;

[0233] The annotation module 303 is used to determine the feet of the perpendiculars corresponding to the first straight line of each of the three scene points according to the first straight line and the second straight line in combination with a preset rectangular coordinate system, and determine the coordinates of the four vertices of the rectangular text box according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, so as to generate the rectangular text box;

[0234] Generate a labeled sample according to the rectangular text box and the target image.

[0235] Furthermore, the determining the coordinates of three scene points on the target image further includes:

[0236] If the user inputs the coordinates of more than three scene points, the coordinates of the first three scene points input by the user are obtained according to the order in which the user inputs;

[0237] Wherein, the first scene point and the second scene point are located on the top edge of the initial rectangular frame;

[0238] The initial rectangular frame is set by the user according to the target text of the target image;

[0239] The top edge of the initial rectangular frame is the edge above the target text when looking directly at the target text;

[0240] The distance between the first scene point and the vertex at one end of the top edge is not greater than a first distance;

[0241] The third scene point is located on the bottom edge of the initial rectangular frame;

[0242] The position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge;

[0243] The bottom edge of the initial rectangular frame is the edge below the target text when the target text is viewed face-on.

[0244] Further, the position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge, specifically:

[0245] If the distance between the second scene point and the vertex at the other end of the top edge is not greater than the first distance, the setting range of the third scene point is: any point on the target projection line segment of the bottom edge of the initial rectangular frame; the target projection line segment is a line segment between the projection points of the first scene point and the second scene point on the bottom edge;

[0246] If the distance between the second scene point and the vertex at the other end of the top edge is greater than the first distance, the setting range of the third scene point is: located on the bottom edge of the initial rectangular frame, and the distance from the target vertex is not greater than the second distance; the target vertex and the vertex at one end of the top edge are diagonal vertices of the initial rectangular frame.

[0247] Further, according to the positional relationship among the first scene point, the second scene point and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located are determined, specifically:

[0248] Connect the first scene point and the second scene point to obtain a first straight line where the top edge of the rectangular text box is located;

[0249] A line parallel to the first straight line is drawn through the third scene point to obtain a second straight line where the bottom edge of the rectangular text box is located.

[0250] Further, according to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars of the three scene points corresponding to the first straight line are determined respectively, specifically:

[0251] Draw a first perpendicular line through the first scene point to the first straight line, and the foot of the perpendicular line is the first foot of the perpendicular line;

[0252] Draw a second perpendicular line through the second scene point to the first straight line, and the foot of the perpendicular line is the second foot of the perpendicular line;

[0253] Draw a third perpendicular line to the first straight line through the third scene point, and the foot of the perpendicular line is the third foot of the perpendicular line.

[0254] Furthermore, the coordinates of the four vertices of the rectangular text box are determined according to the positional relationship between the perpendicular feet, the first straight line and the second straight line, specifically:

[0255] Determine a first vertex and a second vertex on the top edge of the rectangular text box according to the positional relationship between each of the perpendicular feet and the first straight line;

[0256] According to the positional relationship between the first vertex, the second vertex and the second straight line, a third vertex and a fourth vertex on the bottom side of the rectangular text box are determined.

[0257] Further, according to the positional relationship between each of the perpendicular feet and the first straight line, the first vertex and the second vertex on the top edge of the rectangular text box are determined, specifically:

[0258] If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, the longitudinal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0259] The first vertex is the foot of the perpendicular with the largest ordinate value, and the second vertex is the foot of the perpendicular with the smallest ordinate value;

[0260] Or the first vertex is the foot of the perpendicular with the smallest ordinate value, and the second vertex is the foot of the perpendicular with the largest ordinate value;

[0261] If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, the horizontal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex;

[0262] The first vertex is the foot of the perpendicular with the largest horizontal coordinate value, and the second vertex is the foot of the perpendicular with the smallest horizontal coordinate value;

[0263] Alternatively, the first vertex is the foot of the perpendicular with the smallest abscissa value, and the second vertex is the foot of the perpendicular with the largest abscissa value.

[0264] Further, according to the positional relationship between the first vertex, the second vertex and the second straight line, the third vertex and the fourth vertex on the bottom side of the rectangular text box are determined, specifically:

[0265] Taking the perpendicular line of the first vertex relative to the first straight line as the third straight line;

[0266] Taking the perpendicular line of the second vertex relative to the first straight line as the fourth straight line;

[0267] Taking the intersection of the second straight line and the third straight line as the third vertex, and obtaining the coordinates of the third vertex;

[0268] The intersection point of the second straight line and the fourth straight line is taken as a fourth vertex, and the coordinates of the fourth vertex are obtained.

[0269] Furthermore, after determining the third vertex and the fourth vertex on the bottom side of the rectangular text box, the method further includes:

[0270] The distance between the first vertex and the second vertex is taken as the length of the rectangular text box;

[0271] The distance between the first and third vertices is used as the width of the rectangular text box.

[0272] Furthermore, the rectangular text box is generated as follows:

[0273] According to the positional relationship between the first vertex, the second vertex, the third vertex and the fourth vertex of the rectangular text box, the first vertex, the second vertex, the third vertex and the fourth vertex are sorted to obtain a first coordinate point, a second coordinate point, a third coordinate point and a fourth coordinate point in sequence;

[0274] Connecting the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point using a preset component to generate a path;

[0275] The path is instantiated to obtain a rectangular text box.

[0276] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0277] In response to the user's drag modification of the rectangular text box, the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point, the length of the rectangular text box and the width of the rectangular text box are updated.

[0278] Furthermore, after instantiating the path to obtain a rectangular text box, the method further includes:

[0279] Taking the first coordinate point as the starting point, the first straight line generates a text editing box of a preset size;

[0280] Instantiate the text edit box and monitor whether the text content in the text edit box changes; the text content in the text edit box is input by the user in the text edit box;

[0281] If there is a change, the latest input text content is obtained and displayed in the text edit box;

[0282] The latest input text content is saved as text annotation content.

[0283] The above-mentioned rectangular pattern-based annotated sample generation device can implement the rectangular pattern-based annotated sample generation method of the above-mentioned method embodiment. The options in the above-mentioned method embodiment are also applicable to this embodiment and will not be described in detail here. The rest of the contents of the embodiment of this application can refer to the contents of the above-mentioned method embodiment, and will not be repeated in this embodiment.

[0284] The use of the rectangular pattern-based annotation sample generation device of the present application has the following effects: the present application device uses the coordinates of three scene points at preset positions to determine the positions of the four vertices of four rectangular text boxes, and then automatically generates a text box in the shape of a rotated rectangle, thereby improving the efficiency of image annotation. In addition, the present application device determines the top and bottom sides of the rectangular text box, and then determines the direction of the text in the rectangular text box in the process of generating the rectangular text box.

[0285] Embodiment 4

[0286] Please refer to Fig.14 , an image processing device based on a rectangular pattern provided in an embodiment of the present application, comprising: a labeling data acquisition module 401 and a perspective transformation module 402;

[0287] The annotation data acquisition module 401 is used to acquire a target image, and acquire an annotation sample corresponding to the target image according to the annotation sample generation method based on a rectangular pattern as described in the first embodiment;

[0288] The perspective transformation module 402 is used to perform perspective transformation on the text area in the rectangular text box on the target image according to the labeled sample to obtain a picture slice.

[0289] Furthermore, according to the annotated sample, a perspective transformation is performed on the text area in the rectangular text box on the target image to obtain a picture slice, specifically:

[0290] The height of the rectangular text box is used as the height of the target rectangle, and the width of the rectangular text box is used as the width of the target rectangle, to generate a coordinate list of the target rectangle;

[0291] The coordinate list includes the coordinates of the four vertices of the target rectangle; the coordinates of the preset vertices of the target rectangle are the origin coordinates; the order relationship of the four vertices is strongly related to the order relationship of the four vertices of the rectangular text box;

[0292] Calculating a perspective transformation matrix according to the coordinate list and the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point to perform perspective transformation on the target image to obtain a text area image within the rectangular text box;

[0293] The text area image is used as a picture slice.

[0294] Furthermore, after performing perspective transformation on the text area in the rectangular text box on the target image according to the labeled sample to obtain the image slice, the method further includes:

[0295] Get the text annotation content corresponding to the image slice;

[0296] Associate the text annotation content with the image slice and save it.

[0297] The above-mentioned image processing device based on rectangular pattern can implement the image processing method based on rectangular pattern of the above-mentioned method embodiment. The options in the above-mentioned method embodiment are also applicable to this embodiment and will not be described in detail here. The rest of the contents of the embodiment of the present application can refer to the contents of the above-mentioned method embodiment, and will not be repeated in this embodiment.

[0298] The use of the rectangular pattern-based image processing device of the present application has the following effects: since the text box in the annotation sample obtained by the annotation data acquisition module of the present application is a rectangle, the perspective transformation module perspectively transforms the area within the rectangular text box into a horizontal rectangle, and the text in the generated image slice can maintain its original shape. In addition, since the present application determines the top and bottom sides of the rectangular text box, when the perspective transformation module performs perspective transformation slicing on the area within the rectangular text box in the target image, the text in the image slice can maintain the correct direction, thereby improving the quality of the text area slice, so that the obtained text area slice and text annotation content can be used as text recognition data to produce a training data set for the text recognition model.

[0299] Embodiment 5

[0300] Accordingly, the present application also provides a terminal device comprising: at least one processor and a memory; wherein the memory is used to store program instructions; the processor is used to call and execute the program instructions stored in the memory, so that the terminal device executes the method for generating labeled samples based on rectangular patterns as described in Example 1, or executes the image processing method based on rectangular patterns as described in Example 2.

[0301] In some embodiments, the terminal device may include: various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, and portable wearable devices.

[0302] The present application runs the rectangular pattern-based annotation sample generation method described in Example 1 in the form of a program in a terminal device, or runs the rectangular pattern-based image processing method described in Example 2 in the form of a program in a terminal device. The terminal device may include: various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, which can run on different systems and different application platforms to perform text annotation in different scenarios, and have stronger scalability.

[0303] Embodiment 6

[0304] Accordingly, the present application also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the rectangular pattern-based annotation sample generation method or the rectangular pattern-based image processing method as described in any one of the above embodiments.

[0305] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the terminal device.

[0306] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.

[0307] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device.

[0308] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the terminal device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the mobile terminal, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0309] Wherein, if the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0310] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims

1. A method for generating labeled samples based on rectangular patterns, It is characterized in that include: In response to a user's operation on a target image, coordinates of three scene points on the target image are determined; wherein a first scene point and a second scene point of the three scene points are located above an area of ​​text content in the target image; and the third scene point is used to constrain a bottom boundary, or to constrain a bottom boundary and correct left and right boundaries; Determine, according to the positional relationship among the first scene point, the second scene point, and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located; According to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars corresponding to the three scene points of the first straight line are respectively determined, and according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, the coordinates of the four vertices of the rectangular text box are determined to generate the rectangular text box; Generate a labeled sample according to the rectangular text box and the target image.

2. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 1, It is characterized in that The determining of the coordinates of three scene points on the target image further includes: If the user inputs the coordinates of more than three scene points, the coordinates of the first three scene points input by the user are obtained according to the order in which the user inputs; Wherein, the first scene point and the second scene point are located on the top edge of the initial rectangular frame; The initial rectangular frame is set by the user according to the target text of the target image; The top edge of the initial rectangular frame is the edge above the target text when looking directly at the target text; The distance between the first scene point and the vertex at one end of the top edge is not greater than a first distance; The third scene point is located on the bottom edge of the initial rectangular frame; The position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge; The bottom edge of the initial rectangular frame is the edge below the target text when the target text is viewed face-on.

3. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 2, It is characterized in that The position of the third scene point is set according to the distance between the second scene point and the vertex at the other end of the top edge, specifically: If the distance between the second scene point and the vertex at the other end of the top edge is not greater than the first distance, the setting range of the third scene point is: any point on the target projection line segment of the bottom edge of the initial rectangular frame; the target projection line segment is a line segment between the projection points of the first scene point and the second scene point on the bottom edge; If the distance between the second scene point and the vertex at the other end of the top edge is greater than the first distance, the setting range of the third scene point is: located on the bottom edge of the initial rectangular frame, and the distance from the target vertex is not greater than the second distance; the target vertex and the vertex at one end of the top edge are diagonal vertices of the initial rectangular frame.

4. The method for generating a labeled sample based on a rectangular pattern according to claim 1, It is characterized in that According to the positional relationship among the first scene point, the second scene point and the third scene point, a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located are determined, specifically: Connect the first scene point and the second scene point to obtain a first straight line where the top edge of the rectangular text box is located; A line parallel to the first straight line is drawn through the third scene point to obtain a second straight line where the bottom edge of the rectangular text box is located.

5. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 4, It is characterized in that According to the first straight line and the second straight line, in combination with a preset rectangular coordinate system, the feet of the perpendiculars of the three scene points corresponding to the first straight line are determined respectively, specifically: Draw a first perpendicular line through the first scene point to the first straight line, and the foot of the perpendicular line is the first foot of the perpendicular line; Draw a second perpendicular line through the second scene point to the first straight line, and the foot of the perpendicular line is the second foot of the perpendicular line; Draw a third perpendicular line to the first straight line through the third scene point, and the foot of the perpendicular line is the third foot of the perpendicular line.

6. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 5, It is characterized in that According to the positional relationship between each of the perpendicular feet, the first straight line and the second straight line, the coordinates of the four vertices of the rectangular text box are determined, specifically: Determine a first vertex and a second vertex on the top edge of the rectangular text box according to the positional relationship between each of the perpendicular feet and the first straight line; According to the positional relationship between the first vertex, the second vertex and the second straight line, a third vertex and a fourth vertex on the bottom side of the rectangular text box are determined.

7. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 6, It is characterized in that According to the positional relationship between each of the perpendicular feet and the first straight line, the first vertex and the second vertex on the top edge of the rectangular text box are determined, specifically: If the first straight line is parallel to the longitudinal axis of the preset rectangular coordinate system, the longitudinal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex; The first vertex is the foot of the perpendicular with the largest ordinate value, and the second vertex is the foot of the perpendicular with the smallest ordinate value; Or the first vertex is the foot of the perpendicular with the smallest ordinate value, and the second vertex is the foot of the perpendicular with the largest ordinate value; If the first straight line is not parallel to the longitudinal axis of the preset rectangular coordinate system, the horizontal coordinate values ​​of the first perpendicular foot, the second perpendicular foot and the third perpendicular foot are compared to determine the first vertex and the second vertex, and obtain the coordinates of the first vertex and the second vertex; The first vertex is the foot of the perpendicular with the largest horizontal coordinate value, and the second vertex is the foot of the perpendicular with the smallest horizontal coordinate value; Alternatively, the first vertex is the foot of the perpendicular with the smallest abscissa value, and the second vertex is the foot of the perpendicular with the largest abscissa value.

8. The method for generating a labeled sample based on a rectangular pattern as claimed in claim 6, It is characterized in that According to the positional relationship between the first vertex, the second vertex and the second straight line, the third vertex and the fourth vertex on the bottom side of the rectangular text box are determined, specifically: Taking the perpendicular line of the first vertex relative to the first straight line as the third straight line; Taking the perpendicular line of the second vertex relative to the first straight line as the fourth straight line; Taking the intersection of the second straight line and the third straight line as the third vertex, and obtaining the coordinates of the third vertex; The intersection point of the second straight line and the fourth straight line is taken as a fourth vertex, and the coordinates of the fourth vertex are obtained.

9. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 8, It is characterized in that After determining the third vertex and the fourth vertex on the bottom side of the rectangular text box, the method further includes: The distance between the first vertex and the second vertex is taken as the length of the rectangular text box; The distance between the first and third vertices is used as the width of the rectangular text box.

10. The method for generating a labeled sample based on a rectangular pattern according to claim 6, It is characterized in that Generate the rectangular text box, specifically: According to the positional relationship between the first vertex, the second vertex, the third vertex and the fourth vertex of the rectangular text box, the first vertex, the second vertex, the third vertex and the fourth vertex are sorted to obtain a first coordinate point, a second coordinate point, a third coordinate point and a fourth coordinate point in sequence; Connecting the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point using a preset component to generate a path; The path is instantiated to obtain a rectangular text box.

11. A method for generating a labeled sample based on a rectangular pattern as claimed in claim 10, It is characterized in that After instantiating the path to obtain a rectangular text box, the following steps are also included: In response to the user's drag modification of the rectangular text box, the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point, the length of the rectangular text box and the width of the rectangular text box are updated.

12. The method for generating a labeled sample based on a rectangular pattern according to claim 10, It is characterized in that After instantiating the path to obtain a rectangular text box, the following steps are also included: Taking the first coordinate point as the starting point, the first straight line generates a text editing box of a preset size; Instantiate the text edit box and monitor whether the text content in the text edit box changes; the text content in the text edit box is input by the user in the text edit box; If there is a change, the latest input text content is obtained and displayed in the text edit box; The latest input text content is saved as text annotation content.

13. An image processing method based on rectangular patterns, It is characterized in that include: Acquire a target image, and acquire a labeled sample corresponding to the target image according to the method for generating a labeled sample based on a rectangular pattern as described in any one of claims 1 to 12; According to the labeled samples, a perspective transformation is performed on the text area within the rectangular text box on the target image to obtain a picture slice.

14. An image processing method based on rectangular patterns as claimed in claim 13, It is characterized in that According to the labeled sample, a perspective transformation is performed on the text area in the rectangular text box on the target image to obtain a picture slice, specifically: The height of the rectangular text box is used as the height of the target rectangle, and the width of the rectangular text box is used as the width of the target rectangle, to generate a coordinate list of the target rectangle; The coordinate list includes the coordinates of the four vertices of the target rectangle; the coordinates of the preset vertices of the target rectangle are the origin coordinates; the order relationship of the four vertices is strongly related to the order relationship of the four vertices of the rectangular text box; Calculating a perspective transformation matrix according to the coordinate list and the coordinates of the first coordinate point, the second coordinate point, the third coordinate point and the fourth coordinate point to perform perspective transformation on the target image to obtain a text area image within the rectangular text box; The text area image is used as a picture slice.

15. The image processing method based on rectangular pattern as claimed in claim 13, It is characterized in that According to the labeled sample, a perspective transformation is performed on the text area in the rectangular text box on the target image to obtain a picture slice, and the method further includes: Get the text annotation content corresponding to the image slice; Associate the text annotation content with the image slice and save it.

16. A device for generating annotated samples based on rectangular patterns, It is characterized in that include: Scene point data acquisition module, data processing module and annotation module; The scene point data acquisition module is used to respond to the user's operation on the target image and determine the coordinates of three scene points on the target image; wherein the first scene point and the second scene point of the three scene points are located above the area of ​​the text content in the target image; the third scene point is used to constrain the bottom edge boundary, or to constrain the bottom edge boundary and correct the left and right edges; The data processing module is used to determine a first straight line where the top edge of the rectangular text box is located and a second straight line where the bottom edge is located according to the positional relationship among the first scene point, the second scene point and the third scene point; The annotation module is used to determine the feet of the perpendiculars corresponding to the three scene points respectively according to the first straight line and the second straight line in combination with a preset rectangular coordinate system, and determine the coordinates of the four vertices of the rectangular text box according to the positional relationship between the feet of the perpendiculars, the first straight line and the second straight line, so as to generate the rectangular text box; Generate a labeled sample according to the rectangular text box and the target image.

17. An image processing device based on rectangular patterns, It is characterized in that include: Annotation data acquisition module and perspective transformation module; The annotation data acquisition module is used to acquire a target image, and acquire an annotation sample corresponding to the target image according to the annotation sample generation method based on a rectangular pattern according to any one of claims 1 to 12; The perspective transformation module is used to perform perspective transformation on the text area in the rectangular text box on the target image according to the labeled sample to obtain a picture slice.

18. A terminal device, It is characterized in that include: at least one processor and memory; The memory is used to store program instructions; The processor is used to call and execute the program instructions stored in the memory so that the terminal device executes the rectangular pattern-based labeled sample generation method as described in any one of claims 1-12, or executes the rectangular pattern-based image processing method as described in any one of claims 13-15.

19. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored computer program; wherein, when the computer program is run, the device where the computer-readable storage medium is located controls the device to execute the rectangular pattern-based labeled sample generation method as described in any one of claims 1 to 12, or execute the rectangular pattern-based image processing method as described in any one of claims 13 to 15.

Citation Information

Patent Citations

  • All-round view system automatic calibration method, automobile, calibration device and storage medium

    CN107993263A

  • Chinese character sign identification method and device

    CN108629238A

  • Method and device for generating frame selection area of target object

    CN113420753A

  • Image target processing method and device, storage medium and electronic device

    CN114298915A

  • Image processing method and apparatus, device, and storage medium

    WO2022087846A1