In another post, we explained how to apply Object Detection in Tensorflow. In this post, we will provide some examples of how you can apply Object Detection using the YOLO algorithm in Images and Videos. For our example, we will use the ImageAI Python library where with a few lines of code we can apply object detection.

Object Detection in Images

Below we represent the code for Object Detection in Images.

from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "cycling001.jpg"), output_image_path=os.path.join(execution_path , "new_cycling001.jpg"), minimum_percentage_probability=30)
for eachObject in detections:
    print(eachObject["name"] , " : ",    eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("--------------------------------")

And we get:

car  :  99.66793060302734  :  [395, 248, 701, 405]
--------------------------------
bicycle  :  66.10226035118103  :  [81, 270, 128, 324]
--------------------------------
bicycle  :  99.86441731452942  :  [242, 351, 481, 570]
--------------------------------
person  :  99.92108345031738  :  [269, 186, 424, 540]
--------------------------------

#python #computer-vision #object-detection #opencv #ai

YOLO: Object Detection in Images and Videos
1.45 GEEK