Skip to content Skip to sidebar Skip to footer

Camera To Object Distance Calculation Using Opencv And Python

I am using Microsoft Lifecam HD 3000 on my quadcopter for autonomous landing . I wish to calculate the distance between the onboard camera on the quadcopter and a landing pad which

Solution 1:

If the landing rectangle size is known/constant then it is doable

  1. some data to prepare

    Take image of the landing rectangle at known distance. Use your Microsoft Lifecam HD 3000 with the same setup as on the copter (or take it by itself) and compute/measure the rectangle size in pixels and store it. So you have:

    • xs0,ys0 - rectangle size [px]
    • d0 - distance from camera image was taken [m]
  2. take the image

    Find the rectangle on it and try to project it as it was taken perpendicular to camera view axis. Then compute its size in pixels xs,ys

  3. compute the distance

    Use the triangle similarity

    FOV example

    this image was done for this Q/A: Specifiyng speed from visual size which can be of help. So

    • h is the rectangle size in pixels in each axis
    • z is the distance from camera focus point

    so rewritten to names above you get

    • dx=d0*xs/xs0 [m]
    • dy=d0*ys/ys0 [m]

    dx and dy should be the same but if your image is not take perpendicular or have other distortions then they will be a bit different. So distance is average of it or min or max depends on safety reasons. For example

    • d=0.5*(dx+dy) [m]

[Notes]

The distances are measured from projection point of camera so if yo do not know its position take rectangle image from 2 known distances from known point and compute the focus position ...

Post a Comment for "Camera To Object Distance Calculation Using Opencv And Python"