Rigid perspective correction
Our first trial to do perspective correction will be a rigid one. We will follow these steps:
Convert the input image to grayscale.
Use the Canny edge detector to get the edge image.
Detect the lines in the edge image using the probabilistic Hough transform.
Find the bounding lines of the object of interest.
Estimate the bounding rectangle of the object of interest; hence the name rigid because the object doesn't need to have parallel opposite sides, but we will enforce this by using a rectangular estimation to the quadrilateral object.
Build a list of the rectangle's four corners.
Impose a correspondence between the rectangle corners and screen corners.
Use the correspondence to get a perspective transformation matrix.
Apply the transformation matrix to the input image to get the corrected perspective of the object of interest.
UI definitions
We will add an additional menu item to start the perspective correction process. Go to the res/menu/soft_scanner.xml
file and open...