找到旋转图像中的对应点

时间:2014-03-12 17:33:14

标签: math rotational-matrices

我需要帮助将旋转视图中的选定点转换回原始图像中的对应点。因此,例如,如果我在旋转视图中单击左上角(0,0),它应对应于原始图像中的(0,1280)。

无论轮换如何,解决方案的额外分数。

Original Image ( 1920 x 1280 )     Rotated View ( for display on phone )
+----------------------------+     +-----------------+
|(0,0)                       |     |(0,0)            |  ( 1280 x 1920 )
|                            |     |                 |
|                            |     |       x         |
|    x                       |     |    ( click )    |
|    ( what is this point )  |     |                 |
|                            |     |                 |
|                            |     |                 |
+----------------------------+     |                 |
                      (1920,1280)  |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   +-----------------+
                                                      (1280,1920)

已更新


    /*
    This is how I build the matrix used to perform the initial rotation from the original to     the rotated image. This matrix also includes scaling 

    Code base: Android/Java
    bitmap ( bitmap i'm scaling/rotating )
    canvas ( the canvas being drawn to )

    Note: bitmap is in landscape mode / canvas is in portrait

    */

    Matrix matrix = new Matrix();
    float centerX = canvas.getWidth() >> 1;
    float centerY = canvas.getHeight() >> 1;

    rAngle = 90;
    scaleH = ((float) canvas.getHeight()) / bitmap.getWidth();
    scaleW = ((float) canvas.getWidth()) / bitmap.getHeight();

    scaler.preScale(scaleH, scaleW);
    scaler.postRotate(rAngle, centerY, centerX);

    float nx = (canvas.getHeight() - canvas.getWidth()) / 2;
    scaler.postTranslate(-nx, nx);

    canvas.drawBitmap(bitmap,scaler,null);

我不是一个数学家,所以任何握手都会受到赞赏。 :)

1 个答案:

答案 0 :(得分:1)

下标O表示原始框架中的坐标和旋转框架中的下标R

  

X O = Y R
  Y O = maxX R - X R

框架的四个角给我们:

对于旋转帧中的左上角(0,0)

  

X O = 0
  Y O = 1279 - 0 = 1279
  (0,1279)

对于右上角,(1279,0):

  

X O = 0
  Y O = 1279 - 1279 = 0
  (0,0)

左下角,(0,1919):

  

X O = 1919
  Y O = 1279 - 0 = 1279
  (1919年,1279年)

对于右下角,(1279,1919):

  

X O = 1919
  Y O = 1279 - 1279 = 0
  (1919,0)