Skip to content

Question about Affine matrix structure #15

Open

Description

@Justdjent

Hi @kevinzakka
First of all, thank you for detailed explanation and implementation. But I have a question about theta matrix.
I want to use spatial transformer network to estimate affine transformation from 1 image to another and then use those Affine matrix with OpenCV function cv2.warpAffine().
I understood that translation is normalized between (-1,1), but how to deal with scale and rotation parameters?

I created a function to convert the matrix to appropriate format, but it don't work:

def tf_to_cv(theta, input_img):
    rows, cols, ch = input_img.shape
    # print(theta.reshape(2,3))
    M = theta.copy().reshape(2,3)
    M[0][0] = 1/M[0][0]
    M[1][1] = 1/M[1][1]
    M[0][1] = 1/M[0][1]
    M[1][0] = 1/M[1][0]
    M[0][1] = M[0][1] * -1
    M[1][0] = M[1][0] * -1
    M[0][2] = -cols * M[0][2]/4
    M[1][2] = -rows * M[1][2]/4
    # print(M[0][2], M[1][2])
    M[0][2] = M[0][2] + ((1 - M[0][0]) * cols/2 - M[0][1]*rows/2)
    M[1][2] = M[1][2] + (-M[1][0] * cols/2 + (1-M[1][1])*rows/2)
    return M

Activity

  1. Pay20Y commented on Mar 31, 2019

    @Pay20Y

    Hey I have the same question with you. How to make the affine matrix computed from OpenCV work? Did you solve it? Thanks! @ @Justdjent

  2. Pay20Y commented on Apr 1, 2019

    @Pay20Y

    I solved it. Sorry to bother you.

  3. JordanCheney commented on May 10, 2020

    @JordanCheney

    @Pay20Y could you share your solution?

  4. Pay20Y commented on May 11, 2020

    @Pay20Y

    @Pay20Y could you share your solution?

    Sorry, it's been a long time, I've forgotten. I use OpenCV function cv2.getAffineTransform to estimate matrix and use STN to transform the image. The code can be found here.

  5. persuelx commented on Aug 14, 2020

    @persuelx

    @Pay20Y Your answer is totally out of line with the requirements.You should see what people ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions