Given 2 pixels, how can I compute the real distance with ARCore? - arcore

Given an image (frame) I would like to have a function that takes 2 pixels as an argument and then returns the real world distance between those pixels. Is this possible with ARCore? Note that the image is just a random frame of a series of frames, so that initializing measurement should work.
What could I look into for this?

Related

Calculate focus to map world point on imageplane

I try to calculate the focus value to map a world point on to image plane.
I use raspberry pi camera v2. I did get the camera matrix from opencv it gives me for fx and fy 204. Got nearly the same value by measuring at known distance and size of object.
But when I use a formular I get wrong values.
My formular is
Fpix=sensorsize_pix * focus_mm/sensorsize_mm=1pix*focus_mm/pixsize_mm
I'm using as values:
320x240 image.
Image is taken with 640x480 resolution and then binned 2x2 in Software.
Because the image is already binned by driver I would have a total binning of 4x4.
The original pixel size 1.4um and focus 3.00mm
Which would give me a binned pixelsize of 5.6um.
So I would calculate
Fpix=1pix*3.0mm/0.0056mm=536pix
which is a huge difference to 204pix
The specification for the sensor can be found herelink
As I would consider opencv and measurements as correct. Something must be wrong with my formular.

how to get the real distance between two points in image?

HI I am using opencv to detect two objects in frame and calculate the distance between them in pixel but I need to calculate the distance between them in meter can you give the realtionship between the meter and pixel
This is generally impossible: From a single image the scale of reconstructed 3d points is unknown.
Your options are either to
Add more views, and calculate the depth using stereo vision algorithms.
Use knowledge about the size of the objects to determine the distance.
Edit
Given the depth z, camera calibration matrix K and image point x we can get the corresponding 3D-point Xas:
X = z * inv(K) * x
with x is in homogeneous coordinates.
When you have the two 3D points on the object, calculating the distance is trivial.
"thank you I try to use the size but I need the relationship between the real size in meter and the size in pixel with known distance between camera and the object"
What you need to do is have the object is question at a certain distance from the camera and measure the pixels. Then, move this object further or closer from/to the camera and measure the change pixels again.
From this you can ascertain the ratio of the change in pixels which is equivalent to the change in distance, thus the distance of the object from the camera. It's just a simple differential equation.
Assuming the size of the object in question is fixed or scaled to the object used to calculate the ratio, this approach should provide a rough estimate of the distance of the objects to the camera.
You then need to use this ratio to help with calculating the distance between the objects as it would be somewhat inverse proportional to the distance between the objects when their distance to the camera increases.
However this method is very messy and can be inefficient. A better approach would be using two different cameras and looking at the disparity between both as mentioned by Hannes

Measuring object size using webcam

I need to calculate distance between two points using a webcam. Now the catch is I don't need it to be any way related to actual measurements in cm or whatever. What I want is to use different webcams of different resolutions and they should all give the same measurement. I'll explain.
Suppose I am viewing a square shape using a webcam of 640x480 and it measures as one unit. I then view the same object from the same positions using a webcam of 1024x768 and it should still measure as 1 unit. How do I do this?
You didn't mentioned about the process by which you are measuring the dimensions of the object. I'm gonna assume you are measuring by using a single camera. You can take this method as a reference & this can be applied to any methodology.
Here are the steps to measure the size of object:
How will you measure length of a line drawn in this picture?
You need a ruler as a reference. To make this ruler you have to know the real world ruler size which will be in pixels in our case.
Now make a graph. I'm gonna take a unit line as a reference graph. I'm taking centimeter scale as reference.
Place this graph in front of the camera & detect the Two red dots. Now calculate the number of pixels between this two points ref. Lets assume the distance is 1000 pixels. So 1 cm is taking 1000 pixels. So 1 pixel is equal to 0.1 cm & take this as a Reference_pixels_count.
Repeat this step 4 for all the resolutions & find the Reference_pixels_count for that Resolution.
Now place an object & get the size of image.find corners & cycle through each corner and find the distance between each corner. Multiply this distance with the Reference_pixels_count to get the actual dimension of the object.
NOTE: This method can work only for flat object with negligible depth change.

