-
Notifications
You must be signed in to change notification settings - Fork 3
/
objectDetection.py
42 lines (33 loc) · 956 Bytes
/
objectDetection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Object Detection using ImageAI and YOLO
#Loading Modules
import cv2
from imageai import Detection
#Defining Path
modelpath = ""
#Loading YOLO
yolo = Detection.ObjectDetection()
yolo.setModelTypeAsYOLOv3()
yolo.setModelPath(modelpath)
yolo.loadModel()
#Loading Camera
cam = cv2.VideoCapture(0)
while True:
#Read frames
ret, img = cam.read()
#Predict
img, preds = yolo.detectCustomObjectsFromImage(input_image=img,
custom_objects=None, input_type="array",
output_type="array",
minimum_percentage_probability=70,
display_percentage_probability=False,
display_object_name=True)
#Display predictions
cv2.imshow("", img)
print(preds)
#Press 'q' or 'esc' to break
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
#Close camera
cam.release()
cv2.destroyAllWindows()