Created
August 22, 2022 08:21
-
-
Save andreconghau/fcbe5397520d940d79725f635f22ca1c to your computer and use it in GitHub Desktop.
simple_detection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from imageai.Detection import ObjectDetection | |
import os | |
execution_path = os.getcwd() | |
print(execution_path) | |
detector = ObjectDetection() | |
detector.setModelTypeAsRetinaNet() | |
detector.setModelPath( os.path.join(execution_path, "resnet50_coco_best_v2.1.0.h5")) # Download the model via this link https://github.com/OlafenwaMoses/ImageAI/releases/tag/1.0 | |
detector.loadModel() | |
input_image=os.path.join(execution_path, "02.png") | |
output_image_path=os.path.join(execution_path, "02_detected.jpg") | |
print(input_image) | |
print(output_image_path) | |
detections = detector.detectObjectsFromImage(input_image, output_image_path, minimum_percentage_probability=40) | |
for eachObject in detections: | |
print(eachObject["name"], " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] ) | |
print("--------------------------------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Custom Filter get only person or something
https://imageai.readthedocs.io/en/latest/detection/index.html
There are 80 possible objects that you can detect with the
ObjectDetection class, and they are as seen below.
To detect only some of the objects above, you will need to call the CustomObjects function and set the name of the
object(s) yiu want to detect to through. The rest are False by default. In below example, we detected only chose detect only person and dog.