5. Objects Detection & Extraction

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from IPython.display import Image,display
In [3]:
pathA = 'snapshot/teamA.jpg'
pathB = 'snapshot/teamB.jpg'
In [ ]:
from imageai.Detection import ObjectDetection
import os

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( "../../../Python Samples/_TensorFlow/models/resnet50_coco_best_v2.0.1.h5")
detector.loadModel()
In [10]:
detections = detector.detectObjectsFromImage(input_image= "snapshot/teamA.jpg",
                                            output_image_path= "snapshot/objectDetectionTeamA.jpg",
                                             minimum_percentage_probability = 80)
In [11]:
for eachObject in detections:
    print(eachObject["name"] + " : " + str(eachObject["percentage_probability"]) )
potted plant : 91.03466868400574
person : 91.60103797912598
person : 90.57185053825378
person : 95.18238306045532
person : 97.53724932670593
In [12]:
display(Image(filename="snapshot/teamB.jpg"))
In [13]:
detections, extracted_images = detector.detectObjectsFromImage(input_image= "snapshot/teamB.jpg",
                                                               output_image_path= "snapshot/objectDetectionTeamB.jpg",
                                                               minimum_percentage_probability = 65,
                                                               extract_detected_objects=True)
In [14]:
display(Image(filename="snapshot/objectDetectionTeamB.jpg"))