0

If my phone camera is at a known height on my phone and it takes a picture from a known distance, how can I find out the actual height of an object at the bottom of the picture, considering that the camera is taking the photo from a top angle? This question talks of a similar problem, but the answers haven't taken camera angle and height into account. Here's a diagram of the setup - Phone photographing yellow object at the bottom

h is the actual height of the yellow box in front of the blue screen. This is the image captured by the camera -

Image captured by camera

How can I find h, given h' on the image? Assume the focal length of the camera is known.

Community
  • 1
  • 1
Caife
  • 415
  • 1
  • 5
  • 16
  • Pitagoras! Use Pitagoras – Ander Biguri Nov 21 '16 at 13:13
  • @Ander Biguri: Pitagoras is a good solution, however we know h' in image coordinates. We need to know the ratio between the size of pixels and the units of camera coordinates. So I think we also need the calibration matrix. Correct me if I'm wrong. – Ash Nov 21 '16 at 14:53
  • 1
    Your picture is pretty inaccurate. What you will see is two trapezoids sharing an edge, not a square. –  Nov 21 '16 at 15:56
  • @YvesDaoust Yes, sorry about the inaccurate picture. And this picture is only a highly abstract version of the challenge I'm facing. – Caife Nov 22 '16 at 05:21
  • @Caife: yep, but you don't realize that with such inaccuracy we don't even know what h' is. –  Nov 22 '16 at 07:50

2 Answers2

2

enter image description here

Assuming you know the calibration matrix K, here is a solution that I find simpler than calculating angles. Choose the points p1=(x,y) and p2=(r,s) as indicated in the figure above. Since you say that you know the distance from the camera to the object, that means you know the depth d of these points in camera coordinates, and

Q1=inverse(K)*p1*d
Q2=inverse(K)*p2*d

give you the corresponding points on the cube in camera coordinates. Now the height you seek is simply

abs(Q1-Q2)

Hope that helps.

Edit: Here's a quick explanation about the calibration matrix. When using the pinhole camera model, a 3d point P can be reprojected in the image plane via the multiplication KP where K is (assuming square pixels) the matrix

f 0   a
0  f  b
0  0  1

where f is the focal length expressed in terms of pixel size, and [-a,-b]^t is the center of the image coorrdinates system (expressed in pixels). For more info, you can just goolge "intrinsic camera parameters", or for a quick and dirty explanation look here or here. And maybe my other answer can help?

Note: In your case since you only care about depth, you do not need a and b, you can set them to 0 and just set f.

PS: If you don't know f, you should look into camera calibration algorithms (there are auto-calibrating methods but as far as I know they require many frames and fall into the domain of SLAM/SFM). However, I think that you can find pre-computed intrinsic parameters in Blender for a few known smartphone models, but they are not expressed in the exact manner presented above, and you'll need to convert them. I'd calibrate.

Community
  • 1
  • 1
Ash
  • 4,611
  • 6
  • 27
  • 41
0

I must be missing something, but I think this is quite easy (based on your assumptions, which include doing some type of image processing to detect the front and bottom edges of your object in order to get h') Keep in mind that you are also assuming that your distance from the top of the object to your camera is the same as from the bottom of your object to your camera. (at greater distances this becomes moot, but at close ranges, the skew can actually be quite significant)

The standard equation for distance:

dist = (focalDist(mm) * objectRealHeight(mm) * imageHeight(pix) ) / ( objectHeight(pix) * sensorHeight(mm) )

You can re-arrange this equation to solve for objectRealHeight since you know everything else...

Community
  • 1
  • 1
Sneaky Polar Bear
  • 1,611
  • 2
  • 17
  • 29