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
d1952f28
Commit
d1952f28
authored
Jan 19, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cropping and aspect ratio normalization
parent
18df46fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
5 deletions
+39
-5
roc_test.py
apps/sft/misk/roc_test.py
+6
-4
sft.py
apps/sft/misk/sft.py
+33
-1
No files found.
apps/sft/misk/roc_test.py
View file @
d1952f28
...
...
@@ -40,6 +40,7 @@ if __name__ == "__main__":
frame
=
0
pattern
=
args
.
input
camera
=
cv2
.
VideoCapture
(
args
.
input
)
while
True
:
ret
,
img
=
camera
.
read
()
if
not
ret
:
...
...
@@ -50,17 +51,18 @@ if __name__ == "__main__":
_
,
tail
=
os
.
path
.
split
(
name
)
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
)
fp
=
sft
.
match
(
boxes
,
rects
,
confs
)
dt_old
=
sft
.
match
(
boxes
,
rects
,
confs
)
# # draw results
if
rects
is
not
None
:
sft
.
draw_rects
(
img
,
rects
[
0
],
(
0
,
255
,
0
))
if
dt_old
is
not
None
:
sft
.
draw_dt
(
img
,
dt_old
,
(
0
,
255
,
0
))
cv2
.
imshow
(
"result"
,
img
);
if
(
cv2
.
waitKey
(
0
)
==
27
):
...
...
apps/sft/misk/sft.py
View file @
d1952f28
...
...
@@ -29,13 +29,25 @@ 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
:
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
:
bb
=
dt
.
bb
x1
,
y1
,
x2
,
y2
=
dt
.
bb
[
0
],
dt
.
bb
[
1
],
dt
.
bb
[
2
],
dt
.
bb
[
3
]
cv2
.
rectangle
(
img
,
(
x1
,
y1
),
(
l
(
x1
,
x2
),
l
(
y1
,
y2
)),
color
,
2
)
class
Annotation
:
def
__init__
(
self
,
bb
):
self
.
bb
=
bb
...
...
@@ -49,6 +61,10 @@ class Detection:
# 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
):
...
...
@@ -94,6 +110,16 @@ def parse_idl(f):
map
.
update
(
eval
(
l
))
return
map
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
])
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
...
...
@@ -105,6 +131,11 @@ def match(gts, rects, confs):
dts
=
zip
(
dts
[
0
][
0
],
dts
[
0
][
1
])
dts
=
[
Detection
(
r
,
c
)
for
r
,
c
in
dts
]
factor
=
1.0
/
8.0
dt_old
=
dts
for
dt
in
dts
:
dt
.
crop
(
factor
)
for
gt
in
gts
:
# exclude small
...
...
@@ -132,3 +163,4 @@ def match(gts, rects, confs):
fp
=
fp
+
1
print
"fp"
,
fp
return
dt_old
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