Distance measurement using single1οΈβ£camera π·
If you want to estimate distance of objects with your simple webcam, then this algorithm(Triangle similarity) would be helpful for you to find Distance from object to camera, I have provide to two examples, one is simple face detection and distance Estimation, other is Yolo4 object detection and distance Estimation
Here in this readme file you will get short description, if need more details, then you can watch video tutorial on YouTube as well.
Distance & Speed Estimation Demo
Distance.and.Speed.Estimation.Demo.mp4
Video Tutorials
Distance Estimation Youtube Tutorail
Distance & Speed Estimation Youtube Tutorial
YoloV4 Object Detection & Distance Estimation Project GitHub Repository
YoloV4 Distance Estimation
YoloV4.Distance.Estimation.mp4
Distance Estimation on Raspberry Pi π
Distnace.Estiamtion.on.Pi.mp4
βοΈ here is source code and details for Instllation of Opencv-python on π Pi π Distance Estimation on Raspberry pi π
βοΈ I have included Speed Estimation code is well check that out.
βοΈ You can find the implementation of 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 focal_length(measured_distance, real_width, width_in_rf_image):
focal_length_value = (width_in_rf_image * measured_distance) / real_width
#return focal length.
return focal_length_value
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.
I have also create Face Following Robot which use distance Estimation, if you are interested you can Watch my Youtube Video You can create Face Following Robot with Raspberry that would be easy then, using Arduino Stuff, Raspberry π Pi will make it system on Robot π€
if You found this Helpful, please star β it.
You can Watch my Video Tutorial on Computer Vision Topics, just check out my YouTube Channel
If You have any Question or need help in CV Project, Feel free to DM on Instagram
I am avalaible for paid work here Fiverr