-1

i need to measure the distance between the pi camera module and the object , i've found this formula

distance to object (mm) = focal length (mm) * real height of the object (mm) * image height (pixels)
                          ---------------------------------------------------------------------------
                          object height (pixels) * sensor height (mm)

i have found that for the pi NoIR we have :

Focal length : 3.60 mm +/- 0.01

real height of the object : i'm capturing people so it can be between 150 cm and 200 cm

image height (pixels) : 1944 (true ??)

object height (pixels) : ??

sensor height :3.67 x 2.74 mm (so the height should be 2.74 mm)

I found some parameters in the camera docs but i need your help for the others that marked with "?"

http://elinux.org/Rpi_Camera_Module https://www.raspberrypi.org/documentation/hardware/camera.md

thanks :)

2

Object height in pixels is what you measure in the captured images, based on this you can calculate the distance to the object.

You can rearrange the formula into distance to object (mm) = some constant (mm*pixels) ---------------------- object height (pixels) and then determine the constant from a few measurements with the object at different, known distances.

Update: measuring the object height in an image

I have only used simpleCV in Python, which I heard is easier to use than openCV directly. For determining the object height, I would try the following steps.

  • detect the object. This is easiest if the object has a distinct color from the background. Look at the openCV tutorials, and adapt their example code. Try colordistance from the color of the object.

  • do blob detection, where the idea is to find and isolate the object from the rest of the image

  • once the object is a "blob" you should be able to measure its properties, e.g. the height.

If you can choose the object yourself, it would be easy if you choose a sphere, since then the size in the image will not depend on the orientation (rotation) of the object.

7
  • i can't figure out what is the difference between real height of the object and object height and why it's in pixels > thanks
    – The Beast
    Jul 26 '15 at 21:41
  • 2
    well, real height of the object (mm) is just the height of the object itself, in millimeters. Object height (pixels) is how many pixels high it is on the camera's image.
    – Frepa
    Jul 26 '15 at 22:19
  • and so what is the difference between object height (px) and image height (px) :p
    – The Beast
    Jul 27 '15 at 16:58
  • Image height (px) is the number of pixels in the image sensor in the vertical direction. Together with sensor height (mm) they are used to find how high one single physical pixel is on the sensor.
    – Frepa
    Jul 28 '15 at 9:05
  • i have found sensor height but i didn't understand well your answer , are you talking about Pixel size : it's 1.4 µm x 1.4 µm !!! and what about object height --> thanks a lot
    – The Beast
    Jul 28 '15 at 10:24

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.