4

操作する画像がいくつかありますが、これらの画像には常に2つのポイント(x1、y1)と(x2、y2)があります。このような:

|----------------|
|                |
|    .           |
|                |
|          .     |
|                |
|----------------|

このように画像を整列させるためにアルゴリズムをコーディングする必要があります

|----------------|
|                |
|                |
|    .     .     |
|                |
|                |
|----------------|

私はすでにこの質問を読みましたが、によって得られた角度

double angle = Math.Atan2(pointB.Y - pointA.Y, pointB.X - pointA.X);

このローテーションコードをJavaで使用すると、機能しません。

public static BufferedImage tilt(BufferedImage image, double angle) {
    double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
    int w = image.getWidth(), h = image.getHeight();
    int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math
            .floor(h * cos + w * sin);
    GraphicsConfiguration gc = getDefaultConfiguration();
    BufferedImage result = gc.createCompatibleImage(neww, newh,
            Transparency.OPAQUE);
    Graphics2D g = result.createGraphics();

    g.setColor(Color.white);
    g.setBackground(Color.white);
    g.fillRect(0, 0, neww, newh);

    g.translate((neww - w) / 2, (newh - h) / 2);

    g.rotate(angle, w / 2, h / 2);
    g.drawRenderedImage(image, null);
    g.dispose();
    return result;
}

前に述べた投稿では、彼らは次のようなc#コードを使用しています

myImage.TranslateTransform(-pointA.X, -pointA.Y);
myImage.RotateTransform((float) angle, MatrixOrder.Append);
myImage.TranslateTransform(pointA.X, pointA.Y, MatrixOrder.Append);

この場合のJavaの実装を手伝ってくれる人はいますか?

4

3 に答える 3

1

わかりました...問題を解決するために、Math.atan2によって返されるラジアン値を度に変換したところ、回転はうまく機能しました。

みんなありがとう

于 2011-04-12T23:11:20.487 に答える
0

例の左側の点がAで、例の右側の点がBの場合、三角形を完成させるために90度の角度を持つ点C(AX、BY)を描画することを想像してください。ジオメトリ計算を使用してコーナーAの角度を計算すると、回転する量がわかります。

于 2011-04-07T14:45:13.273 に答える
0

私にとって、以下は、pointAがTopLeft Cornerマーク、pointBがBottomLeftコーナーマークであるOMRシートマーキングを位置合わせするために機能しました

ダブルアングル=Math.Atan2(pointB.x-pointA.x、pointB.y-pointA.y);

于 2013-05-28T06:40:17.450 に答える