Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
Opencv Zoo
提交
109656f3
O
Opencv Zoo
项目概览
张重言
/
Opencv Zoo
10 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv Zoo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
109656f3
编写于
10月 13, 2022
作者:
Z
Zihao Mu
提交者:
GitHub
10月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add scale factor to DB demo (#96)
上级
9c156c26
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
18 deletion
+63
-18
models/text_detection_db/demo.py
models/text_detection_db/demo.py
+31
-9
models/text_recognition_crnn/demo.py
models/text_recognition_crnn/demo.py
+32
-9
未找到文件。
models/text_detection_db/demo.py
浏览文件 @
109656f3
...
...
@@ -73,29 +73,40 @@ if __name__ == '__main__':
# If input is an image
if
args
.
input
is
not
None
:
image
=
cv
.
imread
(
args
.
input
)
image
=
cv
.
resize
(
image
,
[
args
.
width
,
args
.
height
])
original_image
=
cv
.
imread
(
args
.
input
)
original_w
=
original_image
.
shape
[
1
]
original_h
=
original_image
.
shape
[
0
]
scaleHeight
=
original_h
/
args
.
height
scaleWidth
=
original_w
/
args
.
width
image
=
cv
.
resize
(
original_image
,
[
args
.
width
,
args
.
height
])
# Inference
results
=
model
.
infer
(
image
)
# Scale the results bounding box
for
i
in
range
(
len
(
results
[
0
])):
for
j
in
range
(
4
):
box
=
results
[
0
][
i
][
j
]
results
[
0
][
i
][
j
][
0
]
=
box
[
0
]
*
scaleWidth
results
[
0
][
i
][
j
][
1
]
=
box
[
1
]
*
scaleHeight
# Print results
print
(
'{} texts detected.'
.
format
(
len
(
results
[
0
])))
for
idx
,
(
bbox
,
score
)
in
enumerate
(
zip
(
results
[
0
],
results
[
1
])):
print
(
'{}: {} {} {} {}, {:.2f}'
.
format
(
idx
,
bbox
[
0
],
bbox
[
1
],
bbox
[
2
],
bbox
[
3
],
score
))
# Draw results on the input image
image
=
visualize
(
image
,
results
)
original_image
=
visualize
(
original_
image
,
results
)
# Save results if save is true
if
args
.
save
:
print
(
'Resutls saved to result.jpg
\n
'
)
cv
.
imwrite
(
'result.jpg'
,
image
)
cv
.
imwrite
(
'result.jpg'
,
original_
image
)
# Visualize results in a new window
if
args
.
vis
:
cv
.
namedWindow
(
args
.
input
,
cv
.
WINDOW_AUTOSIZE
)
cv
.
imshow
(
args
.
input
,
image
)
cv
.
imshow
(
args
.
input
,
original_
image
)
cv
.
waitKey
(
0
)
else
:
# Omit input to call default camera
deviceId
=
0
...
...
@@ -103,22 +114,33 @@ if __name__ == '__main__':
tm
=
cv
.
TickMeter
()
while
cv
.
waitKey
(
1
)
<
0
:
hasFrame
,
fram
e
=
cap
.
read
()
hasFrame
,
original_imag
e
=
cap
.
read
()
if
not
hasFrame
:
print
(
'No frames grabbed!'
)
break
frame
=
cv
.
resize
(
frame
,
[
args
.
width
,
args
.
height
])
original_w
=
original_image
.
shape
[
1
]
original_h
=
original_image
.
shape
[
0
]
scaleHeight
=
original_h
/
args
.
height
scaleWidth
=
original_w
/
args
.
width
frame
=
cv
.
resize
(
original_image
,
[
args
.
width
,
args
.
height
])
# Inference
tm
.
start
()
results
=
model
.
infer
(
frame
)
# results is a tuple
tm
.
stop
()
# Scale the results bounding box
for
i
in
range
(
len
(
results
[
0
])):
for
j
in
range
(
4
):
box
=
results
[
0
][
i
][
j
]
results
[
0
][
i
][
j
][
0
]
=
box
[
0
]
*
scaleWidth
results
[
0
][
i
][
j
][
1
]
=
box
[
1
]
*
scaleHeight
# Draw results on the input image
frame
=
visualize
(
fram
e
,
results
,
fps
=
tm
.
getFPS
())
original_image
=
visualize
(
original_imag
e
,
results
,
fps
=
tm
.
getFPS
())
# Visualize results in a new Window
cv
.
imshow
(
'{} Demo'
.
format
(
model
.
name
),
fram
e
)
cv
.
imshow
(
'{} Demo'
.
format
(
model
.
name
),
original_imag
e
)
tm
.
reset
()
models/text_recognition_crnn/demo.py
浏览文件 @
109656f3
...
...
@@ -75,8 +75,12 @@ if __name__ == '__main__':
# If input is an image
if
args
.
input
is
not
None
:
image
=
cv
.
imread
(
args
.
input
)
image
=
cv
.
resize
(
image
,
[
args
.
width
,
args
.
height
])
original_image
=
cv
.
imread
(
args
.
input
)
original_w
=
original_image
.
shape
[
1
]
original_h
=
original_image
.
shape
[
0
]
scaleHeight
=
original_h
/
args
.
height
scaleWidth
=
original_w
/
args
.
width
image
=
cv
.
resize
(
original_image
,
[
args
.
width
,
args
.
height
])
# Inference
results
=
detector
.
infer
(
image
)
...
...
@@ -86,18 +90,25 @@ if __name__ == '__main__':
recognizer
.
infer
(
image
,
box
.
reshape
(
8
))
)
# Scale the results bounding box
for
i
in
range
(
len
(
results
[
0
])):
for
j
in
range
(
4
):
box
=
results
[
0
][
i
][
j
]
results
[
0
][
i
][
j
][
0
]
=
box
[
0
]
*
scaleWidth
results
[
0
][
i
][
j
][
1
]
=
box
[
1
]
*
scaleHeight
# Draw results on the input image
image
=
visualize
(
image
,
results
,
texts
)
original_image
=
visualize
(
original_
image
,
results
,
texts
)
# Save results if save is true
if
args
.
save
:
print
(
'Resutls saved to result.jpg
\n
'
)
cv
.
imwrite
(
'result.jpg'
,
image
)
cv
.
imwrite
(
'result.jpg'
,
original_
image
)
# Visualize results in a new window
if
args
.
vis
:
cv
.
namedWindow
(
args
.
input
,
cv
.
WINDOW_AUTOSIZE
)
cv
.
imshow
(
args
.
input
,
image
)
cv
.
imshow
(
args
.
input
,
original_
image
)
cv
.
waitKey
(
0
)
else
:
# Omit input to call default camera
deviceId
=
0
...
...
@@ -105,12 +116,17 @@ if __name__ == '__main__':
tm
=
cv
.
TickMeter
()
while
cv
.
waitKey
(
1
)
<
0
:
hasFrame
,
fram
e
=
cap
.
read
()
hasFrame
,
original_imag
e
=
cap
.
read
()
if
not
hasFrame
:
print
(
'No frames grabbed!'
)
break
frame
=
cv
.
resize
(
frame
,
[
args
.
width
,
args
.
height
])
original_w
=
original_image
.
shape
[
1
]
original_h
=
original_image
.
shape
[
0
]
scaleHeight
=
original_h
/
args
.
height
scaleWidth
=
original_w
/
args
.
width
frame
=
cv
.
resize
(
original_image
,
[
args
.
width
,
args
.
height
])
# Inference of text detector
tm
.
start
()
results
=
detector
.
infer
(
frame
)
...
...
@@ -133,10 +149,17 @@ if __name__ == '__main__':
cv
.
putText
(
frame
,
'Latency - {}: {:.2f}'
.
format
(
recognizer
.
name
,
tm
.
getFPS
()),
(
0
,
30
),
cv
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
255
))
tm
.
reset
()
# Scale the results bounding box
for
i
in
range
(
len
(
results
[
0
])):
for
j
in
range
(
4
):
box
=
results
[
0
][
i
][
j
]
results
[
0
][
i
][
j
][
0
]
=
box
[
0
]
*
scaleWidth
results
[
0
][
i
][
j
][
1
]
=
box
[
1
]
*
scaleHeight
# Draw results on the input image
frame
=
visualize
(
fram
e
,
results
,
texts
)
original_image
=
visualize
(
original_imag
e
,
results
,
texts
)
print
(
texts
)
# Visualize results in a new Window
cv
.
imshow
(
'{} Demo'
.
format
(
recognizer
.
name
),
fram
e
)
cv
.
imshow
(
'{} Demo'
.
format
(
recognizer
.
name
),
original_imag
e
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录