Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
a0cd182d
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a0cd182d
编写于
11月 06, 2020
作者:
L
LKKlein
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close unused gocv.Mat
上级
879172a5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
7 addition
and
4 deletion
+7
-4
deploy/paddleocr-go/ocr/core.go
deploy/paddleocr-go/ocr/core.go
+3
-0
deploy/paddleocr-go/ocr/ocr_rec.go
deploy/paddleocr-go/ocr/ocr_rec.go
+3
-2
deploy/paddleocr-go/ocr/postprocess.go
deploy/paddleocr-go/ocr/postprocess.go
+1
-0
deploy/paddleocr-go/ocr/preprocess.go
deploy/paddleocr-go/ocr/preprocess.go
+0
-2
未找到文件。
deploy/paddleocr-go/ocr/core.go
浏览文件 @
a0cd182d
...
@@ -149,6 +149,7 @@ func (sys *TextPredictSystem) getRotateCropImage(img gocv.Mat, box [][]int) gocv
...
@@ -149,6 +149,7 @@ func (sys *TextPredictSystem) getRotateCropImage(img gocv.Mat, box [][]int) gocv
func
(
sys
*
TextPredictSystem
)
Run
(
img
gocv
.
Mat
)
[]
OCRText
{
func
(
sys
*
TextPredictSystem
)
Run
(
img
gocv
.
Mat
)
[]
OCRText
{
srcimg
:=
gocv
.
NewMat
()
srcimg
:=
gocv
.
NewMat
()
defer
srcimg
.
Close
()
img
.
CopyTo
(
&
srcimg
)
img
.
CopyTo
(
&
srcimg
)
boxes
:=
sys
.
detector
.
Run
(
img
)
boxes
:=
sys
.
detector
.
Run
(
img
)
if
len
(
boxes
)
==
0
{
if
len
(
boxes
)
==
0
{
...
@@ -224,6 +225,7 @@ func (ocr *OCRSystem) predictHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -224,6 +225,7 @@ func (ocr *OCRSystem) predictHandler(w http.ResponseWriter, r *http.Request) {
io
.
Copy
(
&
buf
,
file
)
io
.
Copy
(
&
buf
,
file
)
img
,
err2
:=
gocv
.
IMDecode
(
buf
.
Bytes
(),
gocv
.
IMReadColor
)
img
,
err2
:=
gocv
.
IMDecode
(
buf
.
Bytes
(),
gocv
.
IMReadColor
)
defer
img
.
Close
()
if
err2
!=
nil
{
if
err2
!=
nil
{
w
.
Write
([]
byte
(
err2
.
Error
()))
w
.
Write
([]
byte
(
err2
.
Error
()))
return
return
...
@@ -252,6 +254,7 @@ func (ocr *OCRSystem) PredictDirImages(dirname string) map[string][]OCRText {
...
@@ -252,6 +254,7 @@ func (ocr *OCRSystem) PredictDirImages(dirname string) map[string][]OCRText {
for
i
:=
0
;
i
<
len
(
imgs
);
i
++
{
for
i
:=
0
;
i
<
len
(
imgs
);
i
++
{
imgname
:=
imgs
[
i
]
imgname
:=
imgs
[
i
]
img
:=
ReadImage
(
imgname
)
img
:=
ReadImage
(
imgname
)
defer
img
.
Close
()
res
:=
ocr
.
PredictOneImage
(
img
)
res
:=
ocr
.
PredictOneImage
(
img
)
results
[
imgname
]
=
res
results
[
imgname
]
=
res
}
}
...
...
deploy/paddleocr-go/ocr/ocr_rec.go
浏览文件 @
a0cd182d
...
@@ -24,7 +24,8 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
...
@@ -24,7 +24,8 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
shapes
[
i
]
=
s
.
(
int
)
shapes
[
i
]
=
s
.
(
int
)
}
}
}
}
labelpath
:=
getString
(
args
,
"rec_char_dict_path"
,
"./config/ppocr_keys_v1.txt"
)
home
,
_
:=
os
.
UserHomeDir
()
labelpath
:=
getString
(
args
,
"rec_char_dict_path"
,
home
+
"/.paddleocr/rec/ppocr_keys_v1.txt"
)
labels
:=
readLines2StringSlice
(
labelpath
)
labels
:=
readLines2StringSlice
(
labelpath
)
if
getBool
(
args
,
"use_space_char"
,
true
)
{
if
getBool
(
args
,
"use_space_char"
,
true
)
{
labels
=
append
(
labels
,
" "
)
labels
=
append
(
labels
,
" "
)
...
@@ -38,7 +39,6 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
...
@@ -38,7 +39,6 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
labels
:
labels
,
labels
:
labels
,
}
}
if
checkModelExists
(
modelDir
)
{
if
checkModelExists
(
modelDir
)
{
home
,
_
:=
os
.
UserHomeDir
()
modelDir
,
_
=
downloadModel
(
home
+
"/.paddleocr/rec/ch"
,
modelDir
)
modelDir
,
_
=
downloadModel
(
home
+
"/.paddleocr/rec/ch"
,
modelDir
)
}
else
{
}
else
{
log
.
Panicf
(
"rec model path: %v not exist! Please check!"
,
modelDir
)
log
.
Panicf
(
"rec model path: %v not exist! Please check!"
,
modelDir
)
...
@@ -75,6 +75,7 @@ func (rec *TextRecognizer) Run(imgs []gocv.Mat, bboxes [][][]int) []OCRText {
...
@@ -75,6 +75,7 @@ func (rec *TextRecognizer) Run(imgs []gocv.Mat, bboxes [][][]int) []OCRText {
for
k
:=
i
;
k
<
j
;
k
++
{
for
k
:=
i
;
k
<
j
;
k
++
{
data
:=
crnnPreprocess
(
imgs
[
k
],
rec
.
shape
,
[]
float32
{
0.5
,
0.5
,
0.5
},
data
:=
crnnPreprocess
(
imgs
[
k
],
rec
.
shape
,
[]
float32
{
0.5
,
0.5
,
0.5
},
[]
float32
{
0.5
,
0.5
,
0.5
},
255.0
,
maxwhratio
,
rec
.
charType
)
[]
float32
{
0.5
,
0.5
,
0.5
},
255.0
,
maxwhratio
,
rec
.
charType
)
defer
imgs
[
k
]
.
Close
()
copy
(
normimgs
[(
k
-
i
)
*
c
*
h
*
w
:
],
data
)
copy
(
normimgs
[(
k
-
i
)
*
c
*
h
*
w
:
],
data
)
}
}
...
...
deploy/paddleocr-go/ocr/postprocess.go
浏览文件 @
a0cd182d
...
@@ -92,6 +92,7 @@ func (d *DBPostProcess) boxScoreFast(array [][]float32, pred gocv.Mat) float64 {
...
@@ -92,6 +92,7 @@ func (d *DBPostProcess) boxScoreFast(array [][]float32, pred gocv.Mat) float64 {
ymax
:=
clip
(
int
(
math
.
Ceil
(
float64
(
maxf
(
boxY
)))),
0
,
height
-
1
)
ymax
:=
clip
(
int
(
math
.
Ceil
(
float64
(
maxf
(
boxY
)))),
0
,
height
-
1
)
mask
:=
gocv
.
NewMatWithSize
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
gocv
.
MatTypeCV8UC1
)
mask
:=
gocv
.
NewMatWithSize
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
gocv
.
MatTypeCV8UC1
)
defer
mask
.
Close
()
ppt
:=
make
([][]
image
.
Point
,
1
)
ppt
:=
make
([][]
image
.
Point
,
1
)
ppt
[
0
]
=
make
([]
image
.
Point
,
4
)
ppt
[
0
]
=
make
([]
image
.
Point
,
4
)
ppt
[
0
][
0
]
=
image
.
Point
{
int
(
array
[
0
][
0
])
-
xmin
,
int
(
array
[
0
][
1
])
-
ymin
}
ppt
[
0
][
0
]
=
image
.
Point
{
int
(
array
[
0
][
0
])
-
xmin
,
int
(
array
[
0
][
1
])
-
ymin
}
...
...
deploy/paddleocr-go/ocr/preprocess.go
浏览文件 @
a0cd182d
...
@@ -59,7 +59,6 @@ func resizeByMaxLen(img gocv.Mat, maxLen int) (gocv.Mat, int, int) {
...
@@ -59,7 +59,6 @@ func resizeByMaxLen(img gocv.Mat, maxLen int) (gocv.Mat, int, int) {
func
normPermute
(
img
gocv
.
Mat
,
mean
[]
float32
,
std
[]
float32
,
scaleFactor
float32
)
[]
float32
{
func
normPermute
(
img
gocv
.
Mat
,
mean
[]
float32
,
std
[]
float32
,
scaleFactor
float32
)
[]
float32
{
img
.
ConvertTo
(
&
img
,
gocv
.
MatTypeCV32F
)
img
.
ConvertTo
(
&
img
,
gocv
.
MatTypeCV32F
)
img
.
DivideFloat
(
scaleFactor
)
img
.
DivideFloat
(
scaleFactor
)
defer
img
.
Close
()
c
:=
gocv
.
Split
(
img
)
c
:=
gocv
.
Split
(
img
)
data
:=
make
([]
float32
,
img
.
Rows
()
*
img
.
Cols
()
*
img
.
Channels
())
data
:=
make
([]
float32
,
img
.
Rows
()
*
img
.
Cols
()
*
img
.
Channels
())
...
@@ -154,7 +153,6 @@ func crnnPreprocess(img gocv.Mat, resizeShape []int, mean []float32, std []float
...
@@ -154,7 +153,6 @@ func crnnPreprocess(img gocv.Mat, resizeShape []int, mean []float32, std []float
img
.
DivideFloat
(
scaleFactor
)
img
.
DivideFloat
(
scaleFactor
)
img
.
SubtractScalar
(
gocv
.
NewScalar
(
float64
(
mean
[
0
]),
float64
(
mean
[
1
]),
float64
(
mean
[
2
]),
0
))
img
.
SubtractScalar
(
gocv
.
NewScalar
(
float64
(
mean
[
0
]),
float64
(
mean
[
1
]),
float64
(
mean
[
2
]),
0
))
img
.
DivideScalar
(
gocv
.
NewScalar
(
float64
(
std
[
0
]),
float64
(
std
[
1
]),
float64
(
std
[
2
]),
0
))
img
.
DivideScalar
(
gocv
.
NewScalar
(
float64
(
std
[
0
]),
float64
(
std
[
1
]),
float64
(
std
[
2
]),
0
))
defer
img
.
Close
()
if
resizeW
<
imgW
{
if
resizeW
<
imgW
{
gocv
.
CopyMakeBorder
(
img
,
&
img
,
0
,
0
,
0
,
imgW
-
resizeW
,
gocv
.
BorderConstant
,
color
.
RGBA
{
0
,
0
,
0
,
0
})
gocv
.
CopyMakeBorder
(
img
,
&
img
,
0
,
0
,
0
,
imgW
-
resizeW
,
gocv
.
BorderConstant
,
color
.
RGBA
{
0
,
0
,
0
,
0
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录