Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Affine matrix structure #15

Open
Justdjent opened this issue Jun 22, 2018 · 5 comments
Open

Question about Affine matrix structure #15

Justdjent opened this issue Jun 22, 2018 · 5 comments

Comments

@Justdjent
Copy link

Justdjent commented Jun 22, 2018

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
@Pay20Y
Copy link

Pay20Y commented Mar 31, 2019

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

@Pay20Y
Copy link

Pay20Y commented Apr 1, 2019

I solved it. Sorry to bother you.

@JordanCheney
Copy link

@Pay20Y could you share your solution?

@Pay20Y
Copy link

Pay20Y commented May 11, 2020

@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.

@persuelx
Copy link

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants