Cutting method for enabling SynthText data to be suitable for scanning pen character detection

By performing image binarization and OpenCV library function processing in the SynthText data set, and adjusting the character position for cropping, the problem that the existing data set is not suitable for scanning pen detection is solved, and better character detection effects and adaptability are achieved.

CN118587715APending Publication Date: 2024-09-03INGENIC SEMICON CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310185843.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-01
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

The existing SynthText data set is not suitable for text character detection tasks in scanning pens due to the image height, and direct cropping will cause the boundary to be in the middle of the text, affecting the training of character detection neural networks.

Method used

By obtaining the image text position for binarization, use the OpenCV library to find the outline and rectangular frame, filter rectangles with smaller areas, calculate and adjust the relative position of the characters, and perform slicing and cropping to adapt to the image height of the scanning pen.

Benefits of technology

Making the SynthText data set suitable for scanning pen text detection avoids fine-tuning of the later data set, improves the adaptability of practical applications with high image requirements, and enhances the effect of character detection tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118587715A
    Figure CN118587715A
Patent Text Reader

Abstract

The invention provides a clipping method for enabling SynthText data to be suitable for scanning pen character detection, which comprises the following steps of: S1, acquiring an image character position, and carrying out binaryzation on an image; s2, cutting the image by using the binary image; and S3, calculating the relative position of each character after cutting. According to the method, the SynthText public data set is suitable for the document detection condition, and fine adjustment suitable for small-batch document detection data sets in the later period is not needed. The SynthText data set modified by the method is more suitable for practical application scenes with requirements on image height. And the adaptation to the character detection task in the scanning pen is better.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of OCR text detection and digital image processing, and in particular relates to a cutting method for making SynthText data suitable for scanning pen text detection. Background Art

[0002] Optical character recognition (OCR) technology is widely used in different scenarios, such as street view text recognition, document text recognition and other applications. In order to locate the position of relevant text, a large number of image detection training sets are required. SynthText is a data set for locating text and used as a training set for deep neural network models. It contains images and each character in the image.

[0003] The average image height in the existing SynthText dataset is 800 pixels, while the image height scanned by the scanner is 120 pixels each time. Obviously, the existing SynthText image height is not suitable for the text character detection task in the scanner. Moreover, if the image is directly cut according to the desired height, the cutting boundary may be in the middle of the text, which is not conducive to the training of the character detection neural network.

[0004] In other words, the existing SynthText dataset is a text detection dataset synthesized in natural scenes. Since its height (pixel value) is between 400-1200, it is not suitable for scanned document detection (the height of the scanned document is 120), and the SynthText dataset needs to be cropped.

[0005] In addition, commonly used technical terms in the prior art include:

[0006] SynthText: This is a synthetically generated dataset for training character detection, where word instances are placed in natural scene images while taking into account the scene layout, consisting of 800,000 images. Image segmentation: subdividing a digital image into multiple image sub-regions (collections of pixels).

[0007] OPENCV (Open Source Computer Vision Library): Open source image processing library. Summary of the invention

[0008] In order to solve the above problems, the purpose of this application is: This application solves the problem of cutting images in the SynthText dataset to meet the scanning pen training detection task without damaging the character information in the image.

[0009] Specifically, the present invention provides a method for cropping SynthText data to make it suitable for scanning pen text detection, the method comprising the following steps:

[0010] S1. Get the text position of the image and binarize the image:

[0011] S1.1, convert the pixel value of the text area to 0 according to the bounding box label of the text, so that the text bounding box area is displayed in black, where the SynthText dataset contains the bounding box label of the text;

[0012] S1.2, then assign the area in the image area where the pixel value is greater than 0 to 255, the formula is as follows:

[0013]

[0014] Make the values ​​of non-text box areas all 255, where M ij Represented as pixel value in the area;

[0015] S2. Use the binary image to crop the image:

[0016] S2.1, use the cv2.findContours() function in the OpenCV library to find each contour in the image. The function is as follows:

[0017]

