YOLO: Object Detection in Images and Videos

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]
--------------------------------

We also represent the Original and the Detected Image

Notice that it was able to detect the bicycle behind-A-M-A-Z-I-N-G!!!

ML Jobs

Let’s provide another example of the Original and the Detected image

Notice that it detected the bed, the laptop and the two persons!

Trending AI Articles:

1. Microsoft Azure Machine Learning x Udacity — Lesson 4 Notes

2. Fundamentals of AI, ML and Deep Learning for Product Managers

3. Roadmap to Data Science

4. Work on Artificial Intelligence Projects

Object Detection in Videos

Assume that you have a video in your PC called “Traffic.mp4”, then by running this code you will be able to get the detected objects:

from imageai.Detection import VideoObjectDetection
import os
execution_path = os.getcwd()
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "Traffic.mp4"),
output_file_path=os.path.join(execution_path, "New_Traffic")
, frames_per_second=20, log_progress=True)
print(video_path)

And the detected video is here:

Let’s provide another example of a Video:

Object Detection using your Camera

The following examples show how we can use our USB camera for Object Detection:

from imageai.Detection import VideoObjectDetection
import os
import cv2
execution_path = os.getcwd()
camera = cv2.VideoCapture(0)
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
video_path = detector.detectObjectsFromVideo(camera_input=camera,
output_file_path=os.path.join(execution_path, "camera_detected_video")
, frames_per_second=20, log_progress=True, minimum_percentage_probability=30)
print(video_path)

Below I represent just a snapshot of the recorded video of my office while I was coding. As you can see it was able to detect the books of the library behind me!

Don’t forget to give us your ? !


YOLO: Object Detection in Images and Videos was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

Via https://becominghuman.ai/yolo-object-detection-in-images-and-videos-7a5ae09a69b4?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/yolo-object-detection-in-images-and-videos

Published by 365Data Science

365 Data Science is an online educational career website that offers the incredible opportunity to find your way into the data science world no matter your previous knowledge and experience. We have prepared numerous courses that suit the needs of aspiring BI analysts, Data analysts and Data scientists. We at 365 Data Science are committed educators who believe that curiosity should not be hindered by inability to access good learning resources. This is why we focus all our efforts on creating high-quality educational content which anyone can access online.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started