gpt4 book ai didi

Java 图像旋转 : Is the computed angle correct?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:46:28 26 4
gpt4 key购买 nike

我在通过 OCR 处理发票的程序中发现了一个有趣的问题。
在一步中,我对图像进行了歪斜校正,现在我有了一个特定的用例。

原始文件(解密):

original

旋转文件(解密):

rotated

我本以为旋转大约是 -15 度,但程序告诉我是 -2.2 度。

使用的代码:

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;
}

如您所见,代码似乎工作正确,但谁是正确的?我如何找出图像的实际旋转?到底是怎么回事?

最佳答案

看看这一行:

enter image description here

它的尺寸是:472 * 20。对其应用 arctan 函数:

atan(20/472) = 0.042347549 radians

将其转换为度数,您有:

2.42633583 degrees

因此,您的程序运行正常,您对 15 度的估计完全不对。

关于Java 图像旋转 : Is the computed angle correct?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com