Transformations: reshape the signal.
Resize, rotate, warp and re-color an image until it is in the shape your algorithm expects. Learn how pixels move under affine and perspective transforms, and why a corrected input beats a clever model.
import cv2
img = cv2.imread("page.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
flat = cv2.warpPerspective(gray, M, (w, h))