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
faecb4f0
Commit
faecb4f0
authored
Jan 24, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ROC script refactoring
parent
e9232a4b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
53 deletions
+45
-53
roc_test.py
apps/sft/misc/roc_test.py
+1
-4
scale_caltech.py
apps/sft/misc/scale_caltech.py
+1
-15
scale_inria.py
apps/sft/misc/scale_inria.py
+2
-16
sft.py
apps/sft/misc/sft.py
+41
-18
No files found.
apps/sft/misc/roc_test.py
View file @
faecb4f0
...
...
@@ -74,10 +74,7 @@ if __name__ == "__main__":
name
=
pattern
%
(
nframes
,)
_
,
tail
=
os
.
path
.
split
(
name
)
boxes
=
samples
[
tail
]
boxes
=
sft
.
norm_acpect_ratio
(
boxes
,
0.5
)
boxes
=
[
b
for
b
in
boxes
if
(
b
[
3
]
-
b
[
1
])
>
args
.
scale_range
[
0
]
/
args
.
ext_ratio
]
boxes
=
[
b
for
b
in
boxes
if
(
b
[
3
]
-
b
[
1
])
<
args
.
scale_range
[
1
]
*
args
.
ext_ratio
]
boxes
=
sft
.
filter_for_range
(
samples
[
tail
],
args
.
scale_range
,
args
.
ext_ratio
)
nannotated
=
nannotated
+
len
(
boxes
)
nframes
=
nframes
+
1
...
...
apps/sft/misc/scale_caltech.py
View file @
faecb4f0
...
...
@@ -6,20 +6,6 @@ from optparse import OptionParser
import
re
import
numpy
as
np
def
resize
(
image
,
d_w
,
d_h
):
if
(
d_h
<
image
.
shape
[
0
])
or
(
d_w
<
image
.
shape
[
1
]):
ratio
=
min
(
d_h
/
float
(
image
.
shape
[
0
]),
d_w
/
float
(
image
.
shape
[
1
]))
kernel_size
=
int
(
5
/
(
2
*
ratio
))
sigma
=
0.5
/
ratio
image_to_resize
=
cv2
.
filter2D
(
image
,
cv2
.
CV_8UC3
,
cv2
.
getGaussianKernel
(
kernel_size
,
sigma
))
interpolation_type
=
cv2
.
INTER_AREA
else
:
image_to_resize
=
image
interpolation_type
=
cv2
.
INTER_CUBIC
return
cv2
.
resize
(
image_to_resize
,(
d_w
,
d_h
),
None
,
0
,
0
,
interpolation_type
)
def
extractPositive
(
f
,
path
,
opath
,
octave
,
min_possible
):
newobj
=
re
.
compile
(
"^lbl=
\'
(
\
w+)
\'
\
s+str=(
\
d+)
\
s+end=(
\
d+)
\
s+hide=0$"
)
pos
=
re
.
compile
(
"^pos
\
s=(
\
[[((
\
d+
\
.+
\
d*)|
\
s+|
\
;)]*
\
])$"
)
...
...
@@ -107,7 +93,7 @@ def extractPositive(f, path, opath, octave, min_possible):
continue
cropped
=
cv2
.
copyMakeBorder
(
cropped
,
top
,
bottom
,
left
,
right
,
cv2
.
BORDER_REPLICATE
)
resized
=
resiz
e
(
cropped
,
whole_mod_w
,
whole_mod_h
)
resized
=
sft
.
resize_sampl
e
(
cropped
,
whole_mod_w
,
whole_mod_h
)
flipped
=
cv2
.
flip
(
resized
,
1
)
cv2
.
imshow
(
"resized"
,
resized
)
...
...
apps/sft/misc/scale_inria.py
View file @
faecb4f0
...
...
@@ -30,20 +30,6 @@ def adjust(box, tb, lr):
return
[
mix
,
miy
,
max
,
may
]
def
resize
(
image
,
d_w
,
d_h
):
if
(
d_h
<
image
.
shape
[
0
])
or
(
d_w
<
image
.
shape
[
1
]):
ratio
=
min
(
d_h
/
float
(
image
.
shape
[
0
]),
d_w
/
float
(
image
.
shape
[
1
]))
kernel_size
=
int
(
5
/
(
2
*
ratio
))
sigma
=
0.5
/
ratio
image_to_resize
=
cv2
.
filter2D
(
image
,
cv2
.
CV_8UC3
,
cv2
.
getGaussianKernel
(
kernel_size
,
sigma
))
interpolation_type
=
cv2
.
INTER_AREA
else
:
image_to_resize
=
image
interpolation_type
=
cv2
.
INTER_CUBIC
return
cv2
.
resize
(
image_to_resize
,(
d_w
,
d_h
),
None
,
0
,
0
,
interpolation_type
)
if
__name__
==
"__main__"
:
parser
=
OptionParser
()
parser
.
add_option
(
"-i"
,
"--input"
,
dest
=
"input"
,
metavar
=
"DIRECTORY"
,
type
=
"string"
,
...
...
@@ -110,7 +96,7 @@ if __name__ == "__main__":
left
=
int
(
max
(
0
,
0
-
box
[
0
]))
right
=
int
(
max
(
0
,
box
[
2
]
-
mat_w
))
cropped
=
cv2
.
copyMakeBorder
(
cropped
,
top
,
bottom
,
left
,
right
,
cv2
.
BORDER_REPLICATE
)
resized
=
resiz
e
(
cropped
,
whole_mod_w
,
whole_mod_h
)
resized
=
sft
.
resize_sampl
e
(
cropped
,
whole_mod_w
,
whole_mod_h
)
out_name
=
".png"
if
round
(
math
.
log
(
scale
)
/
math
.
log
(
2
))
<
each
:
...
...
@@ -143,7 +129,7 @@ if __name__ == "__main__":
if
(
img
.
shape
[
0
]
<=
min_shape
[
0
]):
resized_size
=
(
int
(
min_shape
[
0
]
*
ratio
),
int
(
min_shape
[
0
]))
img
=
resiz
e
(
img
,
resized_size
[
0
],
resized_size
[
1
])
img
=
sft
.
resize_sampl
e
(
img
,
resized_size
[
0
],
resized_size
[
1
])
else
:
out_name
=
"negative_sample_
%
i.png"
%
idx
...
...
apps/sft/misc/sft.py
View file @
faecb4f0
...
...
@@ -30,7 +30,7 @@ def cascade(min_scale, max_scale, nscales, f):
assert
c
.
load
(
dom
)
return
c
""" Compute prefix sum for en array"""
""" Compute prefix sum for en array
.
"""
def
cumsum
(
n
):
cum
=
[]
y
=
0
...
...
@@ -39,7 +39,7 @@ def cumsum(n):
cum
.
append
(
y
)
return
cum
""" Compute x and y arrays for ROC plot"""
""" Compute x and y arrays for ROC plot
.
"""
def
computeROC
(
confidenses
,
tp
,
nannotated
,
nframes
,
ignored
):
confidenses
,
tp
,
ignored
=
zip
(
*
sorted
(
zip
(
confidenses
,
tp
,
ignored
),
reverse
=
True
))
...
...
@@ -53,14 +53,14 @@ def computeROC(confidenses, tp, nannotated, nframes, ignored):
return
fppi
,
miss_rate
""" Crop rectangle by factor"""
""" Crop rectangle by factor
.
"""
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
"""
Initialize plot axises
"""
"""
Initialize plot axises.
"""
def
initPlot
(
name
=
"ROC curve Bahnhof"
):
fig
,
ax
=
plt
.
subplots
()
...
...
@@ -73,13 +73,14 @@ def initPlot(name = "ROC curve Bahnhof"):
plt
.
xscale
(
'log'
)
plt
.
yscale
(
'log'
)
"""
Show resulted plot
"""
"""
Show resulted plot.
"""
def
showPlot
(
file_name
):
plt
.
savefig
(
file_name
)
plt
.
axis
((
pow
(
10
,
-
3
),
pow
(
10
,
1
),
0.0
,
1
))
plt
.
yticks
(
[
0.05
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
,
0.64
,
0.8
,
1
],
[
'.05'
,
'.10'
,
'.20'
,
'.30'
,
'.40'
,
'.50'
,
'.64'
,
'.80'
,
'1'
]
)
plt
.
show
()
""" Filter true positives and ignored detections for cascade detector output."""
def
match
(
gts
,
dts
):
matches_gt
=
[
0
]
*
len
(
gts
)
matches_dt
=
[
0
]
*
len
(
dts
)
...
...
@@ -94,7 +95,7 @@ def match(gts, dts):
for
idx
,
row
in
enumerate
(
overlaps
):
imax
=
row
.
index
(
max
(
row
))
# try to match ground t
hrus
h
# try to match ground t
rut
h
if
(
matches_gt
[
imax
]
==
0
and
row
[
imax
]
>
0.5
):
matches_gt
[
imax
]
=
1
matches_dt
[
idx
]
=
1
...
...
@@ -109,17 +110,18 @@ def match(gts, dts):
matches_ignore
[
idx
]
=
1
return
matches_dt
,
matches_ignore
""" Draw plot."""
def
plotLogLog
(
fppi
,
miss_rate
,
c
):
print
plt
.
loglog
(
fppi
,
miss_rate
,
color
=
c
,
linewidth
=
2
)
""" Draw detections or ground truth on image."""
def
draw_rects
(
img
,
rects
,
color
,
l
=
lambda
x
,
y
:
x
+
y
):
if
rects
is
not
None
:
for
x1
,
y1
,
x2
,
y2
in
rects
:
cv2
.
rectangle
(
img
,
(
x1
,
y1
),
(
l
(
x1
,
x2
),
l
(
y1
,
y2
)),
color
,
2
)
def
draw_dt
(
img
,
dts
,
color
,
l
=
lambda
x
,
y
:
x
+
y
):
if
dts
is
not
None
:
for
dt
in
dts
:
...
...
@@ -128,10 +130,6 @@ def draw_dt(img, dts, color, l = lambda x, y : x + y):
cv2
.
rectangle
(
img
,
(
x1
,
y1
),
(
l
(
x1
,
x2
),
l
(
y1
,
y2
)),
color
,
2
)
class
Annotation
:
def
__init__
(
self
,
bb
):
self
.
bb
=
bb
class
Detection
:
def
__init__
(
self
,
bb
,
conf
):
self
.
bb
=
bb
...
...
@@ -168,7 +166,7 @@ class Detection:
def
mark_matched
(
self
):
self
.
matched
=
True
"""Parse INPIA annotation format"""
def
parse_inria
(
ipath
,
f
):
bbs
=
[]
path
=
None
...
...
@@ -185,10 +183,11 @@ def parse_inria(ipath, f):
return
Sample
(
path
,
bbs
)
def
glob_set
(
pattern
):
return
[
__n
for
__n
in
glob
.
iglob
(
pattern
)]
#glob.iglob(pattern)
return
[
__n
for
__n
in
glob
.
iglob
(
pattern
)]
# parse ETH idl file
""" Parse ETH idl file. """
def
parse_idl
(
f
):
map
=
{}
for
l
in
open
(
f
):
...
...
@@ -198,11 +197,35 @@ def parse_idl(f):
map
.
update
(
eval
(
l
))
return
map
""" Normalize detection box to unified aspect ration."""
def
norm_box
(
box
,
ratio
):
middle
=
float
(
box
[
0
]
+
box
[
2
])
/
2.0
new_half_width
=
float
(
box
[
3
]
-
box
[
1
])
*
ratio
/
2.0
return
(
int
(
round
(
middle
-
new_half_width
)),
box
[
1
],
int
(
round
(
middle
+
new_half_width
)),
box
[
3
])
""" Process array of boxes."""
def
norm_acpect_ratio
(
boxes
,
ratio
):
return
[
norm_box
(
box
,
ratio
)
for
box
in
boxes
]
\ No newline at end of file
return
[
norm_box
(
box
,
ratio
)
for
box
in
boxes
]
""" Filter detections out of extended range. """
def
filter_for_range
(
boxes
,
scale_range
,
ext_ratio
):
boxes
=
sft
.
norm_acpect_ratio
(
boxes
,
0.5
)
boxes
=
[
b
for
b
in
boxes
if
(
b
[
3
]
-
b
[
1
])
>
scale_range
[
0
]
/
ext_ratio
]
boxes
=
[
b
for
b
in
boxes
if
(
b
[
3
]
-
b
[
1
])
<
scale_range
[
1
]
*
ext_ratio
]
return
boxes
""" Resize sample for training."""
def
resize_sample
(
image
,
d_w
,
d_h
):
h
,
w
,
_
=
image
.
shape
if
(
d_h
<
h
)
or
(
d_w
<
w
):
ratio
=
min
(
d_h
/
float
(
h
),
d_w
/
float
(
w
))
kernel_size
=
int
(
5
/
(
2
*
ratio
))
sigma
=
0.5
/
ratio
image_to_resize
=
cv2
.
filter2D
(
image
,
cv2
.
CV_8UC3
,
cv2
.
getGaussianKernel
(
kernel_size
,
sigma
))
interpolation_type
=
cv2
.
INTER_AREA
else
:
image_to_resize
=
image
interpolation_type
=
cv2
.
INTER_CUBIC
return
cv2
.
resize
(
image_to_resize
,(
d_w
,
d_h
),
None
,
0
,
0
,
interpolation_type
)
\ 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