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 object_localization (single view geometry) #12

Open
where2go947 opened this issue Dec 13, 2023 · 1 comment
Open

Question about object_localization (single view geometry) #12

where2go947 opened this issue Dec 13, 2023 · 1 comment

Comments

@where2go947
Copy link

Thanks for your awesome work. It does help!
But I got confused about a line in code. Could you give me some help? Thanks in advance!

according to the slides (02 single view geometry, 24th):
$Z = \frac{\bar{z}}{\bar{y}} L$
$X = \frac{\bar{x}}{\bar{y}} L$

image

However, in the code below, $X = \frac{c[0]}{c[2]} * L$ (line 62), which $c[2]$ is actually $\bar{z}$ instead of $\bar{y}$.
So in my opinion, the code is supposed to be: $X = \frac{c[0]}{c[1]} * L$

while True:
img_copy = img.copy()
if mouse_state['xy_e'][0] > 0 and mouse_state['xy_e'][1] > 0:
# Calculate object location and height
c = R.T @ [mouse_state['xy_s'][0] - cx, mouse_state['xy_s'][1] - cy, f]
h = R.T @ [mouse_state['xy_e'][0] - cx, mouse_state['xy_e'][1] - cy, f]
if c[1] < 1e-6: # Skip the degenerate case (beyond the horizon)
continue
X = c[0] / c[2] * L # Object location X [m]
Z = c[2] / c[1] * L # Object location Y [m]
H = (c[1] / c[2] - h[1] / h[2]) * Z # Object height [m]

@where2go947
Copy link
Author

where2go947 commented Dec 13, 2023

By the way, I think equation in slides above $[\bar{x}, \bar{y}, \bar{z}]^T = R^T* [x-c_x, y-c_y, f]^T$ is wrong, which $R^T$ should be $R$. ($R$ is the camera orientation)
The implementation in the CPP file is right: Rc is the camera orientation.

cv::Point3d c = R.t() * cv::Point3d(drag.xy_s.x - cx, drag.xy_s.y - cy, f);

Actually, R.t()=Rc, which is the camera orientation:

cv::Matx33d Rc = Rz(cam_ori.z) * Ry(cam_ori.y) * Rx(cam_ori.x);
cv::Point3d tc = cv::Point3d(0, -L, 0);
cv::Matx33d R = Rc.t();
cv::Point3d t = -Rc.t() * tc;

From my perspective, what $R * [x-c_x, y-c_y, f]^T$ does is to represent the point $[x-c_x, y-c_y, f]^T$ under an unrotated coordinate system (its orientation is aligned with the world coordinate system, but the origin keeps unchanged), so that the similar triangles equation $\frac{\bar{x}}{X} = \frac{\bar{y}}{L} = \frac{\bar{z}}{Z}$ would be right.

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

1 participant