forked from Garima13a/YOLO-Object-Detection
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvideo.py
More file actions
49 lines (34 loc) · 1.22 KB
/
Copy pathvideo.py
File metadata and controls
49 lines (34 loc) · 1.22 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# import cv2
# import time
from utils import *
from darknet import Darknet
# Load the network architecture
m = Darknet('./cfg/yolov3.cfg')
# Load the pre-trained weights
m.load_weights('./weights/yolov3.weights')
# Load the COCO object classes
class_names = load_class_names('data/coco.names')
# Set the NMS threshold
nms_thresh = 0.6
# Set the IOU threshold
iou_thresh = 0.4
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, m.width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, m.height)
while True:
ret, frame = cap.read()
original_image = frame
# We resize the image to the input width and height of the first layer of the network.
resized_image = cv2.resize(original_image, (m.width, m.height))
# Detect objects in the image
boxes = detect_objects(m, resized_image, iou_thresh, nms_thresh)
# Plot the image with bounding boxes and corresponding object class labels
frame = plot_boxes(original_image, boxes, class_names, plot_labels=True)
cv2.imshow('Video window', frame)
# press 'q' on keyboard to exit
# this call is necessary in order rendering to work.
# Returns control to event loop
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()