Question

I've found an interesting issue in the program that I'm working on to process invoices via an OCR.
In one step I deskew the image, now I have a particular use case.

Original file (declassified):

original

Rotated file (declassified):

rotated

I was thinking by heart that the rotation would be around -15 degrees, however the program tells me that it is -2.2 degrees.

The code used:

private BufferedImage rotateImage(BufferedImage image, float angleDegrees, int imageType) {
    long start = System.currentTimeMillis();
    angleDegrees %= 360;
    BufferedImage returnImage = new BufferedImage(image.getWidth(), image.getHeight(), imageType);
    Graphics2D g2d = returnImage.createGraphics();
    g2d.rotate(Math.toRadians(angleDegrees), returnImage.getWidth() / 2, returnImage.getHeight() / 2);
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    long end = System.currentTimeMillis();
    float duration = 1.0f * (end - start) / 1000;
    //System.out.println("Duration: " + duration + " seconds");
    return returnImage;
}

As you can see the code seems be working correctly, but who is correct? How would I figure out the actual rotation of the image? What exactly is going on?

Was it helpful?

Solution

Take a look at this line:

enter image description here

It's dimensions are: 472 * 20. Apply the arctan function to it:

atan(20/472) = 0.042347549 radians

Convert this to degrees and you have:

2.42633583 degrees

So, your program works correctly, and your estimation of 15 degrees was simply off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top