Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
re3-tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Gordon
re3-tensorflow
Commits
9a0f24b5
Commit
9a0f24b5
authored
7 years ago
by
Daniel Gordon
Browse files
Options
Downloads
Patches
Plain Diff
drawing updated
parent
e4f8b246
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
re3_utils/util/drawing.py
+26
-20
26 additions, 20 deletions
re3_utils/util/drawing.py
with
26 additions
and
20 deletions
re3_utils/util/drawing.py
+
26
−
20
View file @
9a0f24b5
...
...
@@ -23,20 +23,19 @@ def subplot(plots, rows, cols, outputWidth, outputHeight, border=BORDER,
from
PIL
import
Image
,
ImageDraw
,
ImageFont
FANCY_FONT
=
ImageFont
.
truetype
(
'
/usr/share/fonts/truetype/roboto/hinted/Roboto-Bold.ttf
'
,
20
)
for
row
in
x
range
(
rows
):
for
col
in
x
range
(
cols
):
for
row
in
range
(
rows
):
for
col
in
range
(
cols
):
if
col
+
cols
*
row
>=
len
(
plots
):
return
returnedImage
im
=
plots
[
col
+
cols
*
row
]
if
im
is
None
:
continue
i
m
=
im
.
squeeze
()
imgMin
=
np
.
min
(
im
)
imgMax
=
np
.
m
ax
(
im
)
im
=
((
im
.
astype
(
np
.
float32
)
-
imgMin
)
/
max
((
imgMax
-
imgMin
),
0.0001
)
)
i
f
im
.
dtype
!=
np
.
uint8
or
len
(
im
.
shape
)
<
3
:
im
=
im
.
astype
(
np
.
float32
)
im
-
=
np
.
m
in
(
im
)
im
*
=
255
/
np
.
max
(
im
)
im
=
255
-
im
.
astype
(
np
.
uint8
)
if
len
(
im
.
shape
)
<
3
:
im
=
255
-
(
im
*
255
).
astype
(
np
.
uint8
)
im
=
cv2
.
applyColorMap
(
im
,
cv2
.
COLORMAP_JET
)
if
im
.
shape
!=
(
outputHeight
,
outputWidth
,
3
):
...
...
@@ -47,6 +46,8 @@ def subplot(plots, rows, cols, outputWidth, outputHeight, border=BORDER,
else
:
imWidth
=
im
.
shape
[
1
]
*
outputHeight
/
im
.
shape
[
0
]
imHeight
=
outputHeight
imWidth
=
int
(
imWidth
)
imHeight
=
int
(
imHeight
)
im
=
cv2
.
resize
(
im
,
(
imWidth
,
imHeight
),
interpolation
=
cv2
.
INTER_NEAREST
)
...
...
@@ -62,22 +63,21 @@ def subplot(plots, rows, cols, outputWidth, outputHeight, border=BORDER,
im
=
np
.
lib
.
pad
(
im
,
((
pad0
,
pad1
),
(
0
,
0
),
(
0
,
0
)),
'
constant
'
,
constant_values
=
0
)
if
im
.
dtype
!=
np
.
uint8
:
im
*=
255
im
=
im
.
astype
(
np
.
uint8
)
if
(
titles
is
not
None
and
len
(
titles
)
>
1
and
len
(
titles
)
>
col
+
cols
*
row
and
len
(
titles
[
col
+
cols
*
row
])
>
0
):
if
fancy_text
:
if
im
.
dtype
!=
np
.
uint8
:
im
=
im
.
astype
(
np
.
uint8
)
im
=
Image
.
fromarray
(
im
)
draw
=
ImageDraw
.
Draw
(
im
)
for
x
in
x
range
(
9
,
12
):
for
y
in
x
range
(
9
,
12
):
for
x
in
range
(
9
,
12
):
for
y
in
range
(
9
,
12
):
draw
.
text
((
x
,
y
),
titles
[
col
+
cols
*
row
],
(
0
,
0
,
0
),
font
=
FANCY_FONT
)
draw
.
text
((
10
,
10
),
titles
[
col
+
cols
*
row
],
(
255
,
255
,
255
),
font
=
FANCY_FONT
)
im
=
np
.
array
(
im
,
dtype
=
np
.
uint8
)
im
=
np
.
array
(
im
)
else
:
cv2
.
putText
(
im
,
titles
[
col
+
cols
*
row
],
(
10
,
30
),
CV_FONT
,
.
5
,
[
0
,
0
,
0
],
4
)
cv2
.
putText
(
im
,
titles
[
col
+
cols
*
row
],
(
10
,
30
),
CV_FONT
,
.
5
,
[
255
,
255
,
255
],
1
)
...
...
@@ -90,24 +90,26 @@ def subplot(plots, rows, cols, outputWidth, outputHeight, border=BORDER,
# for one long title
if
titles
is
not
None
and
len
(
titles
)
==
1
:
if
fancy_text
:
if
im
.
dtype
!=
np
.
uint8
:
im
=
im
.
astype
(
np
.
uint8
)
im
=
Image
.
fromarray
(
im
)
draw
=
ImageDraw
.
Draw
(
im
)
for
x
in
x
range
(
9
,
12
):
for
y
in
x
range
(
9
,
12
):
for
x
in
range
(
9
,
12
):
for
y
in
range
(
9
,
12
):
draw
.
text
((
x
,
y
),
titles
[
0
],
(
0
,
0
,
0
),
font
=
FANCY_FONT
)
draw
.
text
((
10
,
10
),
titles
[
0
],
(
255
,
255
,
255
),
font
=
FANCY_FONT
)
im
=
np
.
array
(
im
,
dtype
=
np
.
uint8
)
im
=
np
.
array
(
im
)
else
:
cv2
.
putText
(
im
,
titles
[
0
],
(
10
,
30
),
CV_FONT
,
.
5
,
[
0
,
0
,
0
],
4
)
cv2
.
putText
(
im
,
titles
[
0
],
(
10
,
30
),
CV_FONT
,
.
5
,
[
255
,
255
,
255
],
1
)
cv2
.
putText
(
im
,
titles
[
0
],
(
10
,
30
),
CV_FONT
,
128
,
[
0
,
0
,
0
],
4
)
cv2
.
putText
(
im
,
titles
[
0
],
(
10
,
30
),
CV_FONT
,
128
,
[
1
,
1
,
1
],
1
)
return
im
# BBoxes are [x1 y1 x2 y2]
def
drawRect
(
image
,
bbox
,
padding
,
color
):
import
bb_util
from
my_utils.util
import
bb_util
imageHeight
=
image
.
shape
[
0
]
imageWidth
=
image
.
shape
[
1
]
bbox
=
np
.
round
(
np
.
array
(
bbox
))
# mostly just for copying
...
...
@@ -128,6 +130,10 @@ def drawPoint(image, point, size, padding, color):
point
=
np
.
array
(
point
)
point
=
tuple
(
point
.
astype
(
int
).
tolist
())
cv2
.
circle
(
image
,
point
,
int
(
size
),
color
,
int
(
padding
))
'''
bbox = xywh_to_xyxy([point[0], point[1], size, size])
drawRect(image, bbox, padding, color)
'''
return
image
def
images_to_sprite
(
data
,
padsize
=
1
,
padval
=
0
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment