-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_detection_local.py
More file actions
28 lines (27 loc) · 1.02 KB
/
object_detection_local.py
File metadata and controls
28 lines (27 loc) · 1.02 KB
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
import numpy as np
import imutils
import cv2
from imageai.Detection import ObjectDetection
import tensorflow as tf
detector = ObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath('yolo-tiny.h5')
detector.loadModel(detection_speed="flash")
graph = tf.get_default_graph()
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
frame = imutils.resize(frame, width=600)
# print(type(frame))
with graph.as_default():
# img_array = np.array(frame)
detected_image_array, detections = detector.detectObjectsFromImage(input_type="array",
input_image=frame,
output_type="array")
# image_really = Image.fromarray(detected_image_array.astype('uint8')).convert('RGB')
cv2.imshow("Frame", detected_image_array)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
cap.stop()