AdSense

Sunday, May 31, 2020

Object Detection with Less Than 10 Lines of Python Code

Object Detection with Less Than 10 Lines of Python Code



0_MacOS_Python_setup.txt
# Install on Terminal of MacOS

#pip3 install -U opencv-python

#pip3 install -U cvlib

#pip3 install -U matplotlib

#pip3 install -U tensorflow



1_MacOS_Terminal.txt
########## Run Terminal on MacOS and execute
### TO UPDATE
cd "YOUR_WORKING_DIRECTORY"


python3 od01.py 1.jpeg

python3 od01.py 2.jpeg

python3 od01.py 3.jpeg

python3 od01.py 4.jpg





Image files

1.jpeg


2.jpeg


3.jpeg


4.jpg



Python files

od01.py
########## Object Detection with Less Than 10 Lines of Python Code ##########

# Save image files from the following website:
# https://towardsdatascience.com/object-detection-with-less-than-10-lines-of-code-using-python-2d28eebc5b11
# https://stackabuse.com/object-detection-with-imageai-in-python/

# Run this script on Terminal of MacOS as follows:
#
# python3 od01.py 1.jpeg
#
# More generally,
# python3 od01.py (image file name)


# Reference
#
# Object Detection with Less Than 10 Lines of Code Using Python
# Find out what objects are in the image
# by Sabina Pokhrel
# https://towardsdatascience.com/object-detection-with-less-than-10-lines-of-code-using-python-2d28eebc5b11


import cv2
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox
import sys


imtmp = sys.argv[1]


im = cv2.imread(imtmp)

bbox, label, conf = cv.detect_common_objects(im)
output_image = draw_bbox(im, bbox, label, conf)
plt.imshow(output_image)
plt.savefig("Objects_detected_" + imtmp)
plt.show()





Output images
Objects_detected_1.jpeg


Objects_detected_2.jpeg


Objects_detected_3.jpeg


Objects_detected_4.jpg



References
Download csv data from the following website and save it to your working directory (where the lgrs01.py script is saved):
https://drive.google.com/open?id=1Upqoz2gIAYq6LByD7YjHU-9_9K4EOhOh
User_Data.csv

No comments:

Post a Comment

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights ...