March 2019
Intermediate to advanced
538 pages
13h 38m
English
Now, all we must do is extract the text and adjust the text skew. This is done by the deskewAndCrop function, as follows:
Mat deskewAndCrop(Mat input, const RotatedRect& box)
{
double angle = box.angle;
auto size = box.size;
//Adjust the box angle
if (angle -45.0)
{
angle += 90.0; std::swap(size.width, size.height);
}
//Rotate the text according to the angle
auto transform = getRotationMatrix2D(box.center, angle, 1.0);
Mat rotated;
warpAffine(input, rotated, transform, input.size(), INTER_CUBIC);
//Crop the result
Mat cropped;
getRectSubPix(rotated, size, box.center, cropped);
copyMakeBorder(cropped,cropped,10,10,10,10,BORDER_CONSTANT,Scalar(0));
return cropped;
}
First, we start by reading the desired ...