Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ac252a34
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ac252a34
编写于
6月 17, 2022
作者:
Z
zhiboniu
提交者:
zhiboniu
6月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
plate run ok
上级
3f5ff9e6
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
6676 addition
and
44 deletion
+6676
-44
deploy/pphuman/rec_word_dict.txt
deploy/pphuman/rec_word_dict.txt
+6623
-0
deploy/python/vechile_plate.py
deploy/python/vechile_plate.py
+49
-44
deploy/python/vechile_plateutils.py
deploy/python/vechile_plateutils.py
+4
-0
未找到文件。
deploy/pphuman/rec_word_dict.txt
0 → 100644
浏览文件 @
ac252a34
此差异已折叠。
点击以展开。
deploy/python/vechile_plate.py
浏览文件 @
ac252a34
...
@@ -28,11 +28,10 @@ import sys
...
@@ -28,11 +28,10 @@ import sys
parent_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
*
([
'..'
])))
parent_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
*
([
'..'
])))
sys
.
path
.
insert
(
0
,
parent_path
)
sys
.
path
.
insert
(
0
,
parent_path
)
from
utils
import
Timer
,
get_current_memory_mb
from
infer
import
get_test_images
,
print_arguments
from
infer
import
Detector
,
get_test_images
,
print_arguments
,
create_inputs
from
vechile_plateutils
import
create_predictor
,
get_infer_gpuid
,
argsparser
,
get_rotate_crop_image
,
draw_boxes
from
vechile_plateutils
import
create_predictor
,
get_infer_gpuid
,
argsparser
,
get_rotate_crop_image
from
vecplatepostprocess
import
build_post_process
from
vecplatepostprocess
import
build_post_process
from
preprocess
import
preprocess
,
Resize
,
NormalizeImage
,
Permute
,
PadStride
,
LetterBoxResize
,
WarpAffine
,
Pad
,
decode_imag
e
,
Resize_Mult32
from
preprocess
import
preprocess
,
NormalizeImage
,
Permut
e
,
Resize_Mult32
class
PlateDetector
(
object
):
class
PlateDetector
(
object
):
...
@@ -93,7 +92,8 @@ class PlateDetector(object):
...
@@ -93,7 +92,8 @@ class PlateDetector(object):
for
im_path
in
image_list
:
for
im_path
in
image_list
:
im
,
im_info
=
preprocess
(
im_path
,
preprocess_ops
)
im
,
im_info
=
preprocess
(
im_path
,
preprocess_ops
)
input_im_lst
.
append
(
im
)
input_im_lst
.
append
(
im
)
input_im_info_lst
.
append
(
im_info
[
'im_shape'
])
input_im_info_lst
.
append
(
im_info
[
'im_shape'
]
/
im_info
[
'scale_factor'
])
return
np
.
stack
(
input_im_lst
,
axis
=
0
),
input_im_info_lst
return
np
.
stack
(
input_im_lst
,
axis
=
0
),
input_im_info_lst
...
@@ -136,18 +136,15 @@ class PlateDetector(object):
...
@@ -136,18 +136,15 @@ class PlateDetector(object):
dt_boxes
=
np
.
array
(
dt_boxes_new
)
dt_boxes
=
np
.
array
(
dt_boxes_new
)
return
dt_boxes
return
dt_boxes
def
predict_image
(
self
,
img
):
def
predict_image
(
self
,
img
_list
):
st
=
time
.
time
()
st
=
time
.
time
()
if
self
.
args
.
run_benchmark
:
if
self
.
args
.
run_benchmark
:
self
.
autolog
.
times
.
start
()
self
.
autolog
.
times
.
start
()
img
,
shape_list
=
self
.
preprocess
(
img
)
img
,
shape_list
=
self
.
preprocess
(
img
_list
)
if
img
is
None
:
if
img
is
None
:
return
None
,
0
return
None
,
0
# img = np.expand_dims(img, axis=0)
# shape_list = np.expand_dims(shape_list, axis=0)
# img = img.copy()
if
self
.
args
.
run_benchmark
:
if
self
.
args
.
run_benchmark
:
self
.
autolog
.
times
.
stamp
()
self
.
autolog
.
times
.
stamp
()
...
@@ -166,27 +163,28 @@ class PlateDetector(object):
...
@@ -166,27 +163,28 @@ class PlateDetector(object):
#self.predictor.try_shrink_memory()
#self.predictor.try_shrink_memory()
post_result
=
self
.
postprocess_op
(
preds
,
shape_list
)
post_result
=
self
.
postprocess_op
(
preds
,
shape_list
)
dt_boxes
=
post_result
[
0
][
'points'
]
dt_boxes
=
self
.
filter_tag_det_res
(
dt_boxes
,
shape_list
[
0
])
dt_batch_boxes
=
[]
for
idx
in
range
(
len
(
post_result
)):
org_shape
=
img_list
[
idx
].
shape
dt_boxes
=
post_result
[
idx
][
'points'
]
dt_boxes
=
self
.
filter_tag_det_res
(
dt_boxes
,
org_shape
)
dt_batch_boxes
.
append
(
dt_boxes
)
if
self
.
args
.
run_benchmark
:
if
self
.
args
.
run_benchmark
:
self
.
autolog
.
times
.
end
(
stamp
=
True
)
self
.
autolog
.
times
.
end
(
stamp
=
True
)
et
=
time
.
time
()
et
=
time
.
time
()
return
dt_boxes
,
et
-
st
return
dt_b
atch_b
oxes
,
et
-
st
class
TextRecognizer
(
object
):
class
TextRecognizer
(
object
):
def
__init__
(
self
,
def
__init__
(
self
,
FLAGS
,
use_gpu
=
True
,
benchmark
=
False
):
FLAGS
,
self
.
rec_image_shape
=
[
input_shape
=
[
3
,
48
,
320
],
int
(
v
)
for
v
in
FLAGS
.
rec_image_shape
.
split
(
","
)
batch_size
=
8
,
]
rec_algorithm
=
"SVTR"
,
self
.
rec_batch_num
=
FLAGS
.
rec_batch_num
word_dict_path
=
"rec_word_dict.txt"
,
self
.
rec_algorithm
=
FLAGS
.
rec_algorithm
use_gpu
=
True
,
word_dict_path
=
FLAGS
.
word_dict_path
benchmark
=
False
):
self
.
rec_image_shape
=
input_shape
self
.
rec_batch_num
=
batch_size
self
.
rec_algorithm
=
rec_algorithm
isuse_space_char
=
True
isuse_space_char
=
True
postprocess_params
=
{
postprocess_params
=
{
...
@@ -398,7 +396,7 @@ class TextRecognizer(object):
...
@@ -398,7 +396,7 @@ class TextRecognizer(object):
return
padding_im
,
resize_shape
,
pad_shape
,
valid_ratio
return
padding_im
,
resize_shape
,
pad_shape
,
valid_ratio
def
__call__
(
self
,
img_list
):
def
predict_text
(
self
,
img_list
):
img_num
=
len
(
img_list
)
img_num
=
len
(
img_list
)
# Calculate the aspect ratio of all text bars
# Calculate the aspect ratio of all text bars
width_list
=
[]
width_list
=
[]
...
@@ -549,28 +547,36 @@ class TextRecognizer(object):
...
@@ -549,28 +547,36 @@ class TextRecognizer(object):
class
PlateRecognizer
(
object
):
class
PlateRecognizer
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
batch_size
=
8
use_gpu
=
FLAGS
.
device
.
lower
()
==
"gpu"
self
.
platedetector
=
PlateDetector
(
FLAGS
)
self
.
platedetector
=
PlateDetector
(
FLAGS
)
self
.
textrecognizer
=
TextRecognizer
(
self
.
textrecognizer
=
TextRecognizer
(
FLAGS
,
FLAGS
,
use_gpu
=
use_gpu
,
benchmark
=
FLAGS
.
run_benchmark
)
input_shape
=
[
3
,
48
,
320
],
batch_size
=
8
,
rec_algorithm
=
"SVTR"
,
word_dict_path
=
"rec_word_dict.txt"
,
use_gpu
=
True
,
benchmark
=
False
)
def
get_platelicense
(
self
,
image_list
):
def
get_platelicense
(
self
,
image_list
):
plate_text_list
=
[]
plate_text_list
=
[]
plateboxes
,
det_time
=
self
.
platedetector
.
predict_image
(
image_list
)
plateboxes
,
det_time
=
self
.
platedetector
.
predict_image
(
image_list
)
for
idx
,
boxes_pcar
in
enumerate
(
plateboxes
):
for
idx
,
boxes_pcar
in
enumerate
(
plateboxes
):
plate_images
=
get_rotate_crop_image
(
image_list
[
idx
],
boxes_pcar
)
for
box
in
boxes_pcar
:
print
(
plate_images
.
shape
)
plate_images
=
get_rotate_crop_image
(
image_list
[
idx
],
box
)
plate_texts
=
self
.
textrecognizer
(
plate_images
)
plate_texts
=
self
.
textrecognizer
.
predict_text
([
plate_images
]
)
plate_text_list
.
append
(
plate_texts
)
plate_text_list
.
append
(
plate_texts
)
import
pdb
print
(
"plate text:{}"
.
format
(
plate_texts
))
pdb
.
set_trace
()
newimg
=
draw_boxes
(
image_list
[
idx
],
boxes_pcar
)
return
results
cv2
.
imwrite
(
"vechile_plate.jpg"
,
newimg
)
return
self
.
check_plate
(
plate_text_list
)
def
check_plate
(
self
,
text_list
):
simcode
=
[
'浙'
,
'粤'
,
'京'
,
'津'
,
'冀'
,
'晋'
,
'蒙'
,
'辽'
,
'黑'
,
'沪'
,
'吉'
,
'苏'
,
'皖'
,
'赣'
,
'鲁'
,
'豫'
,
'鄂'
,
'湘'
,
'桂'
,
'琼'
,
'渝'
,
'川'
,
'贵'
,
'云'
,
'藏'
,
'陕'
,
'甘'
,
'青'
,
'宁'
]
for
text_info
in
text_list
:
# import pdb;pdb.set_trace()
text
=
text_info
[
0
][
0
][
0
]
if
len
(
text
)
>
2
and
text
[
0
]
in
simcode
and
len
(
text
)
<
10
:
print
(
"text:{} length:{}"
.
format
(
text
,
len
(
text
)))
return
text
def
main
():
def
main
():
...
@@ -581,17 +587,16 @@ def main():
...
@@ -581,17 +587,16 @@ def main():
img_list
=
get_test_images
(
FLAGS
.
image_dir
,
FLAGS
.
image_file
)
img_list
=
get_test_images
(
FLAGS
.
image_dir
,
FLAGS
.
image_file
)
for
img
in
img_list
:
for
img
in
img_list
:
image
=
cv2
.
imread
(
img
)
image
=
cv2
.
imread
(
img
)
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results
=
detector
.
get_platelicense
([
image
])
results
=
detector
.
get_platelicense
([
image
])
if
not
FLAGS
.
run_benchmark
:
if
FLAGS
.
run_benchmark
:
detector
.
det_times
.
info
(
average
=
True
)
else
:
mems
=
{
mems
=
{
'cpu_rss_mb'
:
detector
.
cpu_mem
/
len
(
img_list
),
'cpu_rss_mb'
:
detector
.
cpu_mem
/
len
(
img_list
),
'gpu_rss_mb'
:
detector
.
gpu_mem
/
len
(
img_list
),
'gpu_rss_mb'
:
detector
.
gpu_mem
/
len
(
img_list
),
'gpu_util'
:
detector
.
gpu_util
*
100
/
len
(
img_list
)
'gpu_util'
:
detector
.
gpu_util
*
100
/
len
(
img_list
)
}
}
perf_info
=
detector
.
det_
times
.
report
(
average
=
True
)
perf_info
=
detector
.
self
.
autolog
.
times
.
report
(
average
=
True
)
model_dir
=
FLAGS
.
model_dir
model_dir
=
FLAGS
.
model_dir
mode
=
FLAGS
.
run_mode
mode
=
FLAGS
.
run_mode
model_info
=
{
model_info
=
{
...
...
deploy/python/vechile_plateutils.py
浏览文件 @
ac252a34
...
@@ -40,6 +40,10 @@ def argsparser():
...
@@ -40,6 +40,10 @@ def argsparser():
parser
.
add_argument
(
"--rec_model_dir"
,
type
=
str
)
parser
.
add_argument
(
"--rec_model_dir"
,
type
=
str
)
parser
.
add_argument
(
"--rec_image_shape"
,
type
=
str
,
default
=
"3, 48, 320"
)
parser
.
add_argument
(
"--rec_image_shape"
,
type
=
str
,
default
=
"3, 48, 320"
)
parser
.
add_argument
(
"--rec_batch_num"
,
type
=
int
,
default
=
6
)
parser
.
add_argument
(
"--rec_batch_num"
,
type
=
int
,
default
=
6
)
parser
.
add_argument
(
"--word_dict_path"
,
type
=
str
,
default
=
"deploy/pphuman/rec_word_dict.txt"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--image_file"
,
type
=
str
,
default
=
None
,
help
=
"Path of image file."
)
"--image_file"
,
type
=
str
,
default
=
None
,
help
=
"Path of image file."
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录