Skip to content

MASIFAYUB/Distance_measurement_using_single_camera

 
 

Repository files navigation

Distance measurement using single:one:camera :camera:

GitHub Repo stars GitHub forks YouTube Channel Subscribers

You can use this code to measures the distance from object to camera using single camera 📷 .

I have detect a face in the frame and estimated a distance using the width of face.

✔️ I have included Speed Estimation code is well check that out.

✔️ I have include Distance estimation of multiple objects using Yolo V4 Object Detector Opencv-python

Clone this Repo:

git clone https://github.com/Asadullah-Dal17/Distance_measurement_using_single_camera

install Opencv-python

  • Windows

    pip install opencv-python

  • install Opencv-python on Linux or Mac

    pip3 install opencv-python

Run the code

  • windows: 👇

    python distance.py

    ------ OR ---------

    python Updated_distance.py

  • linux or Mac 👇

    python3 distance.py

    ------ OR ---------

    python3 Updated_distance.py

💡Focal Length Finder Function Description 💡

# focal length finder function
def FocalLength(measured_distance, real_width, width_in_rf_image):
    focal_length = (width_in_rf_image* measured_distance)/ real_width
    return focal_length

The Focal Length finder Function Tacks Three Arguments:

measured_distance It is distance which we have measured while capturing reference image:straightruler:. **_From object to Camera** which is Known_distance = 72.2 #centimeter

real_width Its measure with width of object in real world, here i measure the width of face in real world which was Known_width =14.3 #centimeter

width_in_rf_image it width of object in the image/frame it will be in pixels

💡Distance Finder Function Description 💡

# distance estimation function
def Distance_finder (Focal_Length, real_face_width, face_width_in_frame):
    distance = (real_face_width * Focal_Length)/face_width_in_frame
    return distance

This Funciton Taks Three Argument,

Focal_Length it is focal length, out of FocalLength finder function.

real_face_width Its measure width of object in real world, here i measure the width of face in real world which was Known_width =14.3 #centimeter

face_width_in_frame width of face in the frame, unit will pixels here.

Updated_Distance.py Looks something likes This.

Youtube Tutorial YouTube Video Views

Gif Update Distnace code

Speed and Distance Estimation

Youtube Tutorial YouTube Video Views speed and Distance Estimation

I have also create Face Following Robot which use distance Estimation, if you are interested you can Watch my Youtube Video

if You found this Helpful, please star ⭐ it.

if you have any Query feel free to ask me on my Social Media.

Keep me motivated to work on project like these, please subscribe to my Youtube Channel

💚 Join Me on Social Media 💚

AiPhile Youtube AiPhile Facebook AiPhile Insta Github

About

using single camera to measure the distance opencv python,

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%