I have a 640x480 camera that recognizes a rectangle that is 1ftx2ft. Is it possible to calculate the distance between the camera and the rectangle?


The horizontal angle of view is 54°.

  • $\begingroup$ You will need to know the field of view of the camera and how many pixels wide the rectangle appears in order to calculate the distance away. $\endgroup$ – Shard Jan 12 '13 at 23:24
  • $\begingroup$ I have these measurements, I don't know what to do next. $\endgroup$ – Belos Jan 12 '13 at 23:29
  • $\begingroup$ Knowing the field of view you can calculate how far away the rectangle would have to be to completely fill the view with trigonometry. $\endgroup$ – Shard Jan 12 '13 at 23:42

$$D=\frac{Lw}{2x\tan\frac\alpha2}$$ where $D$ = Distance from Camera, $L$ = length of object (2ft), $w$=width of screen in pixels (640), $x$=width of object on camera in pixels, and $\alpha$ = camera field of view.

  • $\begingroup$ Is it assumed that the rectangle is in the center of the screen or it doesn't matter? $\endgroup$ – Belos Jan 13 '13 at 0:31
  • $\begingroup$ With a narrow field of view it shouldn't matter where the rectangle is. But it is important that the rectangle is facing flat on to the camera. If you had been using a wide angle lens things might be trickier. $\endgroup$ – Shard Jan 13 '13 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.