Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不会修仙的道士
labelme
提交
595ca167
L
labelme
项目概览
不会修仙的道士
/
labelme
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
labelme
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
595ca167
编写于
4月 02, 2018
作者:
K
Kentaro Wada
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add img_b64_to_arr, img_arr_to_b64
上级
ab3a2631
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
10 deletion
+41
-10
.gitignore
.gitignore
+10
-6
labelme/utils.py
labelme/utils.py
+15
-0
tests/data/apc2016_obj3.jpg
tests/data/apc2016_obj3.jpg
+1
-0
tests/data/apc2016_obj3.json
tests/data/apc2016_obj3.json
+1
-0
tests/test_utils.py
tests/test_utils.py
+14
-4
未找到文件。
.gitignore
浏览文件 @
595ca167
.cache/
build/
dist/
/.cache/
/.pytest_cache/
/build/
/dist/
/*.egg-info/
*.py[cdo]
*.egg-info/
icons/.DS_Store
labelme/resources.py
.DS_Store
/labelme/resources.py
labelme/utils.py
浏览文件 @
595ca167
...
...
@@ -57,12 +57,27 @@ def label2rgb(lbl, img=None, n_labels=None, alpha=0.3, thresh_suppress=0):
def
img_b64_to_array
(
img_b64
):
warnings
.
warn
(
'img_ba64_to_array is deprecated. '
'Please use img_b64_to_arr.'
)
return
img_b64_to_arr
(
img_b64
)
def
img_b64_to_arr
(
img_b64
):
f
=
io
.
BytesIO
()
f
.
write
(
base64
.
b64decode
(
img_b64
))
img_arr
=
np
.
array
(
PIL
.
Image
.
open
(
f
))
return
img_arr
def
img_arr_to_b64
(
img_arr
):
img_pil
=
PIL
.
Image
.
fromarray
(
img_arr
)
f
=
io
.
BytesIO
()
img_pil
.
save
(
f
,
format
=
'PNG'
)
img_bin
=
f
.
getvalue
()
img_b64
=
base64
.
encodestring
(
img_bin
)
return
img_b64
def
polygons_to_mask
(
img_shape
,
polygons
):
mask
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
uint8
)
mask
=
PIL
.
Image
.
fromarray
(
mask
)
...
...
tests/data/apc2016_obj3.jpg
0 → 120000
浏览文件 @
595ca167
../../examples/single_image/apc2016_obj3.jpg
\ No newline at end of file
tests/data/apc2016_obj3.json
0 → 120000
浏览文件 @
595ca167
../../examples/single_image/apc
2016
_obj
3
.json
\ No newline at end of file
tests/test_utils.py
浏览文件 @
595ca167
...
...
@@ -2,17 +2,27 @@ import json
import
os.path
as
osp
import
numpy
as
np
import
PIL.Image
from
labelme
import
utils
import
labelme
here
=
osp
.
dirname
(
osp
.
abspath
(
__file__
))
data_dir
=
osp
.
join
(
here
,
'data'
)
def
test_img_b64_to_arr
ay
():
json_file
=
osp
.
join
(
here
,
'../examples/single_image/
apc2016_obj3.json'
)
def
test_img_b64_to_arr
():
json_file
=
osp
.
join
(
data_dir
,
'
apc2016_obj3.json'
)
data
=
json
.
load
(
open
(
json_file
))
img_b64
=
data
[
'imageData'
]
img
=
utils
.
img_b64_to_array
(
img_b64
)
img
=
labelme
.
utils
.
img_b64_to_arr
(
img_b64
)
assert
img
.
dtype
==
np
.
uint8
assert
img
.
shape
==
(
907
,
1210
,
3
)
def
test_img_arr_to_b64
():
img_file
=
osp
.
join
(
data_dir
,
'apc2016_obj3.jpg'
)
img_arr
=
np
.
asarray
(
PIL
.
Image
.
open
(
img_file
))
img_b64
=
labelme
.
utils
.
img_arr_to_b64
(
img_arr
)
img_arr2
=
labelme
.
utils
.
img_b64_to_arr
(
img_b64
)
np
.
testing
.
assert_allclose
(
img_arr
,
img_arr2
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录