How can I calculate the Focal Length of my rendered image in a ray tracer (Let's say PBRT)? - raytracing

Actually, I have rendered 3 input images of a sphere with different light directions in PBRT.
As the next step of the process, I am going to compute surface normals of this sphere, so I need to put the Focal length value in my formula.
All that I now is that I have the value of Field of View (FOV) in my PBRT input files which is 45.
The dimensions of the whole image is 32*32 and the dimensions of the sphere in the image is 26*26.
How can I compute the exact amount of the Focal length using this information?

you can not use perspective without knowing the focal length in 3D graphics. It is also called z_near and it is the distance from camera origin (point from which you cast the rays) to the projection plane. Look at this:
where: Point P near Camera label is the focal point and the blue rectangle labeled Screen(z_near) is the projection plane. The focal length is perpendicular distance of this point to the plane.
PS. boyfarrell is right you do not need focal length for normal computations. It does not make sense. You could need it to compute some physic process like pupil size etc but not for normals.

Related

How do I find the corners of a plane in 3d space if I know three points

Apologies in advance for my feeble maths.
I'm trying to be able to find the corners of a plane in space based on the equation of that plane. Here's what I know. I know three points on the plane and I know where they fall in the 2d coordinate space of the plane (x,y) and where they are in 3d space. I know the width and height of the plane and I can now calculate the equation of the plane. The plane sits on the inside of a large sphere that surrounds the origin so, in theory, it should more or less face where the camera is (though in my diagram it doesn't face the origin as it's just for illustrative purposes)
But it's not clear to me how I can use that to figure out another point. One thought I had was to find the transform that moves the plane parallel to the xy axis and rotate it round one of the points (so it stays in the same place), find the position of the new point, and then rotate it by the inverse of that transform. But it's not clear to me how I would find that transform matrix or how to use it. Could I do this using the normal and vector maths? I understand what normals are, but I'm fuzzy about how to use them.

Pixel coordinates derived from real distance measurements

In my program (using MATLAB), I specified(through dragging) the pedestrian lane as my Region Of Interest (ROI) with the coordinates [7, 178, 620, 190] (in xmin, ymin, width, and height respectively) using the getrect, roipoly and insertshape function. Refer to the image below.
The video from where this snapshot is taken is in 640x480 pixels resolution (480p)
Defining a real world space as my ROI by mouse dragging is barbaric. That's why the ROI coordinates must be derived mathematically.
What I'm going at is using real-world measurements from the video capturing site and use the Pythagorean Theorem from where the camera is positioned:
How do I obtain the equivalent pixel coordinates and parameters using the real-world measurements?
I'll try to split your question into 2 smaller questions.
A) How do I obtain the equivalent pixel coordinates of an interesting
point? (pratical question)
Your program shoudl be able to retrieve/reconnaise a feature/marker that you positioned in the "real-world" interesting point. The output is a coordinate in pixel. This can be done quite easily (think about QR-codes, for example)
B) What is the analytical relationship between 1 point in 3D space and
its pixel coordinate in the image? (theoretical question)
This is the projection equation based on the pinhole camera model. X,Y,Z 3D coordinates are related with x,y pixel coordinates
Cool, but some detail have to be explained (and there will be any "automatic short formula")
s represent the scale factor. A single pixel in an image could be the projection of infinite different point, due to perspective. In your photo, a pixel containing a piece of a car (when the car is present) will be the same pixel that contain a piece of street under the car (when the car is passed).
So there is not an univocal relationship starting from pixels coordinates
The matrix on the left involves the camera parameters (focal length, etc.) which are called intrinsic parameters. They have to be known to build the relationship between 3D coordinates and pixel coordinates
The matrix on the right seems to be trivial, is the combination of an identity matrix which represents rotation and a column array of zeros which represents translation. Something like T = [R|t].
Which rotation, which translation? You have to consider that every set of coordinates is implicitly expressed in its own reference system. So you have to determine the relationship between the reference system of your measurement and the camera reference system: not only to retrieve position of the camera in your 3D space with euclidean geometry, but also orientation of the camera (angles).

Computing depthmap from 3D reconstruction model

I'm using VisualSfM to build the 3D reconstruction of a scene. Now I want to estimate the depthmap and reproject the image. Any idea on how to do it?
If you have the camera intrinsic matrix K, its position vector in the world C and an orientation matrix R that rotates from world space to camera space, you can iterate over all pixels x,y in your image and perform:
Then, find using ray tracing, the minimal t that causes the ray to intersect with your 3D model (assuming it's dense, otherwise interpolate it), so that P lies on your model. The t value you found is then the pixel value of the depth map (perhaps normalized to some range).

Captured image viewpoint changing

i have a picture that captured from a fixed position [X Y Z] and angle [Pitch Yaw Roll] and a focal length of F (i think this information is called camera matrix)
i want to change the captured picture to a different position like it was taken in up position
the result image should be like:
in fact i have picture taken from this position:
and i want to change my picture in a way that it was taken in this position:
i hope that i could express my problem.
thnx in advance
It can be done accurately only for the (green) plane itself. The 3D objects standing onto the plane will be deformed after remapping, but the deformation may be acceptable if their height is small relative to the camera distance.
If the camera is never moving, all you need to do is identify on the perspective image four points that are the four vertices of a rectangle of known size (e.g. the soccer field itself), then compute the homography that maps those four points to that rectangle, and apply it to the whole image.
For details and code, see the OpenCV links at the bottom of that Wikipedia article.

How to get rotation angles of Image Plane relative to the World Plane?

So we have such situation:
In this illustration, the first quadrilateral is shown on the Image Plane and the second quadrilateral is shown on the World Plane. [1]
In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, with same rotation relative to the plane they are lying on, and are not situated on same line on plane.
I wonder if we can get rotation angles of Image Plane to World Plane knowing stuff described?
In my case as input I have such data structures: original image (RGB pixels), objects (squares) with angles points in pixels (x,y) on Image Plane.
Take a look at Sections 2 and 3 of Algorithms for plane-based pose estimation.
The methods described there assume that you know the (x,y) coordinates of the features in question - in this case the red squares.
The problem you are describing is generally known as pose estimation - determining the 3D orientation and position of an object relative to a camera from a 2D view. For you, the object is a plane. Googling 'pose estimation plane' should give you more sources.

Resources