Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
c3785440
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看板
提交
c3785440
编写于
8月 03, 2020
作者:
A
authorfu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
注释改为英语的
上级
c3c417f5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
31 addition
and
30 deletion
+31
-30
deploy/android_demo/app/src/main/cpp/native.cpp
deploy/android_demo/app/src/main/cpp/native.cpp
+1
-1
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp
+1
-1
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h
+12
-12
deploy/android_demo/app/src/main/cpp/ppredictor.h
deploy/android_demo/app/src/main/cpp/ppredictor.h
+4
-4
deploy/android_demo/app/src/main/cpp/predictor_output.h
deploy/android_demo/app/src/main/cpp/predictor_output.h
+4
-4
deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java
...ain/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java
+7
-6
deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java
...c/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java
+2
-2
未找到文件。
deploy/android_demo/app/src/main/cpp/native.cpp
浏览文件 @
c3785440
...
@@ -30,7 +30,7 @@ Java_com_baidu_paddle_lite_demo_ocr_OCRPredictorNative_init(JNIEnv *env, jobject
...
@@ -30,7 +30,7 @@ Java_com_baidu_paddle_lite_demo_ocr_OCRPredictorNative_init(JNIEnv *env, jobject
}
}
/**
/**
* "LITE_POWER_HIGH"
转为
paddle::lite_api::LITE_POWER_HIGH
* "LITE_POWER_HIGH"
convert to
paddle::lite_api::LITE_POWER_HIGH
* @param cpu_mode
* @param cpu_mode
* @return
* @return
*/
*/
...
...
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.cpp
浏览文件 @
c3785440
...
@@ -37,7 +37,7 @@ int OCR_PPredictor::init_from_file(const std::string &det_model_path, const std:
...
@@ -37,7 +37,7 @@ int OCR_PPredictor::init_from_file(const std::string &det_model_path, const std:
return
RETURN_OK
;
return
RETURN_OK
;
}
}
/**
/**
*
调试用,保存第一步的框选结果
*
for debug use, show result of First Step
* @param filter_boxes
* @param filter_boxes
* @param boxes
* @param boxes
* @param srcimg
* @param srcimg
...
...
deploy/android_demo/app/src/main/cpp/ocr_ppredictor.h
浏览文件 @
c3785440
...
@@ -12,26 +12,26 @@
...
@@ -12,26 +12,26 @@
namespace
ppredictor
{
namespace
ppredictor
{
/**
/**
*
配置
*
Config
*/
*/
struct
OCR_Config
{
struct
OCR_Config
{
int
thread_num
=
4
;
//
线程数
int
thread_num
=
4
;
//
Thread num
paddle
::
lite_api
::
PowerMode
mode
=
paddle
::
lite_api
::
LITE_POWER_HIGH
;
// PaddleLite Mode
paddle
::
lite_api
::
PowerMode
mode
=
paddle
::
lite_api
::
LITE_POWER_HIGH
;
// PaddleLite Mode
};
};
/**
/**
*
一个四边形内图片的推理结果,
*
PolyGone Result
*/
*/
struct
OCRPredictResult
{
struct
OCRPredictResult
{
std
::
vector
<
int
>
word_index
;
//
std
::
vector
<
int
>
word_index
;
std
::
vector
<
std
::
vector
<
int
>>
points
;
std
::
vector
<
std
::
vector
<
int
>>
points
;
float
score
;
float
score
;
};
};
/**
/**
* OCR
一共有2个模型进行推理,
* OCR
there are 2 models
* 1.
使用第一个模型(det),框选出多个四边形
* 1.
First model(det),select polygones to show where are the texts
* 2.
从原图从抠出这些多边形,使用第二个模型(rec),获取文本
* 2.
crop from the origin images, use these polygones to infer
*/
*/
class
OCR_PPredictor
:
public
PPredictor_Interface
{
class
OCR_PPredictor
:
public
PPredictor_Interface
{
public:
public:
...
@@ -50,7 +50,7 @@ public:
...
@@ -50,7 +50,7 @@ public:
int
init
(
const
std
::
string
&
det_model_content
,
const
std
::
string
&
rec_model_content
);
int
init
(
const
std
::
string
&
det_model_content
,
const
std
::
string
&
rec_model_content
);
int
init_from_file
(
const
std
::
string
&
det_model_path
,
const
std
::
string
&
rec_model_path
);
int
init_from_file
(
const
std
::
string
&
det_model_path
,
const
std
::
string
&
rec_model_path
);
/**
/**
*
返回OCR结果
*
Return OCR result
* @param dims
* @param dims
* @param input_data
* @param input_data
* @param input_len
* @param input_len
...
@@ -69,7 +69,7 @@ public:
...
@@ -69,7 +69,7 @@ public:
private:
private:
/**
/**
*
从第一个模型的结果中计算有文字的四边形
*
calcul Polygone from the result image of first model
* @param pred
* @param pred
* @param output_height
* @param output_height
* @param output_width
* @param output_width
...
@@ -81,7 +81,7 @@ private:
...
@@ -81,7 +81,7 @@ private:
const
cv
::
Mat
&
origin
);
const
cv
::
Mat
&
origin
);
/**
/**
*
第二个模型的推理
*
infer for second model
*
*
* @param boxes
* @param boxes
* @param origin
* @param origin
...
@@ -91,14 +91,14 @@ private:
...
@@ -91,14 +91,14 @@ private:
infer_rec
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
,
const
cv
::
Mat
&
origin
);
infer_rec
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
,
const
cv
::
Mat
&
origin
);
/**
/**
*
第二个模型提取文字的后处理
*
Postprocess or sencod model to extract text
* @param res
* @param res
* @return
* @return
*/
*/
std
::
vector
<
int
>
postprocess_rec_word_index
(
const
PredictorOutput
&
res
);
std
::
vector
<
int
>
postprocess_rec_word_index
(
const
PredictorOutput
&
res
);
/**
/**
*
计算第二个模型的文字的置信度
*
calculate confidence of second model text result
* @param res
* @param res
* @return
* @return
*/
*/
...
...
deploy/android_demo/app/src/main/cpp/ppredictor.h
浏览文件 @
c3785440
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
namespace
ppredictor
{
namespace
ppredictor
{
/**
/**
* PaddleLite Preditor
通用接口
* PaddleLite Preditor
Common Interface
*/
*/
class
PPredictor_Interface
{
class
PPredictor_Interface
{
public:
public:
...
@@ -21,7 +21,7 @@ public:
...
@@ -21,7 +21,7 @@ public:
};
};
/**
/**
*
通用推理
*
Common Predictor
*/
*/
class
PPredictor
:
public
PPredictor_Interface
{
class
PPredictor
:
public
PPredictor_Interface
{
public:
public:
...
@@ -33,9 +33,9 @@ public:
...
@@ -33,9 +33,9 @@ public:
}
}
/**
/**
*
初始化paddlitelite的opt模型,nb格式,与init_paddle二选一
*
init paddlitelite opt model,nb format ,or use ini_paddle
* @param model_content
* @param model_content
* @return 0
目前是固定值0, 之后其他值表示失败
* @return 0
*/
*/
virtual
int
init_nb
(
const
std
::
string
&
model_content
);
virtual
int
init_nb
(
const
std
::
string
&
model_content
);
...
...
deploy/android_demo/app/src/main/cpp/predictor_output.h
浏览文件 @
c3785440
...
@@ -21,10 +21,10 @@ public:
...
@@ -21,10 +21,10 @@ public:
const
std
::
vector
<
std
::
vector
<
uint64_t
>>
get_lod
()
const
;
const
std
::
vector
<
std
::
vector
<
uint64_t
>>
get_lod
()
const
;
const
std
::
vector
<
int64_t
>
get_shape
()
const
;
const
std
::
vector
<
int64_t
>
get_shape
()
const
;
std
::
vector
<
float
>
data
;
//
通常是float返回,与下面的data_int二选一
std
::
vector
<
float
>
data
;
//
return float, or use data_int
std
::
vector
<
int
>
data_int
;
//
少数层是int返回,与 data二选一
std
::
vector
<
int
>
data_int
;
//
several layers return int ,or use data
std
::
vector
<
int64_t
>
shape
;
// PaddleLite
输出层的
shape
std
::
vector
<
int64_t
>
shape
;
// PaddleLite
output
shape
std
::
vector
<
std
::
vector
<
uint64_t
>>
lod
;
// PaddleLite
输出层的
lod
std
::
vector
<
std
::
vector
<
uint64_t
>>
lod
;
// PaddleLite
output
lod
private:
private:
std
::
unique_ptr
<
const
paddle
::
lite_api
::
Tensor
>
_tensor
;
std
::
unique_ptr
<
const
paddle
::
lite_api
::
Tensor
>
_tensor
;
...
...
deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/MiniActivity.java
浏览文件 @
c3785440
...
@@ -41,8 +41,8 @@ public class MiniActivity extends AppCompatActivity {
...
@@ -41,8 +41,8 @@ public class MiniActivity extends AppCompatActivity {
private
String
assetlabelFilePath
=
"labels/ppocr_keys_v1.txt"
;
private
String
assetlabelFilePath
=
"labels/ppocr_keys_v1.txt"
;
private
Button
button
;
private
Button
button
;
private
ImageView
imageView
;
//
显示图像
private
ImageView
imageView
;
//
image result
private
TextView
textView
;
//
显示结果
private
TextView
textView
;
//
text result
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -85,7 +85,7 @@ public class MiniActivity extends AppCompatActivity {
...
@@ -85,7 +85,7 @@ public class MiniActivity extends AppCompatActivity {
}
}
}
}
};
};
sender
.
sendEmptyMessage
(
REQUEST_LOAD_MODEL
);
//
对应上面的REQUEST_LOAD_MODEL, 调用
onLoadModel()
sender
.
sendEmptyMessage
(
REQUEST_LOAD_MODEL
);
//
corresponding to REQUEST_LOAD_MODEL, to call
onLoadModel()
imageView
=
findViewById
(
R
.
id
.
imageView
);
imageView
=
findViewById
(
R
.
id
.
imageView
);
textView
=
findViewById
(
R
.
id
.
sample_text
);
textView
=
findViewById
(
R
.
id
.
sample_text
);
...
@@ -112,7 +112,7 @@ public class MiniActivity extends AppCompatActivity {
...
@@ -112,7 +112,7 @@ public class MiniActivity extends AppCompatActivity {
}
}
/**
/**
*
onCreate的时候调用, 模型初始化
*
call in onCreate, model init
*
*
* @return
* @return
*/
*/
...
@@ -124,7 +124,8 @@ public class MiniActivity extends AppCompatActivity {
...
@@ -124,7 +124,8 @@ public class MiniActivity extends AppCompatActivity {
}
}
/**
/**
* on
* init engine
* call in onCreate
*
*
* @return
* @return
*/
*/
...
@@ -133,7 +134,7 @@ public class MiniActivity extends AppCompatActivity {
...
@@ -133,7 +134,7 @@ public class MiniActivity extends AppCompatActivity {
String
assetImagePath
=
"images/5.jpg"
;
String
assetImagePath
=
"images/5.jpg"
;
InputStream
imageStream
=
getAssets
().
open
(
assetImagePath
);
InputStream
imageStream
=
getAssets
().
open
(
assetImagePath
);
Bitmap
image
=
BitmapFactory
.
decodeStream
(
imageStream
);
Bitmap
image
=
BitmapFactory
.
decodeStream
(
imageStream
);
//
这里输入是
Bitmap
//
Input is
Bitmap
predictor
.
setInputImage
(
image
);
predictor
.
setInputImage
(
image
);
return
predictor
.
isLoaded
()
&&
predictor
.
runModel
();
return
predictor
.
isLoaded
()
&&
predictor
.
runModel
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
...
deploy/android_demo/app/src/main/java/com/baidu/paddle/lite/demo/ocr/Predictor.java
浏览文件 @
c3785440
...
@@ -228,7 +228,7 @@ public class Predictor {
...
@@ -228,7 +228,7 @@ public class Predictor {
for
(
int
i
=
0
;
i
<
warmupIterNum
;
i
++)
{
for
(
int
i
=
0
;
i
<
warmupIterNum
;
i
++)
{
paddlePredictor
.
runImage
(
inputData
,
width
,
height
,
channels
,
inputImage
);
paddlePredictor
.
runImage
(
inputData
,
width
,
height
,
channels
,
inputImage
);
}
}
warmupIterNum
=
0
;
//
之后不要再warm了
warmupIterNum
=
0
;
//
do not need warm
// Run inference
// Run inference
start
=
new
Date
();
start
=
new
Date
();
ArrayList
<
OcrResultModel
>
results
=
paddlePredictor
.
runImage
(
inputData
,
width
,
height
,
channels
,
inputImage
);
ArrayList
<
OcrResultModel
>
results
=
paddlePredictor
.
runImage
(
inputData
,
width
,
height
,
channels
,
inputImage
);
...
@@ -323,7 +323,7 @@ public class Predictor {
...
@@ -323,7 +323,7 @@ public class Predictor {
for
(
Point
p
:
result
.
getPoints
())
{
for
(
Point
p
:
result
.
getPoints
())
{
sb
.
append
(
"("
).
append
(
p
.
x
).
append
(
","
).
append
(
p
.
y
).
append
(
") "
);
sb
.
append
(
"("
).
append
(
p
.
x
).
append
(
","
).
append
(
p
.
y
).
append
(
") "
);
}
}
Log
.
i
(
TAG
,
sb
.
toString
());
//
这里在logcat里打印结果
Log
.
i
(
TAG
,
sb
.
toString
());
//
show LOG in Logcat panel
outputResultSb
.
append
(
i
+
1
).
append
(
": "
).
append
(
result
.
getLabel
()).
append
(
"\n"
);
outputResultSb
.
append
(
i
+
1
).
append
(
": "
).
append
(
result
.
getLabel
()).
append
(
"\n"
);
}
}
outputResult
=
outputResultSb
.
toString
();
outputResult
=
outputResultSb
.
toString
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录