[0018] where countours is a list consisting of n elements, each element i is a list consisting of m i The set of points (x{i,j},y{i,j}) represents the coordinate set of the i-th edge; i and j represent the index of the edge and the index of the point respectively, and x{i,j} and y{i,j} represent the horizontal and vertical coordinates of the j-th point in the i-th edge respectively;

[0019] S2.2, use the cv2.minAreaRect() function in the OpenCV library to calculate the rectangle of each contour. The function is as follows:

[0020] rect=((x0, y0), (w, h), θ),

[0021] Among them, rect is the data structure returned by the cv2.minAreaRect() function, which represents the vertex coordinates, width, height and clockwise rotation angle of the rectangle; (x0, y0) represents the coordinates of the center of the rectangle, (w, h) represents the width and height of the rectangle respectively, and θ is the rotation angle of the rectangle, which represents the counterclockwise rotation angle of the rectangle relative to the horizontal axis;

[0022] S2.3, filtering out rectangles with smaller areas, where the smaller area is less than 1 / 4 of the average area of ​​all rectangles;

[0023] S2.4, use the cv2.boxPoints() function in the OpenCV library to obtain the coordinates of the four vertices of the rectangle [x1y1 x2y2x3y3 x4y4], starting from the upper left corner, respectively (x1, y1), (x2, y2), (x3, y3), (x4, y4); the cv2.boxPoints() function is used to obtain the four vertices of the rectangle: expressed as follows:

[0024] Loop body: for i,contour in enumerate(contours):

[0025] Determine whether i==0 is true: if i==0:

[0026] Continue: continue

[0027] Find the rectangle with the smallest area:

[0028] rect=cv2.minAreaRect(contour)

[0029] Get the vertex coordinates of the minimum rectangle:

[0030] box = cv2.boxPoints(rect)

[0031] Normalize vertex coordinates to integers:

[0032] box = np.int0(box)

[0033] The contours in the above code are obtained by step S2.1;

[0034] S2.5, based on the obtained rectangular frame coordinates, use the slicing operation to crop the image, as shown below:

[0035] x1,y1,x2,y2=box

[0036] Crop the area where the rectangular frame is located

[0037] roi = img[y1:y2,x1:x2];

[0038] S3. Calculate the relative position of each character after cropping:

[0039] According to the distance between the left and upper boundaries of each rectangular box after cropping and the left and upper boundaries of the original image, the coordinate position of each character in the rectangular box is adjusted accordingly:

[0040] Assume that x is a character, the coordinates of the left, top, right, and bottom points in clockwise direction are (x1, y1), (x2, y1), (x2, y2), (x1, y2) respectively;

[0041] Assuming that margin_left and margin_top are the distances from the upper left and upper right of the rectangle containing the character to the original image, respectively, and w and h are the width and height of the cropped image, the coordinates of the left, top, right, and bottom points of the cropped character clockwise are:

[0042] (max(x1-margin_left,0),max(y1-margin_top),0),

[0043] (min(x2-margin_left,w),max(y1-margin_top),0),

[0044] (min(x2-margin_left,w),min(y2-margin_top,h)),

[0045] (max(x1-margin_left,0),min(y2-margin_top,h)).

[0046] The method is suitable for application of OCR in documents.

[0047] The method is applicable to a scanning translator pen.

[0048] Therefore, the advantages of this application are: this method makes the SynthText public dataset suitable for document detection, without the need for fine-tuning of small batch document detection datasets later. The SynthText dataset modified by this method is more suitable for practical application scenarios that require image height. It is better adapted to the character detection task in the scanning translator pen. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.

[0050] Figure 1 This is a schematic diagram of converting the pixel value of the text area to 0 based on the bounding box label of the text.

[0051] Figure 2 This is a schematic diagram of assigning a value of 255 to areas in the image where the pixel value is greater than 0.

[0052] Figure 3 This is a schematic diagram of the pseudo code corresponding to the coordinates of the four vertices of a rectangle using the cv2.boxPoints() function in the OpenCV library.

[0053] Figure 4It is a schematic diagram of obtaining the maximum boundary value and cropping the image according to the coordinate frame.

