Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4c4c878b
Commit
4c4c878b
authored
Jan 20, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add detection to ground truth matching
according to Piotr Dollar paper
parent
d1952f28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
52 deletions
+65
-52
roc_test.py
apps/sft/misk/roc_test.py
+13
-8
sft.py
apps/sft/misk/sft.py
+52
-44
No files found.
apps/sft/misk/roc_test.py
View file @
4c4c878b
...
...
@@ -7,6 +7,11 @@ import sys, os, os.path, glob, math, cv2
from
datetime
import
datetime
import
numpy
# "key" : ( b, g, r)
bgr
=
{
"red"
:
(
0
,
0
,
255
),
"green"
:
(
0
,
255
,
0
),
"blue"
:
(
255
,
0
,
0
)}
def
call_parser
(
f
,
a
):
return
eval
(
"sft.parse_"
+
f
+
"('"
+
a
+
"')"
)
...
...
@@ -37,10 +42,10 @@ if __name__ == "__main__":
dom
=
xml
.
getFirstTopLevelNode
()
assert
cascade
.
load
(
dom
)
frame
=
0
pattern
=
args
.
input
camera
=
cv2
.
VideoCapture
(
args
.
input
)
camera
=
cv2
.
VideoCapture
(
pattern
)
frame
=
0
while
True
:
ret
,
img
=
camera
.
read
()
if
not
ret
:
...
...
@@ -53,17 +58,17 @@ if __name__ == "__main__":
boxes
=
samples
[
tail
]
boxes
=
sft
.
norm_acpect_ratio
(
boxes
,
0.5
)
if
boxes
is
not
None
:
sft
.
draw_rects
(
img
,
boxes
,
(
255
,
0
,
0
),
lambda
x
,
y
:
y
)
frame
=
frame
+
1
rects
,
confs
=
cascade
.
detect
(
img
,
rois
=
None
)
dt_old
=
sft
.
match
(
boxes
,
rects
,
confs
)
dts
=
sft
.
convert2detections
(
rects
,
confs
)
sft
.
draw_dt
(
img
,
dts
,
bgr
[
"green"
])
fp
,
fn
=
sft
.
match
(
boxes
,
dts
)
print
"fp and fn"
,
fp
,
fn
if
dt_old
is
not
None
:
sft
.
draw_dt
(
img
,
dt_old
,
(
0
,
255
,
0
))
sft
.
draw_rects
(
img
,
boxes
,
bgr
[
"blue"
],
lambda
x
,
y
:
y
)
cv2
.
imshow
(
"result"
,
img
);
if
(
cv2
.
waitKey
(
0
)
==
27
):
break
;
...
...
apps/sft/misk/sft.py
View file @
4c4c878b
...
...
@@ -4,6 +4,29 @@ import cv2, re, glob
import
numpy
as
np
import
matplotlib.pyplot
as
plt
""" Convert numpy matrices with rectangles and confidences to sorted list of detections."""
def
convert2detections
(
rects
,
confs
,
crop_factor
=
0.125
):
if
rects
is
None
:
return
[]
dts
=
zip
(
*
[
rects
.
tolist
(),
confs
.
tolist
()])
dts
=
zip
(
dts
[
0
][
0
],
dts
[
0
][
1
])
dts
=
[
Detection
(
r
,
c
)
for
r
,
c
in
dts
]
dts
.
sort
(
lambda
x
,
y
:
-
1
if
(
x
.
conf
-
y
.
conf
)
>
0
else
1
)
for
dt
in
dts
:
dt
.
crop
(
crop_factor
)
return
dts
def
crop_rect
(
rect
,
factor
):
val_x
=
factor
*
float
(
rect
[
2
])
val_y
=
factor
*
float
(
rect
[
3
])
x
=
[
int
(
rect
[
0
]
+
val_x
),
int
(
rect
[
1
]
+
val_y
),
int
(
rect
[
2
]
-
2.0
*
val_x
),
int
(
rect
[
3
]
-
2.0
*
val_y
)]
return
x
#
def
plot_curve
():
fig
,
ax
=
plt
.
subplots
()
...
...
@@ -29,12 +52,6 @@ def plot_curve():
plt
.
xscale
(
'log'
)
plt
.
show
()
def
crop_rect
(
rect
,
factor
):
val_x
=
factor
*
float
(
rect
[
2
])
val_y
=
factor
*
float
(
rect
[
3
])
x
=
[
int
(
rect
[
0
]
+
val_x
),
int
(
rect
[
1
]
+
val_y
),
int
(
rect
[
2
]
-
2.0
*
val_x
),
int
(
rect
[
3
]
-
2.0
*
val_y
)]
return
x
def
draw_rects
(
img
,
rects
,
color
,
l
=
lambda
x
,
y
:
x
+
y
):
if
rects
is
not
None
:
for
x1
,
y1
,
x2
,
y2
in
rects
:
...
...
@@ -58,16 +75,13 @@ class Detection:
self
.
conf
=
conf
self
.
matched
=
False
# def crop(self):
# rel_scale = self.bb[1] / 128
def
crop
(
self
,
factor
):
print
"was"
,
self
.
bb
self
.
bb
=
crop_rect
(
self
.
bb
,
factor
)
print
"bec"
,
self
.
bb
# we use rect-stype for dt and box style for gt. ToDo: fix it
def
overlap
(
self
,
b
):
print
self
.
bb
,
"vs"
,
b
a
=
self
.
bb
w
=
min
(
a
[
0
]
+
a
[
2
],
b
[
2
])
-
max
(
a
[
0
],
b
[
0
]);
h
=
min
(
a
[
1
]
+
a
[
3
],
b
[
3
])
-
max
(
a
[
1
],
b
[
1
]);
...
...
@@ -120,47 +134,40 @@ def norm_acpect_ratio(boxes, ratio):
return
[
norm_box
(
box
,
ratio
)
for
box
in
boxes
]
def
match
(
gts
,
rects
,
confs
):
if
rects
is
None
:
return
0
fp
=
0
fn
=
0
dts
=
zip
(
*
[
rects
.
tolist
(),
confs
.
tolist
()])
dts
=
zip
(
dts
[
0
][
0
],
dts
[
0
][
1
])
dts
=
[
Detection
(
r
,
c
)
for
r
,
c
in
dts
]
def
match
(
gts
,
dts
):
factor
=
1.0
/
8.0
dt_old
=
dts
for
dt
in
dts
:
dt
.
crop
(
factor
)
print
dt
.
bb
,
print
for
gt
in
gts
:
print
gt
# exclude small
if
gt
[
2
]
-
gt
[
0
]
<
27
:
continue
matched
=
False
# Cartesian product for each detection BB_dt with each BB_gt
overlaps
=
[[
dt
.
overlap
(
gt
)
for
gt
in
gts
]
for
dt
in
dts
]
print
overlaps
for
dt
in
dts
:
# dt.crop()
overlap
=
dt
.
overlap
(
gt
)
print
dt
.
bb
,
"vs"
,
gt
,
overlap
if
overlap
>
0.5
:
dt
.
mark_matched
()
matched
=
True
print
"matched "
,
dt
.
bb
,
gt
matches_gt
=
[
0
]
*
len
(
gts
)
print
matches_gt
if
not
matched
:
fn
=
fn
+
1
matches_dt
=
[
0
]
*
len
(
dts
)
print
matches_dt
print
"fn"
,
fn
for
idx
,
row
in
enumerate
(
overlaps
):
print
idx
,
row
for
dt
in
dts
:
if
not
dt
.
matched
:
fp
=
fp
+
1
imax
=
row
.
index
(
max
(
row
))
if
(
matches_gt
[
imax
]
==
0
and
row
[
imax
]
>
0.5
):
matches_gt
[
imax
]
=
1
matches_dt
[
idx
]
=
1
print
matches_gt
print
matches_dt
fp
=
sum
(
1
for
x
in
matches_dt
if
x
==
0
)
fn
=
sum
(
1
for
x
in
matches_gt
if
x
==
0
)
print
"fp"
,
fp
return
dt_old
return
fp
,
fn
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment