Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating camera ray direction to 3d world pixel

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:

Scene

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

like image 856
NewProggie Avatar asked Dec 30 '12 19:12

NewProggie


People also ask

How do you determine ray direction in ray tracing?

P=orig+t∗dir. Where t is the distance from the origin of the point to the point on the half-line. This variable can either be negative or positive. It t is negative, the point on the ray is behind the ray origin and if t is positive, the point P is in "front" of the ray's origin.

What is 3D world coordinate system?

This coordinate system is a convention used to define the coordinates [0,0,0] in our 3D virtual space and three unit axes orthogonal to each other (figure 4). It's the prime meridian of a 3D scene, a reference to which any other point or any other arbitrary coordinate system is measured to.

What is ray tracing algorithm?

Ray tracing generates computer graphics images by tracing the path of light from the view camera (which determines your view into the scene), through the 2D viewing plane (pixel plane), out into the 3D scene, and back to the light sources.


1 Answers

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

left handed camera coordination system

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 angles (phi and theta) and distance from eye position (lets call it d).

You'll get u vector and v vector. (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 alphaalpha and beta though represents distances the point from middle of projection screen.

So alpha coefficient and beta coefficient, 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

projection plane

Final position of any point on projection plane is point on projection plane.

Then calculation of requested vector is desired vector.

like image 160
Sorceror Avatar answered Sep 25 '22 12:09

Sorceror