For your first question:
First remove any “specifications” of noisy white pixels that are not part of the letter sequence. A gentle low-pass filter (pixel color = average surrounding pixel), followed by clamping the pixel values to pure black or pure white. This should get rid of the small “dot” under the “a” symbol in your image and any other specifications.
Now find the following pixels:
xMin = white pixel with the lowest x value (white pixel closest to the left edge) xMax = white pixel with the largest x value (white pixel closest to the right edge) yMin = white pixel with the lowest y value (white pixel closest to the top edge) yMax = white pixel with the largest y value (white pixel closest to the bottom edge) with these four pixel values, form a bounding box: Rect(xMin, yMin, xMax, yMax); compute the area of the bounding box and find the center. using the center of the bounding box, rotate the box by N degrees. (You can pick N: 1 degree would be an ok value). Repeat the process of finding xMin,xMax,yMin,yMax and recompute the area Continue rotating by N degrees until you've rotated K degrees. Also rotate by -N degrees until you've rotated by -K degrees. (Where K is the max rotation... say 30 degrees). At each step recompute the area of the bounding box.
The rotation that creates the bounding rectangle with the smallest area is probably rotational, aligning letters parallel to the bottom edge (horizontal alignment).
source share