Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
39e75b85
Commit
39e75b85
authored
Aug 15, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
draw boxes
parent
da0984df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletion
+47
-1
tensorpack/utils/viz.py
tensorpack/utils/viz.py
+47
-1
No files found.
tensorpack/utils/viz.py
View file @
39e75b85
...
...
@@ -9,6 +9,7 @@ import sys
import
io
from
.fs
import
mkdir_p
from
.argtools
import
shape2d
from
.rect
import
BoxBase
try
:
import
cv2
...
...
@@ -350,6 +351,42 @@ def intensity_to_rgb(intensity, cmap='cubehelix', normalize=False):
intensity
=
cmap
(
intensity
)[
...
,
:
3
]
return
intensity
.
astype
(
'float32'
)
*
255.0
def
draw_boxes
(
im
,
boxes
,
labels
=
None
,
color
=
(
218
,
218
,
218
)):
"""
Args:
im (np.ndarray): will not be modified
boxes (np.ndarray or list[BoxBase]):
labels: (list[str] or None)
Returns:
np.ndarray
"""
if
isinstance
(
boxes
,
list
):
arr
=
np
.
zeros
((
len
(
boxes
),
4
),
dtype
=
'int32'
)
for
idx
,
b
in
enumerate
(
boxes
):
assert
isinstance
(
b
,
BoxBase
),
b
arr
[
idx
,
:]
=
[
int
(
b
.
x1
),
int
(
b
.
y1
),
int
(
b
.
x2
),
int
(
b
.
y2
)]
boxes
=
arr
else
:
boxes
=
boxes
.
astype
(
'int32'
)
if
labels
is
not
None
:
assert
len
(
labels
)
==
len
(
boxes
),
"{} != {}"
.
format
(
len
(
labels
),
len
(
boxes
))
areas
=
(
boxes
[:,
2
]
-
boxes
[:,
0
]
+
1
)
*
(
boxes
[:,
3
]
-
boxes
[:,
1
]
+
1
)
sorted_inds
=
np
.
argsort
(
-
areas
)
im
=
im
.
copy
()
for
i
in
sorted_inds
:
box
=
boxes
[
i
,
:]
cv2
.
rectangle
(
im
,
(
box
[
0
],
box
[
1
]),
(
box
[
2
],
box
[
3
]),
color
,
thickness
=
1
)
if
labels
is
not
None
:
label
=
labels
[
i
]
cv2
.
putText
(
im
,
label
,
(
box
[
0
],
box
[
1
]
-
3
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.4
,
color
,
lineType
=
cv2
.
LINE_AA
)
return
im
from
..utils.develop
import
create_dummy_func
# noqa
try
:
import
matplotlib.pyplot
as
plt
...
...
@@ -367,8 +404,17 @@ if __name__ == '__main__':
imglist
,
max_width
=
500
,
max_height
=
200
)):
of
=
"patch{:02d}.png"
.
format
(
idx
)
cv2
.
imwrite
(
of
,
patch
)
e
lse
:
if
Fa
lse
:
imglist
=
[]
img
=
cv2
.
imread
(
'out.png'
)
img2
=
cv2
.
resize
(
img
,
(
300
,
300
))
viz
=
stack_patches
([
img
,
img2
],
1
,
2
,
pad
=
True
,
viz
=
True
)
if
True
:
img
=
cv2
.
imread
(
'cat.jpg'
)
boxes
=
np
.
asarray
([
[
10
,
30
,
200
,
100
],
[
20
,
80
,
250
,
250
]
])
img
=
draw_boxes
(
img
,
boxes
,
[
'asdfasdf'
,
'11111111111111'
])
interactive_imshow
(
img
)
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