Yolo is a Deep Learning algorithm which is used to perform object detection in images or real time videos.
In this project I created a package using which you can easily add object detection functionalities in any of your application.
As YOLO is very Dense Neural Network, it need lot of computing power to execute. Therefore I will suggest to use GPU while running these programs.
Note - I did not include yolo3.weights
and yolo3.cfg
files in this repository. You can download those files from https://pjreddie.com/darknet/yolo/
In this repository there is a folder named detection
. detection.py
is a main file
in which the Object Detection code is written in OOPs format. There is a class Yolo
which
performs the task of detection.
Yolo class from this repository needs parameters like follows -
weights_path
- Pass the path of yolo3.weights
file.conf_path
- Pass the path of yolo3.cfg
file.label_path
- Pass the path of coco.names
file.yolo_shape
- Pass the value of input shape for particular YOLO model of which weights you passedthreshold_confidence
- Pass the Threshold Confidence. Detected objects has the confidence above the threshold confidence value. By Default it is 0.95.These are the parameters that need to pass to Yolo
class while creating its object.
The Yolo class contains following functions -
detect_objects(image)
- This function is used to detect and locate the objects in the image. We have to pass
the image array with BGR Format. (You can also use the OpenCV's cv2.imread()
function to read the image and
then pass it to the function). This function returns a Dictionary having object name as key and
its location in image as value.
Returned dictionary of this function-
{'person': [524, 315, 155, 428], 'dog': [723, 456, 144, 169]}
Here, in the returned dictionary keys are the detected objects and the value is a list of location of the object in that image. List has X co-ordinate of center, Y co-ordinate of center, Width and Height of object Respectively
draw_objects(image, object_location)
- This function takes the same image and the object-location dictionary as a
argument. It returns the new image with drawn bounding boxes over the detected objects.
Returned Image -
I created two demo projects detection-from-image and real-time-detection which will give you an idea that how can you use this project.
detection-from-image.py
file will apply object detection on images.
real-time-detection.py
file will detect objects using the webcam of your PC.