-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
yolo.py
63 lines (49 loc) · 1.92 KB
/
yolo.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import argparse
import cv2 as cv
import time
import os
from yolo_utils import infer_image
from pathlib import Path
FLAGS = []
def yolo_detect(frames,labelh,net):
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--labels',
type=str,
default='./yolov3-coco/coco-labels',
help='Path to the file having the labels in a new-line seperated way.')
parser.add_argument('-c', '--confidence',
type=float,
default=0.5,
help='The model will reject boundaries which has a \
probabiity less than the confidence value. \
default: 0.5')
parser.add_argument('-th', '--threshold',
type=float,
default=0.3,
help='The threshold to use when applying the Non-Max Suppresion')
FLAGS, unparsed = parser.parse_known_args()
# Get the labels
labels = open(FLAGS.labels).read().strip().split('\n')
# Intializing colors to represent each label uniquely
colors = np.random.randint(0, 255, size=(len(labels), 3), dtype='uint8')
# Get the output layer names of the model
layer_names = net.getLayerNames()
layer_names = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
height , width = None, None
writer = None
count = 0
for frame in frames:
print("frame count :",count)
detect = 0
if(count%2==0):
if width is None or height is None:
width = frame.shape[1]
height = frame.shape[0]
detect = infer_image(net, layer_names, height, width, frame, colors, labels, FLAGS,labelh)
count += 1
if detect == 0:
continue
else:
return detect
return detect