#!/usr/bin/env python # coding: utf-8 # In[2]: get_ipython().run_line_magic('load_ext', 'watermark') get_ipython().run_line_magic('watermark', '-a "Romell D.Z." -u -d -p numpy,pandas,matplotlib,keras,imageai') # # 5. Objects Detection & Extraction # In[2]: get_ipython().run_line_magic('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"]) ) # 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")) # In[15]: for eachObject,image in zip(detections,extracted_images): print(eachObject["name"] + " : " + str(eachObject["percentage_probability"]) ) display(Image(filename=image)) # In[ ]: