GithubHelp home page GithubHelp logo

asadullah-dal17 / yolov4-detector-and-distance-estimator Goto Github PK

View Code? Open in Web Editor NEW
92.0 2.0 25.0 26.23 MB

Python 100.00%
opencv python distance-calculation distacne distance-estimation-python distance-estimation-opencv distance-measure-opencv yolov4-distance-estimation yolov4-tiny

yolov4-detector-and-distance-estimator's Introduction

Yolov4-Detector-and-Distance-Estimator

Find the distance from the object to the camera using the YoloV4 object detector, here we will be using a single camera ๐Ÿ“ท, detailed explanation of distance estimation is available in another repository Face detection and Distance Estimation using single camera

YoloV4.Distance.Estimation.mp4

Video Tutorial Explains the concept and implementation YouTube Video Views

  • Here we are targeting the person and cell phone classes only, for demo purposes.

  • you can follow all the steps mentioned in the video to create other objects as well.

implementation detail available on Darknet


TO DO

  • Finding the distance of multiple objects at the same time.

Installation you need opencv-contrib-python

opencv contrib

windows

pip install opencv-contrib-python==4.5.3.56

Linux or Mac

pip3 install opencv-contrib-python==4.5.3.56

then just clone this repository and you are good to go.

I have used tiny weights, check out more on darknet GitHub for more


Add more Classes(Objects) for Distance Estimation

You will make changes on these particular lines DistanceEstimation.py

if classid ==0: # person class id 
    data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)])
elif classid ==67: # cell phone
    data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)])
    
# Adding more classes for distance estimation 

elif classid ==2: # car
    data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)])

elif classid ==15: # cat
    data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)])
# In that way you can include as many classes as you want 

    # returning list containing the object data. 
return data_list

Reading images and getting focal length

You have to make changes on these lines ๐Ÿ“ DistanceEstimation.py there are two situations, if the object(classes) in the single image then, here you can see my reference image it has to two object, person and cell phone

# reading reference images 
ref_person = cv.imread('ReferenceImages/image14.png')
ref_mobile = cv.imread('ReferenceImages/image4.png')
# calling the object detector function to get the width or height of the object
# getting pixel width for person
person_data = object_detector(ref_person)
person_width_in_rf = person_data[0][1]

# Getting pixel width for cell phone
mobile_data = object_detector(ref_mobile)
mobile_width_in_rf = mobile_data[1][1]

# getting pixel width for cat
cat_data = object_detector(ref_person)
cat_width_in_rf = person_data[2][1]

# Getting pixel width for car
car_data = object_detector(ref_person)
car_width_in_rf = person_data[3][1]

if there is single class(object) in reference image then you approach it that way ๐Ÿ‘

# reading the reference image from dir 
ref_person = cv.imread('ReferenceImages/person_ref_img.png')
ref_car = cv.imread('ReferenceImages/car_ref_img.png.png')
ref_cat = cv.imread('ReferenceImages/cat_ref_img.png')
ref_mobile = cv.imread('ReferenceImages/ref_cell_phone.png')

# Checking object detection on the reference image 
# getting pixel width for person
person_data = object_detector(ref_person)
person_width_in_rf = person_data[0][1]

# Getting pixel width for cell phone
mobile_data = object_detector(ref_mobile)
mobile_width_in_rf = mobile_data[0][1]

# getting pixel width for cat
cat_data = object_detector(ref_cat)
cat_width_in_rf = person_data[0][1]

# Getting pixel width for car
car_data = object_detector(ref_car)
car_width_in_rf = person_data[0][1]
# Then you find the Focal length for each

If you have any doubt DM me on insta Instagram


if You found this Helpful, please star โญ it.

You can Watch my Video Tutorial on Computer Vision Topics, just check out my YouTube Channel AiPhile Youtube

I am avalaible for paid work here Fiverr fiverr

๐Ÿ’š๐Ÿ–ค Join me on Social Media ๐Ÿ–ค๐Ÿ’š

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.