-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_nms.py
101 lines (61 loc) · 1.93 KB
/
test_nms.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 13 21:48:28 2018
@author: Administrator
"""
# import the necessary packages
from nms import non_max_suppression_fast
import numpy as np
import cv2
# construct a list containing the images that will be examined
# along with their respective bounding boxes
images = [
("images/audrey.jpg", np.array([
(19, 40, 271, 299),
(66, 92, 378, 393),
(71, 62, 360, 309)])),
("images/bksomels.jpg", np.array([
(247, 183, 447, 470),
(217, 260, 493, 553),
(187, 139, 531, 831),
(285, 308, 401, 585)])),
("images/gpripe.jpg", np.array([
(230, 117, 305, 193),
(246, 134, 292, 218),
(224, 105, 307, 253),
(311, 122, 366, 209),
(301, 122, 388, 191),
(323, 105, 293, 236)]))]
# loop over the images
for (imagePath, boundingBoxes) in images:
# load the image and clone it
print ("[x] %d initial bounding boxes" % (len(boundingBoxes)))
image = cv2.imread(imagePath)
orig=np.zeros(image.shape,np.uint8)
orig = image.copy()
# loop over the bounding boxes for each image and draw them
for (startX, startY, endX, endY) in boundingBoxes:
cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 0, 255), 2)
# perform non-maximum suppression on the bounding boxes
pick = non_max_suppression_fast(boundingBoxes, 0.5)
print ("[x] after applying non-maximum, %d bounding boxes" % (len(pick)))
# loop over the picked bounding boxes and draw them
for (startX, startY, endX, endY) in pick:
cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
# display the images
cv2.imshow("Original", orig)
cv2.imshow("After NMS", image)
cv2.waitKey(0)
#import numpy as np
#import nms
#
#boxes=[[200,200,400,400,0.99],
# [220,220,420,420,0.9],
# [100,100,150,150,0.82],
# [200,240,400,440,0.5],
# [150,250,300,400,0.88]]
#boxes=np.array(boxes)
#
#abc=nms.non_max_suppression_slow(boxes,0.8)
##abc=nms.py_cpu_nms(boxes,0.8)
#print(abc)