How to Measure Height, Width and Distance of Object Using Camera

How to measure height and width of object using camera?

I am answering this in context of:

I want to make this type of application not exactly same but quite same but for my requirement I want to measure my image height and width using camera.

You can get height and width of ImageView by using getWidth() and getHeight() through while this will not give you the exact width and height of the image, for getting the Image width height first you need to get the drawable as background then convert drawable to BitmapDrawable to get the image as Bitmap from that you can get the width and height like here

Bitmap b = ((BitmapDrawable)imageView.getBackground()).getBitmap();
int w = b.getWidth();
int h = b.getHeight();

or do like here

imageView.setDrawingCacheEnabled(true);
Bitmap b = imageView.getDrawingCache();
int w = b.getWidth();
int h = b.getHeight();

the above code will give you current imageview sized bitmap like screen shot of device

for only ImageView size

imageView.getWidth(); 
imageView.getHeight();

If you have drawable image and you want that size you can get like this way

Drawable d = getResources().getDrawable(R.drawable.yourimage);
int h = d.getIntrinsicHeight();
int w = d.getIntrinsicWidth();


╔═══════════════════════════════╗   ^
║ ImageView ╔══════════════╗ ║ |
║ ║ ║ ║ |
║ ║ Actual image ║ ║ |
║ ║ ║ ║ |60px height of ImageView
║ ║ ║ ║ |
║ ║ ║ ║ |
║ ╚══════════════╝ ║ |
╚═══════════════════════════════╝ v
<------------------------------->
90px width of ImageView

how to measure height, width and distance of object using camera in phone?

I think it's not possible, since iOS devices don't have such sensors. No echo-locators, no even second rear camera for getting stereo image and using paralax effect for analyzing distance. You have only flat 2d image.

Find width of an object from camera and sensors

Well I am answering my own question to help others having same problem.

In order to find the width follow below steps. This requires a 3D imagination to understand

1) User need to enter the height of the point of observation(that is camera height from ground) manually .

2) The object whose width is to be measured , needs to be at the same level where the person is standing.

3) We need to point at bottom of the object's start point from the same height and capture the angle.

4) Then we need to tilt the device at the same height and capture the bottom of the end point of object and measure the angle.

5) With the angle and camera height from ground, we will find the respective distance of both sides applying tan rule.

   tan(θ)=opposite/adjacent
tan(θ)=height_of_camera/distance

6) From the distances we calculated in previous step and with the height of camera, using pythagorean theorem, calculate the projected distances ie.camera to the objects start and end points(imagine in 3D view)

7) Now as we have 2 sides and one angle use the following formula(cosine rule) to get the other side which is the width of the object.

  Width = sqrt((s1*s1) + (s2*s2) − 2(s1)(s2)cos(θ))
s1=sideOne , s2=sideTwo

Is it possible to measure distance to object with camera?

Well you should read how ithinkdiff.com "measures" the distance:

Uses the angle of the iPhone to estimate the distance to a point on the ground.
Hold the iPhone in front of you, align the point in the camera and get a direct
reading of the distance. The distance can then be used in the speed tool.

So basically it takes the height of where you hold the phone (eye-level), then you must point the camera to the point where object touches the ground. Then the phone measures the inclination and with simple trigonometry it calculates distance.

This is of course not very accurate. It gets less accurate the further the object is. Also it assumes that the ground is level.



Related Topics



Leave a reply



Submit