question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] relative_transformation returns wrong transformation

See original GitHub issue

🐛 Bug

The function relative_transformation is not returning the correct relative transform given two random input transforms. We might have to take a look at compose_transformations and inverse_transformation too.

To Reproduce

Use this colab link: https://colab.research.google.com/drive/104_T6Jfqyq_cy3xTYd_Qo6g6dCYAiL8H?usp=sharing

or run:

Steps to reproduce the behavior:

import torch
import kornia as K

def to_homogeneous(x):
    x_out = torch.nn.functional.pad(x, (0, 0, 0, 1), "constant", 0.)
    x_out[..., -1, -1] += 1.
    return x_out

B = 1  # batch size
rtmat_a = torch.rand(B, 3, 4)
rtmat_b = torch.rand(B, 3, 4)

w_trans_a = to_homogeneous(rtmat_a)
w_trans_b = to_homogeneous(rtmat_b)
print("cam1")
print(w_trans_a)
print("cam2")
print(w_trans_b)

# compute relative motion using kornia with transpose
rtmat_ab = K.relative_transformation(w_trans_a[:, :3], w_trans_b[:, :3])
b_trans_a_kornia = to_homogeneous(rtmat_ab)

# compute relative motion using direct way
b_trans_a_torch = (w_trans_b).inverse() @ w_trans_a

# try to reconstruct cameras
print("rec cam1 kornia")
print(w_trans_b @ b_trans_a_kornia)

print("rec cam1 torch")
print(w_trans_b @ b_trans_a_torch)

print("rec cam2 kornia")
print(w_trans_a @ b_trans_a_kornia.inverse())

print("rec cam2 torch")
print(w_trans_a @ b_trans_a_torch.inverse())

Expected behavior

Environment

Please copy and paste the output from our environment collection script (or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
  • PyTorch Version (e.g., 1.0):
  • OS (e.g., Linux):
  • How you installed PyTorch (conda, pip, source):
  • Build command you used (if compiling from source):
  • Python version:
  • CUDA/cuDNN version:
  • GPU models and configuration:
  • Any other relevant information:

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
edgarribacommented, Oct 13, 2021

gotcha - I think it’s worth having a utility function to create random orthogonal rotation matrices similar to scipy.stats.special_ortho_group https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.special_ortho_group.html

0reactions
thatbrguycommented, Oct 13, 2021

gotcha - I think it’s worth having a utility function to create random orthogonal rotation matrices similar to scipy.stats.special_ortho_group https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.special_ortho_group.html

Yeah I think such a function would be nice to have in kornia for testing purposes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Computing relative transformations between objects / How ...
Hi, I'm trying to compute the relative transformation between two actors in Carla Actor A and Actor B. To do this I take...
Read more >
relative transformation of coordinates on a flat surface
This code is not working right, for instance, if I insert this test just before the return... print(domain * np.array([[1],[0],[0]]).T) print( ...
Read more >
Why are my Relative Transformation Values not 0? | PluginCafé
... an issue where I'm trying to compare an object's relative transformation Vectors ... Position to a Vector with 0 values, however, it...
Read more >
math - Trying to find the relative transformation between to two ...
I have overlaid 3D axes onto the image as shown above using XNA so I assume the rotation and translation relative to the...
Read more >
Wrong rendering of transformed fonts on Windows with Java 6
2, only with Java 6. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Normal string "3 500" ACTUAL - Expected string with skewed numbers....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found