How to change 3 meter to pixel distance? - matlab

I have a 3D object and I need to project it relative to a 2D image, which is captured 3m away with a camera. When I tried to make a projection matrix I found that I need to state the camera position from the object (3m) and the height of the Camera above the ground (1m). Thus, I need to change these values, measured in meters, to pixels so that they can be used in a projection matrix.
I need to do the computation in Matlab. Any pointers?

get(0,'ScreenPixelsPerInch')
Gives you the missing ingredient in Quentin's solution.

1 metre = 39.3700787 inches so dpi * distance_in_meters / 39.3700787
Obviously you will need to know the DPI of the output device.

Related

How to resize a texture for meters in ARKit

I need to tile a texture across a plane with updating geometry (floor fill), and I need the texture to be scaled to fit real-world dimensions in centimeters. It is a square floor tile of 50cm, and the texture size is 1024 pixels. How do I convert pixels to meters in ARKit? i know that I have to use SCNMatrix4MakeScale on the SCNMaterial diffuse.contentsTransform but not sure what properties to set to get it accurate.
What you might do is use the physical size of SCNNode that you are working with and determine how much squares of 50x50cm could it fit. After you get this coefficient, use it inside the contentsTransform to achieve needed behavior. Please refer to this answer for code snippets and more hints that you might find useful.

AR place an object with same size

I am building an AR application. I have some points which are real worlds coordinates.
I can geolocate these points through Mapbox. My problem is that when I got far away from the points, they are looking getting smaller. I want to see them as the same size independently from the distance.
Here is an example of how to visualize the points:
So, if I near the points I see them in normal sizes. Even though I got 400 KMs away from the point, I want to see it in the same size. Is it possible?
You can try to scale the lables by some value * distance to object.
If you are standing in device and the target is in target it would be:
float experimentalScale = 0.5f
This is the amplifier of the distance. If you increase the value, the lable will get bigger by greater distance. Try out what works best for you.
float scaleFactor = Vector3.Distance(device.transform.position, target.transform.position) * experimentalScale;
target.transform.localScale(scaleFactor,scaleFactor,scaleFactor)
This only works if your Objects scale is 1. If it is something else, just multiply the scale with scaleFactor.

Unity 5 Heighmap Resolution relationship to terrain width / terrain length?

Trying to understand how they relate to the final mesh.
As I understand it,
Terrain width and length is simply the shape/size and within that the resolution determine the vector points/wireframe and how many of them?
So, if i have a width of 500 and length of 500. and height map resolution of 257, then there will be a vector every 2m squared ?
Now, finally, I assume detail resolution and detail resolution per patch have no effect on this at all? but simply the rending process and how the mesh is split up into small chucks?
So, if i have a width of 500 and length of 500. and height map
resolution of 257, then there will be a vector every 2m squared ?
Yes, you guessed it right. Width and length is the width and length in units of the terrain, whereas heightmap resolution is in pixels. So essentially one pixel on the heightmap will map to ~4 square units (2^2) on the terrain.
Now, finally, I assume detail resolution and detail resolution per
patch have no effect on this at all?
The detail resolution is the resolution of the splat map which contains the data for placement of detail objects like grass, plants, rocks, etc. and is in no way related to the shape of the terrain. Detail patches are just for optimization and LODGroups of detail objects.

pixel to pixel transformation

I am having a problem transferring the position of some objects in still image (RGB image ) into 2D view of the room where the image had been taken.I have the coordinates of about 3 objects in the image (i mean X,y coordinate ) as well as the distance between them and I want to transfer the position of these 3 objects into the plan view .
Any help is much appreciated
You will probably need to clarify your question, but if I'm reading it the right way, it coult be as simple as taking the ratio from one object to another.
For example, if your sensor is 640px wide, and that covers a horizontal length of 10 meters, then you know that every 64 pixels represents one meter in the real world.
Bare in mind that this assumes the objects in the real world are at in the same plane, orthogonal to the lens vector. If objects are in different planes (depths), then you have a bigger problem in your hands.

OpenGL ES units

I am developing an application for iPhone.
I am using OpenGL to display a 3D object in the screen, with the camera view as background.
I'd like to know how can i change the OpenGL ES unit to centimeters/meters.
How can i do that?
You dont.
Thought experiment time!
First imagine you have sphere 1 centimeter in diameter. And you have a camera 10 centimeters away. You would see a small sphere in the center of the frame.
Now imagine you have a sphere 1 kilometer in diameter and a camera 10 kilometers away. How would you expect the image to be different?
The correct answer is you would not expect the image to change at all. All that really matters is the relative sizes of things. So the unit type you attribute to the the numbers only matters to the programmer, and not to the program.
So you simply mentally declare that one unit is equal to one centimeter and create your objects and world according to that scale. There is no code level change to make this happen. It's merely a convention that you use to help you build things in correct dimensions relative to each other.
OpenGL does not have a notion for units. It just uses unit-less values. What these values mean is up to you. They just have to be consistent. So if your objects coordinates and viewing parameters are all specified with meters in mind and you have an object whose coordinates are in centimeters, just scale that object by a factor of 0.1.