-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectDetection.py
More file actions
34 lines (28 loc) · 918 Bytes
/
ObjectDetection.py
File metadata and controls
34 lines (28 loc) · 918 Bytes
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
modelpath = "yolo.h5"
from imageai import Detection
yolo = Detection.ObjectDetection()
yolo.setModelTypeAsYOLOv3()
yolo.setModelPath(modelpath)
yolo.loadModel()
import cv2
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1300)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 1500)
while True:
## read frames
ret, img = cam.read()
## predict yolo
img, preds = yolo.detectObjectsFromImage(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)
## press q or Esc to quit
if (cv2.waitKey(1) & 0xFF == ord("q")) or (cv2.waitKey(1)==27):
break
## close camera
cam.release()
cv2.destroyAllWindows()