Find edges on a receipt and correct the angle with OpenCV - Java

1.1k Views Asked by At

I'm trying to figure out how to correct the angle of a given image of a receipt (taken with a digital camera, so it's probably not straight enough) using OpenCV in Java. The plan is to (maybe) improve ABBYY FineReaders automatic text recognition results. Unfortunately I'm not making progress with the documentation - it's for C++ and I'm really having trouble with it... I don't know which functions to use, etc... Could someone with experience with OpenCV give me a few hints on how to proceed? Help would be much appreciated.

1

There are 1 best solutions below

0
On

It's pretty easy using warpaffine function in opencv. you just need to set from where the image should be rotated and then you create the rotation matrix and apply it on the image using the above function. here it is a sample code of how to make one:

   cv::Point Rotation_anchor = cv::Point( Desired_X_Position, Desired_Y_Position );
   double angle = Angle_Val;
   double scale = 1;    
   /// Get the rotation matrix with the specifications above
   cv::Mat rotation_matrix = cv::getRotationMatrix2D( Rotation_anchor, angle, scale );   
   /// Rotate the warped image
   cv::warpAffine( Input_Image, Output_Image, rotation_matrix, Input_Image.size() );