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 ray direction #99

Closed
zhshi0816 opened this issue Jan 12, 2023 · 3 comments
Closed

Question about ray direction #99

zhshi0816 opened this issue Jan 12, 2023 · 3 comments

Comments

@zhshi0816
Copy link

zhshi0816 commented Jan 12, 2023

Hi,

Thanks for making a great contribution to our PyTorch community. I have a question about the ray direction. The camera projection formulation is as follows:
$$u = \frac{x}{z}f + \frac{W}{2}, v = -\frac{y}{z}f + \frac{H}{2}$$

I just reverse the formulation to derive the ray direction as follows:
$$[ \frac{u-\frac{W}{2}}{f}z, \hspace{6mm} -\frac{v-\frac{H}{2}}{f}z, \hspace{6mm} z]$$.

Then I set z=-1, which is different from your result.
Can anyone show me where I was wrong? How do you calculate the direction?

@JunjieLl
Copy link

so have you ever figure out why? I have the same question as yours, would you please give me some response, thanks.

@JunjieLl
Copy link

JunjieLl commented Apr 11, 2023

world coordinates $P=(X,Y,Z)$, imaging plane coordinates $P^{'}=(X^{'},Y^{'},Z^{'})$, pixel coordinates $(u,v)$

$$ \frac{Z}{f}=-\frac{X}{X^{'}}=-\frac{Y}{Y^{'}} $$

$$ X^{'}=-f\frac{X}{Z},Y^{'}=-f\frac{Y}{Z} $$

$$ u=X^{'}+c_x,v=Y^{'}+c_y $$

$$ u=-f\frac{X}{Z}+c_x,v=-f\frac{Y}{Z}+c_y $$

$$ X=\frac{c_x-u}{f}Z,Y=\frac{c_y-v}{f}Z $$

$$ P=(\frac{c_x-u}{f}Z,\frac{c_y-v}{f}Z,Z) $$

$$ P=(\frac{u-c_x}{f},\frac{v-c_y}{f},-1),\ where\ Z=-1 $$

Finally, I resolve this issue from here, the axis y is reversed and then the equation matches the code.

@chzhan
Copy link

chzhan commented Sep 20, 2023

世界坐标磷=(X,和,和),成像平面坐标磷′=(X′,和′,和′),像素坐标(在,在)

和F=−XX′=−和和′

X′=−FX和,和′=−F和和

在=X′+CX,在=和′+C和

在=−FX和+CX,在=−F和和+C和

X=CX−在F和,和=C和−在F和

磷=(CX−在F和,C和−在F和,和)

磷=(在−CXF,在−C和F,−1), 在H这是r这是 和=−1

最后,我从这里解决了这个问题,y轴反转,然后方程与代码匹配。

遇到了同样的问题,感觉你的推理是对的,但是坐标轴是对不上的,我查了下常用的坐标系,像素坐标系x轴和相机坐标系x轴是同向的,y轴是反方向的

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

3 participants