Determining pixel coordinates across display resolutions

If a program displays a pixel at X,Y on a display with resolution A, can I precisely predict at what coordinates the same pixel will display at resolution B?
MORE INFORMATION
The 2 display resolutions are:
A-->1366 x 768
B-->1600 x 900
Dividing the max resolutions in each direction yields:
X-direction scaling factor = 1600/1366 = 1.171303075
Y-direction scaling factor = 900/768 = 1.171875
Say for example that the only red pixel on display A occurs at pixel (1,1). If I merely scale up using these factors, then on display B, that red pixel will be displayed at pixel (1.171303075, 1.171875). I'm not sure how to interpret that, as I'm used to thinking of pixels as integer values. It might help if I knew the exact geometry of pixel coordinates/placement on a screen. e.g., do pixel coordinates (1,1) mean that the center of the pixel is at (1,1)? Or a particular corner of the pixel is at (1,1)? I'm sure diagrams would assist in visualizing this--if anyone can post a link to helpful resources, I'd appreciate it. And finally, I may be approaching this all wrong.
Thanks in advance.
I think, your problem is related to the field of scaling/resampling images. Bitmap-, or raster images are digital photographs, so they are the most common form to represent natural images that are rich in detail. The term bitmap refers to how a given pattern (bits in a pixel) maps to a specific color. A bitmap images take the form of an array, where the value of each element, called a pixel picture element, correspond to the color of that region of the image.
Sampling
When measuring the value for a pixel, one takes the average color of an area around the location of the pixel. A simplistic model is sampling a square, and a more accurate measurement is to calculate a weighted Gaussian average. When perceiving a bitmap image the human eye should blend the pixel values together, recreating an illusion of the continuous image it represents.
Raster dimensions
The number of horizontal and vertical samples in the pixel grid is called raster dimensions, it is specified as width x height.
Resolution
Resolution is a measurement of sampling density, resolution of bitmap images give a relationship between pixel dimensions and physical dimensions. The most often used measurement is ppi, pixels per inch.
Scaling / Resampling
Image scaling is the name of the process when we need to create an image with different dimensions from what we have. A different name for scaling is resampling. When resampling algorithms try to reconstruct the original continuous image and create a new sample grid. There are two kind of scaling: up and down.
Scaling image down
The process of reducing the raster dimensions is called decimation, this can be done by averaging the values of source pixels contributing to each output pixel.
Scaling image up
When we increase the image size we actually want to create sample points between the original sample points in the original raster, this is done by interpolation the values in the sample grid, effectively guessing the values of the unknown pixels. This interpolation can be done by nearest-neighbor interpolation, bilinear interpolation, bicubic interpolation, etc. But the scaled up/down image must be also represented over discrete grid.

Finding the actual size of an object using kinect depth data

I was wondering how would I figure out the actual size of the object, using the kinect depth values.
For example, if the kinect sees a round object in front of it, and the round object take 100 pixels of space in the image, and the depth value the kinect gives is x, how would I know the actual size of the round object?
I don't need it in units like meters or anything, I am just trying to find a formula to calculate the size of object that is independant from how far the object is from the kinect.
I am using OpenCV and the kinect SDK, if anything is useful there please let me know.
Thanks in advance.
To find the size in 3d, given a size in 2d, you just do:
3d_rad = 2d_rad * depth
So if the ball appears on the screen as 10 pixels wide and is 1 metre away, it really is 10 "units" wide. Do a little playing to find out the units returned, I'm unsure what they will be.
Suppose you have a 20 pixel radius ball on screen and the depth is returned as 30, the real size of the ball is 20*30 = 600 units. Again, I'm unsure what unit exactly, it depends on the camera, but it is a constant so play around with it. Put a 1 metre ball in front of the camera, far enough away that it looks like 100 pixels. The reciprocal of that distance should be the conversion factor to turn the units you have into centimetres and can be used as a constant. For example:
3d_rad_in_cm = conversion * 2d_rad * depth

Resources