计算相机射线方向到3d世界像素 [英] Calculating camera ray direction to 3d world pixel

查看:286
本文介绍了计算相机射线方向到3d世界像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算射线从相机到像素位置(在世界坐标系中)与给定高度的方向,如,但是所描述的解决方案不包括像素高度(这里为z)。

解决方案

几年前,当我写我的文凭论文时,我解决了同样的问题。这是它的一部分,它描述如何创建相机的光线追踪..



首先,你需要定义相机的坐标系。它是正交坐标系,这意味着所有三个基矢量彼此垂直并具有相同的大小(不必是一)。此外,您需要指出,如果您的相机坐标系是右撇子或左撇子(我会说左手)。首先你需要定义向量(向量显示屏幕上的y轴是什么)和相机方向向量(因此从眼睛位置到投影平面中间的矢量)。然后你会计算左向量(或右向量,如果你需要)(它指向你的屏幕上的x轴正确)by cross product 相机方向向量 / code>。现在,因为只有摄像机方向矢量和左矢量是垂直的,所以你必须使另外一个交叉乘积 相机方向矢量左向量(图像上的向量y)。



喜欢这个





无需定义,您的投影屏幕在世界坐标中的大小。这可能有时很棘手,因此您也可以通过两个角度定义它( phi theta )和距离眼睛位置的距离(让它调用 d ) 。



您会得到和。 ( x 向量是在屏幕上定义x轴的向量,因此它左向量
通过线性组合这两个向量 u v ,您可以计算投影上的任何位置屏幕。系数 alpha 和虽然代表距离从投影屏幕中间的点



因此和,其中 s r 是您计算的图片上的 x y 坐标, imageWidth

因此,您可以在此图像上看到





投影平面上任何点的最终位置为。



然后,请求向量的计算是。


I'm want to calculate ray directions from camera to pixel positions (in world coords) with given height as described in this paper. Camera image size is 640,480. I calibrated the intrinsic camera parameters and undistort each image. I measured the physical distance between camera and background plane (29 cm) as sketched here:

1 cm translates to 25 pixel (assuming quadratic pixels). My first approach was to calculate based on pixel- and camera position as follows:

float3 pixPos = (float3)(u, v, z);
float3 camPos = (float3)(height/2, width/2, 29*25);
float3 ray = normalize(pixPos-camPos);

where u,v are image coords from 0,0 to height,width and z are my (already estimated) height values. This doesn't seem to be the right way. I already did a search on SO and found this answer, but the solution described there doesn't include pixel heights (z here).

解决方案

I was solving same problem few years back, when I was writing my diploma thesis. Here is a part of it which describes how to create camera for raytracing..

First of all you need to define coordinate system of camera. It's orthonormal coordinate system, that means that all three basis vectors are perpendicular to each other and have same size (doesn't have to be "one"). Also you need to point out, if your coordinate system of camera is right-handed or left-handed (I will talk about left-handed). First you'll need to define up vector (the vector shows you what is y axis on your screen) and camera direction vector (so vector from eye position to middle of your projection plane). Then you'll calculate left vector (or right vector if you need) (which points where exactly is x axis on your screen) by cross product of the up vector and camera direction vector. Now, because only camera direction vector and left vector are perpendicular for sure, you have to make one more cross product of camera direction vector and left vector (vector y on the image).

So you'll get camera coordination system like this one

No you have to define, how big is your projection screen in world coordinates. That might be sometimes tricky, so you can also define it by two angles (phi and theta) and distance from eye position (lets call it d).

You'll get and . (the x vector is the vector which defines x axis on screen, so it's left vector or right vector, depends of handedness) By linear combination of those two vectors u and v you can compute any position on your projection screen. Coefficients alpha and though represents distances the point from middle of projection screen.

So and , where s and r are x and y coordinates on your calculated image and imageWidth and imageHeight are appropriate sizes.

So as you can see on this image

Final position of any point on projection plane is .

Then calculation of requested vector is .

这篇关于计算相机射线方向到3d世界像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