[0054] Figure 5 It is a schematic diagram of a specific embodiment of the method for calculating the relative position of each character after cropping.

[0055] Figure 6 is a schematic diagram of the process of this method. DETAILED DESCRIPTION

[0056] In order to more clearly understand the technical content and advantages of the present invention, the present invention is now further described in detail in conjunction with the accompanying drawings.

[0057] like Figure 6 As shown, this application describes the application of OCR in documents. A method for cropping SynthText data suitable for scanning pen text detection is proposed, and the main implementation steps of the method are as follows:

[0058] S1. Get the text position of the image and binarize the image:

[0059] S1.1, according to the bounding box label of the text, the pixel value of the text area is converted to 0, so that the text bounding box area is displayed in black. The SynthText dataset contains the bounding box label of the text, such as Figure 1 As shown;

[0060] S1.2, then assign the area in the image area where the pixel value is greater than 0 to 255, the formula is as follows:

[0061] Make the values ​​of non-text box areas all 255, such as Figure 2 As shown;

[0062] S2. Use the binary image to crop the image:

[0063] S2.1, use the cv2.findContours() function in the OpenCV library to find each contour in the image. The function is as follows:

[0064]

[0065] where countours is a list consisting of n elements, each element i is a list consisting of m i The set of points (x{i,j},y{i,j}) represents the coordinate set of the i-th edge; i and j represent the index of the edge and the index of the point respectively, and x{i,j} and y{i,j} represent the horizontal and vertical coordinates of the j-th point in the i-th edge respectively;

[0066] S2.2, use the cv2.minAreaRect() function in the OpenCV library to calculate the rectangle of each contour. The function is as follows:

[0067] rect=((x0, y0), (w, h), θ),

[0068] Among them, rect is the data structure returned by the cv2.minAreaRect() function, which represents the vertex coordinates, width, height and clockwise rotation angle of the rectangle; (x0, y0) represents the coordinates of the center of the rectangle, (w, h) represents the width and height of the rectangle respectively, and θ is the rotation angle of the rectangle, which represents the counterclockwise rotation angle of the rectangle relative to the horizontal axis;

[0069] S2.3, filtering out rectangles with smaller areas, where the smaller area is less than 1 / 4 of the average area of ​​all rectangles;

[0070] S2.4, use the cv2.boxPoints() function in the OpenCV library to get the coordinates of the four vertices of the rectangle [x1y1 x2y2x3y3 x4y4], starting from the upper left corner, they are (x1, y1), (x2, y2), (x3, y3), (x4, y4), and the corresponding pseudo code is as follows Figure 3 As shown;

[0071] S2.5, according to the obtained rectangular frame coordinates, crop the image, such as Figure 4 As shown;

[0072] S3. Calculate the relative position of each character after cropping, such as Figure 5 As shown:

[0073] According to the distance between the left and upper boundaries of each rectangular box after cropping and the left and upper boundaries of the original image, the coordinate position of each character in the rectangular box is adjusted accordingly:

[0074] Assume H is a character, the coordinates of the left, top, right, and bottom points in clockwise direction are (x1, y1), (x2, y2), (x3, y3), and (x4, y4) respectively;

[0075] Assuming that margin_left and margin_top are the distances from the upper left and upper right of the rectangle containing the character to the original image, respectively, and w and h are the width and height of the cropped image, the coordinates of the left, top, right, and bottom points of the cropped character clockwise are:

[0076] (max(x1-margin_left,0),max(y1-margin_top,0)),

[0077] (min(x2-margin_left,w),max(y2-margin_top,0)),

[0078] (min(x3-margin_left,w),min(y3-margin_top,h)),

[0079] (max(x4-margin_left,0),min(y4-margin_top,h)).

[0080] Here the image has a width of w=600 and a height of h=500, margin_left=30, margin_top=50, and the clockwise left, top, right, and bottom coordinates of the character H in the image are: (266,186), (501,186), (501,435), (266,435). After cropping, the clockwise left, top, right, and bottom coordinates are (236,136), (471,136), (471,385), (236,385).

