Image processing apparatus, image processing method, and storage medium
A training image in accordance with a way a hane occurs, which is found in actual handwriting, is generated. Among line segments constituting a handwritten character in a character image representing the handwritten character, a line segment at which a handwritten hane may occur is detected. Then, by performing processing to add a simulated hane to the end portion of the detected line segment, a training image is generated.
1 . An image processing apparatus comprising:
a memory that stores a program; and
a processor that executes the program to perform:
obtaining a character image representing a handwritten character;
detecting a line segment at which an extra segment may occur in handwriting among line segments constituting the handwritten character in the character image;
adding a simulated extra segment to the end portion of the detected line segment; and
generating training data for machine learning by associating the character image in which the simulated extra segment has been added and a correct answer class with each other;
performing the machine learning by using the generated training data and generating a trained model; and
outputting text information by inputting a target image to the trained model,
wherein the adding is performed by randomly determining a length of the simulated extra segment.
2 . The image processing apparatus according to claim 1 , wherein
in the detecting:
in an area accounting for a predetermined percentage in the bottom portion in the character image, a number of connected pixel groups for each row and a number of connected pixels in each connected pixel group are obtained; and
in a case where the maximum value of the number of connected pixel groups for each row is 1 and the maximum number of connected pixels in each connected pixel group is less than or equal to a threshold value, a line segment existing in the area is detected as the line segment at which the extra segment may occur,
in the adding, the simulated extra segment is added to the bottom end portion of the detected line segment,
the connected pixel group for each row represents a black pixel group existing continuously in a direction horizontal with respect to an erect direction of the handwritten character, and
the number of connected pixels represents a number of black pixels constituting the connected pixel group.
3 . The image processing apparatus according to claim 1 , wherein
in the detecting:
in an area accounting for a predetermined percentage in the top portion in the character image, a number of connected pixel groups for each row and a number of connected pixels in each connected pixel group are obtained; and
in a case where the maximum value of the number of connected pixel groups for each row is 1 and the maximum number of connected pixels in each connected pixel group is less than or equal to a threshold value, a line segment existing in the area is detected as the line segment at which the extra segment may occur,
in the adding, the simulated extra segment is added to the top end portion of the detected line segment,
the connected pixel group for each row represents a black pixel group existing continuously in a direction horizontal with respect to an erect direction of the handwritten character, and
the number of connected pixels represents a number of black pixels constituting the connected pixel group.
4 . The image processing apparatus according to claim 1 , wherein
in the detecting:
in an area accounting for a predetermined percentage in the right portion in the character image, a number of connected pixel groups for each column and a number of connected pixels in each connected pixel group are obtained; and
in a case where the maximum value of the number of connected pixel groups for each column is 1 and the maximum number of connected pixels in each connected pixel group is less than or equal to a threshold value, a line segment existing in the area is detected as the line segment at which the extra segment may occur,
in the adding, the simulated extra segment is added to the right end portion of the detected line segment,
the connected pixel group for each column represents a black pixel group existing continuously in a direction vertical with respect to an erect direction of the handwritten character, and
the number of connected pixels represents a number of black pixels constituting the connected pixel group.
5 . The image processing apparatus according to claim 1 , wherein
the length is determined in a range of 1% to 10% of a height of the cut-out image in a case where the height is taken to be a reference.
6 . The image processing apparatus according to claim 1 , wherein
the processor executes the program to perform:
deformation processing for the obtained character image; and
the detecting is performed by taking a deformed character image as a target.
7 . The image processing apparatus according to claim 1 , wherein
the processor executes the program to perform:
the machine learning by using the generated training data.
8 . The image processing apparatus according to claim 1 , wherein
the adding is performed by randomly determining an angle of the simulated extra segment.
9 . The image processing apparatus according to claim 2 , wherein
the adding is performed by randomly determining an angle of the simulated extra segment.
10 . The image processing apparatus according to claim 3 , wherein
the adding is performed by randomly determining an angle of the simulated extra segment.
11 . The image processing apparatus according to claim 4 , wherein
the adding is performed by specifying a landing point and a drawing start point of the simulated extra segment and determining an angle of the simulated extra segment based on the specified landing point and the specified drawing start point.
12 . The image processing apparatus according to claim 6 , wherein
the deformation processing includes one of rotation, enlargement or reduction, expansion or contraction, and aspect ratio change.
13 . The image processing apparatus according to claim 9 , wherein
the angle is determined in a range of 15° to 60° in a case where the angle in the exactly rightward direction is taken to be 0° and the angle in the exactly upward direction is taken to be 90° in the character image.
14 . The image processing apparatus according to claim 10 , wherein
the angle is determined in a range of 135° to 225° in a case where the angle in the exactly rightward direction is taken to be 0° and the angle in the exactly upward direction is taken to be 90° in the character image.
15 . The image processing apparatus according to claim 11 , wherein
in the adding, an angle formed by the specified landing point and the specified drawing start point is determined to be an angle of the simulated extra segment.
16 . The image processing apparatus according to claim 11 , wherein
the adding is performed by determining a length of the simulated extra segment as a random length in a range in which a distance between two points of the specified drawing start point and the specified landing point is not exceeded.
17 . An image processing method comprising the steps of:
obtaining a character image representing a handwritten character;
detecting a line segment at which an extra segment may occur in handwriting among line segments constituting the handwritten character in the character image;
adding a simulated extra segment to the end portion of the detected line segment; and
generating training data for machine learning by associating the character image in which the simulated extra segment has been added and a correct answer class with each other;
performing the machine learning by using the generated training data and generating a trained model; and
outputting text information by inputting a target image to the trained model,
wherein the adding is performed by randomly determining a length of the simulated extra segment.
18 . A non-transitory computer readable storage medium storing a program for causing a computer to perform an image processing method comprising the steps of:
obtaining a character image representing a handwritten character;
detecting a line segment at which an extra segment may occur in handwriting among line segments constituting the handwritten character in the character image;
adding a simulated extra segment to the end portion of the detected line segment; and
generating training data for machine learning by associating the character image in which the simulated extra segment has been added and a correct answer class with each other;
performing the machine learning by using the generated training data and generating a trained model; and
outputting text information by inputting a target image to the trained model,
wherein the adding is performed by randomly determining a length of the simulated extra segment.