Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the Dimensions (Height ,width) of an Object using Camera

Tags:

I want to find the solution to get the dimensions of an Object Using Camera, Well it sounds like Duplicate one

How to measure height, width and distance of object using camera?

But the solution doesn't help me out.Well from the Above link i got some idea to find out the distance (Measure Distance).

Can somebody suggest me how am i supposed to get the width as well as height of an object. Simple math or any Idea would be really helpful.

Is there any possibilities to achieve the above solution using OpenCV. Measure Height and Width

What i have tried so far:

enter image description here

Suppose we assume the Fixed Distance , We can calculate Angle of elevation

tan(α/2) = (l/2)/d,

hence

α = 2*atan(l/2d)

But still we don't know the value of L (Length of the object)

Another way to find the View angle:

  double thetaV = Math.toRadians(camera.getParameters().getVerticalViewAngle());
  double thetaH = Math.toRadians(camera.getParameters().getHorizontalViewAngle());

Seems Not working !!

like image 547
Janmejoy Avatar asked Apr 01 '16 06:04

Janmejoy


1 Answers

The actual physics of a lens are explained for example on this website of Georgia State University.

See this illustration which explains how you can use either the linear magnification or focal length relations to find out object size from image size:

Nice lens illustration with equations

In particular, -i / h' = o / h, and this relation o / h holds true for all similar triangles (that is, an object of size 2h at distance 2o has the same sizeh' on the picture). So as you can see, even in the case of the full equation, you can't know both the distance o and the size h of an object -- however one will give you the other.

On the other hand, two objects at the same distance o will see their sizes h1' and h2' on the image be proportional to their sizes in real life h1 and h2, since h1' / h1 = M = h2' / h2.

Hence if you know for one object both oand h, you know M, thus knowing an object's size on film you can deduct its size from its distance and vice versa.

The -i / h' value is naturally expressed for the maximal h'. If the size of an object fills the image exactly, it fills the field of view, then the ratio of its distance to its size is tan(α/2) = (l / 2) / d (note that in the conventions of the image below, d = o and l = 2 * h).

enter image description here

This α is what you name theta in your example. Now, from the image size you can get under what angle you see the image -- that is, what size l would the image be if it were at distance d. From there, you can deduce the size of the object from its distance and vice versa.

Algorithm steps:

  1. get ratio r = size of object in image (in px) / total size of image (in px).
    Do this along the axis for which you know or plan to get the real object size, of course.
  2. get the corresponding field of view and angle multiply r by the tangent of half that angle
    r *= tan(camera.getParameters().getXXXXViewAngle() / 2)
  3. r is now the tangent of the half-angle under which you see the object, hence the following relations are true: r = (l / 2) / d = h / o (with the respective drawing's notations).
    • If you know the distance d to the object, its size is l = 2 * r * d
    • If you know the size l of the object, it is at distance is d = l / (2 * r)

This works for objects hat are actually pointed at by the camera, if they aren't centred the maths may be off.

like image 137
Cimbali Avatar answered Oct 11 '22 03:10

Cimbali