[0081] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for cropping SynthText data to make it suitable for scanning pen text detection, characterized in that: The method comprises the following steps: S1. Get the text position of the image and binarize the image: S1.1, convert the pixel value of the text area to 0 according to the bounding box label of the text, so that the text bounding box area is displayed in black, where the SynthText dataset contains the bounding box label of the text; S1.2, then assign the area in the image area where the pixel value is greater than 0 to 255, the formula is as follows: Make the values ​​of non-text box areas all 255, where M ij Represented as pixel value in the area; S2. Use the binary image to crop the image: S2.1, use the cv2.findContours() function in the OpenCV library to find each contour in the image. The function is as follows: where countours is a list consisting of n elements, each element i is a list consisting of m i The set of points (x{i,j},y{i,j}) represents the coordinate set of the i-th edge; i and j represent the index of the edge and the index of the point respectively, and x{i,j} and y{i,j} represent the horizontal and vertical coordinates of the j-th point in the i-th edge respectively; S2.2, use the cv2.minAreaRect() function in the OpenCV library to calculate the rectangle of each contour. The function is as follows: rect=((x0, y0), (w, h), θ), Among them, rect is the data structure returned by the cv2.minAreaRect() function, which represents the vertex coordinates, width, height and clockwise rotation angle of the rectangle; (x0, y0) represents the coordinates of the center of the rectangle, (w, h) represents the width and height of the rectangle respectively, and θ is the rotation angle of the rectangle, which represents the counterclockwise rotation angle of the rectangle relative to the horizontal axis; S2.3, filtering out rectangles with smaller areas, where the smaller area is less than 1 / 4 of the average area of ​​all rectangles; S2.4, use the cv2.boxPoints() function in the OpenCV library to obtain the coordinates of the four vertices of the rectangle [x1y1 x2y2 x3y3x4y4], starting from the upper left corner, respectively (x1, y1), (x2, y2), (x3, y3), (x4, y4); the cv2.boxPoints() function is used to obtain the four vertices of the rectangle: expressed as follows: Loop body: for i,contour in enumerate(contours): Determine whether i==0 is true: if i==0: Continue: continue Find the rectangle with the smallest area: rect=cv2.minAreaRect(contour) Get the vertex coordinates of the minimum rectangle: box = cv2.boxPoints(rect) Normalize vertex coordinates to integers: box = np.int0(box) The contours in the above code are obtained by step S2.1; S2.5, based on the obtained rectangular frame coordinates, use the slicing operation to crop the image, as shown below: x1,y1,x2,y2=box Crop the area where the rectangular frame is located roi = img[y1:y2,x1:x2]; S3. Calculate the relative position of each character after cropping: According to the distance between the left and upper boundaries of each rectangular box after cropping and the left and upper boundaries of the original image, the coordinate position of each character in the rectangular box is adjusted accordingly: assuming that x is a certain character, the coordinates of the left, upper, right, and lower points in clockwise direction are (x1, y1), (x2, y1), (x2, y2), (x1, y2) respectively; Assuming that margin_left and margin_top are the distances from the upper left and upper right of the rectangle containing the character to the original image, respectively, and w and h are the width and height of the cropped image, the coordinates of the left, top, right, and bottom points of the cropped character clockwise are: (max(x1-margin_left,0),max(y1-margin_top),0), (min(x2-margin_left,w),max(y1-margin_top),0), (min(x2-margin_left,w),min(y2-margin_top,h)), (max(x1-margin_left,0),min(y2-margin_top,h)).

2. A method for cutting SynthText data to make it suitable for scanning pen text detection according to claim 1, characterized in that: The method is suitable for application of OCR in documents.

3. A method for cutting SynthText data to make it suitable for scanning pen text detection according to claim 1, characterized in that: The method is applicable to a scanning translator pen.

Citation Information

Patent Citations

  • Segmentation and recognition method and system for combined verification code

    CN108875745A

  • Edge cutting method and system for scanned document

    CN111062317A

  • Image cutting method and device, terminal and readable storage medium

    CN114549551A

  • Training sample production method and apparatus, computer device, and readable storage medium

    WO2021174786A1