Given an image containing a rotated block of text at an unknown angle, we need to correct the text skew by:
- Detecting the block of text in the image.
- Computing the angle of the rotated text.
- Rotating the image to correct for the skew.
Mat correctSkew()
{
Mat warpMat = Imgproc.getAffineTransform( new MatOfPoint2f(srcTri), new MatOfPoint2f(dstTri) );
Mat warpDst = Mat.zeros( src.rows(), src.cols(), src.type() );
Imgproc.warpAffine( src, warpDst, warpMat, warpDst.size() );
Point center = new Point(warpDst.cols() / 2, warpDst.rows() / 2);
double angle = -50.0;
double scale = 0.6;
// Rotate matrix Opencv Function
Mat rotMat = ##Imgproc.getRotationMatrix2D( center, angle, scale );
Mat warpRotateDst = new Mat();
Imgproc.warpAffine( warpDst, warpRotateDst, rotMat, warpDst.size() );
return warpRotateDst;
}