## Appendix A
### Segment Rotation  
There are several problems in image recognition, especially when applied to an environment exposed to motion, light, and other factors. This results in several segments of the number not being straight. To solve this problem, the segment matrix can be rotated by capturing the pixels with the values found in the first and last columns of the segment. Figure A3 shows the matrix of the tilted section with the obtained positions. Subsequently, the column of the first black pixel of the row is captured and if this value is greater than half of the total columns, then the row of the first black pixel of the first column is captured; otherwise, the row of the first pixel is captured in black in the last column. The segmented matrix is rotated counterclockwise, regardless of the calculated angle. It is important to consider that when performing the rotation process, local interpolation is applied, so when rotating its size, the matrix must be re-binarized with the new pixel values created by the interpolation [45]. In addition, the threshold value is recalculated to capture lighter pixels in the matrix; this matrix is created from the following code:  
* img = cv2.imread(num.png).
* rows, cols, ch = img.shape.
* pts1 = np.float32([[100, 400], [400, 100], [100, 100]]).
* pts2 = np.float32([[50, 300], [400, 200], [80, 150]]).
* M = cv2.getAffineTransform(pts1, pts2).
* dst = cv2.warpAffine(img, M, (cols, rows)).  
When rotating images, the edges of the image are usually cut off, as shown in the example in the figure. When the image is rotated with a larger angle, it means that part of the image is lost during the process. This is not a bug in OpenCV, but it is how the functions are designed. To solve this problem, it is possible to use several coexistence functions with OpenCV. The image captured in the image is made up of four quadrants, which indicate the different angles to which the figure was subjected for the rotation process. To move from the initial quadrant, it is necessary to find its rotation matrix; for this, the function getRotationMatrix2D() of OpenCV is used. In the function, the first argument is the center of the image by which the image is rotated. The second argument is the rotation angle, and the third argument is the scale of the image. If the scale is less than one, the image will become smaller than the original image. The image will be scaled or enlarged if the scale is a positive number; if the scale is 1, the image will not be scaled. The first argument of the warpAffine() function is the image to rotate, the second argument is the rotation matrix, and the third argument is the size of the output image. For example, the figure shows the rotation of the image around its center, for which the following code is added:  
* image = cv2.imread(\"num.jpg\").
* (h, w) = image.shape[:2].
* center = (w/2, h/2).
* angle = 15.
* scale = 1.
* M = cv2.getRotationMatrix2D(center, angle, scale).
* rotated = cv2.warpAffine(image, M, (w, h)).
* cv2.imshow(\"original Image\", image).
* cv2.imshow(\"Rotated Image\", rotated).
* cv2.waitKey(0).
* cv2.destroyAllWindows().  
Applying the above code, the shape method is used to find the length and width of the given image. Then the center of the image is calculated by taking half of the length and width. You can change the center, angle, and scale value to obtain the desired result.