Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
a7660331a
tesseract
提交
43747d6e
T
tesseract
项目概览
a7660331a
/
tesseract
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tesseract
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
43747d6e
编写于
5月 10, 2021
作者:
E
Egor Pugin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Postfix for #3418.
上级
e7c01a6f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
34 deletion
+36
-34
include/tesseract/publictypes.h
include/tesseract/publictypes.h
+5
-4
src/api/baseapi.cpp
src/api/baseapi.cpp
+7
-7
src/ccmain/tesseractclass.cpp
src/ccmain/tesseractclass.cpp
+2
-2
src/ccmain/thresholder.cpp
src/ccmain/thresholder.cpp
+17
-17
src/ccmain/thresholder.h
src/ccmain/thresholder.h
+1
-1
src/ccstruct/image.h
src/ccstruct/image.h
+4
-3
未找到文件。
include/tesseract/publictypes.h
浏览文件 @
43747d6e
...
...
@@ -278,15 +278,16 @@ enum OcrEngineMode {
OEM_COUNT
// Number of OEMs
};
/**
/**
* Except when Otsu is chosen
* Leptonica is used for thresholding
* Leptonica is used for thresholding
*/
enum
class
ThreshMethod
{
enum
class
Thresh
old
Method
{
Otsu
,
// Legacy Tesseract's Otsu thresholding
AdaptiveOtsu
,
TiledSauvola
,
Count
,
// Number of Thresholding methods
Max
,
// Number of Thresholding methods
};
}
// namespace tesseract.
...
...
src/api/baseapi.cpp
浏览文件 @
43747d6e
...
...
@@ -2113,14 +2113,14 @@ bool TessBaseAPI::Threshold(Pix **pix) {
Image
pix_grey
;
Image
pix_thresholds
;
auto
thresholding_method
=
static_cast
<
ThreshMethod
>
(
static_cast
<
int
>
(
tesseract_
->
thresholding_method
));
auto
thresholding_method
=
static_cast
<
Thresh
old
Method
>
(
static_cast
<
int
>
(
tesseract_
->
thresholding_method
));
if
(
thresholding_method
==
ThreshMethod
::
Otsu
)
{
if
(
thresholding_method
==
Thresh
old
Method
::
Otsu
)
{
if
(
!
thresholder_
->
ThresholdToPix
(
pageseg_mode
,
&
pix_binary
))
{
return
false
;
}
*
pix
=
pix_binary
;
if
(
!
thresholder_
->
IsBinary
())
{
tesseract_
->
set_pix_thresholds
(
thresholder_
->
GetPixRectThresholds
());
tesseract_
->
set_pix_grey
(
thresholder_
->
GetPixRectGrey
());
...
...
@@ -2137,12 +2137,12 @@ bool TessBaseAPI::Threshold(Pix **pix) {
*
pix
=
pix_binary
;
tesseract_
->
set_pix_thresholds
(
pix_thresholds
);
tesseract_
->
set_pix_grey
(
pix_grey
);
}
tesseract_
->
set_pix_grey
(
pix_grey
);
}
thresholder_
->
GetImageSizes
(
&
rect_left_
,
&
rect_top_
,
&
rect_width_
,
&
rect_height_
,
&
image_width_
,
&
image_height_
);
// Set the internal resolution that is used for layout parameters from the
// estimated resolution, rather than the image resolution, which may be
// fabricated, but we will use the image resolution, if there is one, to
...
...
src/ccmain/tesseractclass.cpp
浏览文件 @
43747d6e
...
...
@@ -75,8 +75,8 @@ Tesseract::Tesseract()
" (Values from PageSegMode enum in tesseract/publictypes.h)"
,
this
->
params
())
,
INT_MEMBER
(
thresholding_method
,
static_cast
<
int
>
(
tesseract
::
Thresh
Method
::
Otsu
),
"Thresholding "
static_cast
<
int
>
(
tesseract
::
Thresh
oldMethod
::
Otsu
),
"Thresholding "
"method: 0 = Otsu, 1 = Adaptive Otsu, 2 = Sauvola"
,
this
->
params
())
,
INT_INIT_MEMBER
(
tessedit_ocr_engine_mode
,
tesseract
::
OEM_DEFAULT
,
...
...
src/ccmain/thresholder.cpp
浏览文件 @
43747d6e
...
...
@@ -16,12 +16,6 @@
//
///////////////////////////////////////////////////////////////////////
#include <allheaders.h>
#include <cstdint> // for uint32_t
#include <cstring>
#include <tuple>
#include "otsuthr.h"
#include "thresholder.h"
#include "tprintf.h" // for tprintf
...
...
@@ -30,6 +24,12 @@
# include "openclwrapper.h" // for OpenclDevice
#endif
#include <allheaders.h>
#include <cstdint> // for uint32_t
#include <cstring>
#include <tuple>
namespace
tesseract
{
ImageThresholder
::
ImageThresholder
()
...
...
@@ -186,7 +186,7 @@ void ImageThresholder::SetImage(const Image pix) {
}
std
::
tuple
<
bool
,
Image
,
Image
,
Image
>
ImageThresholder
::
Threshold
(
ThreshMethod
method
)
{
Thresh
old
Method
method
)
{
Image
pix_grey
=
nullptr
;
Image
pix_binary
=
nullptr
;
Image
pix_thresholds
=
nullptr
;
...
...
@@ -195,7 +195,7 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
tprintf
(
"Image too large: (%d, %d)
\n
"
,
image_width_
,
image_height_
);
return
std
::
make_tuple
(
false
,
nullptr
,
nullptr
,
nullptr
);
}
if
(
pix_channels_
==
0
)
{
// We have a binary image, but it still has to be copied, as this API
// allows the caller to modify the output.
...
...
@@ -207,19 +207,19 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
pix_grey
=
GetPixRectGrey
();
if
(
method
==
Thresh
Method
::
Otsu
||
method
>=
ThreshMethod
::
Count
)
{
method
=
ThreshMethod
::
AdaptiveOtsu
;
if
(
method
==
Thresh
oldMethod
::
Otsu
||
method
>=
ThresholdMethod
::
Max
)
{
method
=
Thresh
old
Method
::
AdaptiveOtsu
;
}
int
r
;
if
(
method
==
ThreshMethod
::
AdaptiveOtsu
)
{
r
=
pixOtsuAdaptiveThreshold
(
pix_grey
,
300
,
300
,
0
,
0
,
0.1
,
pix_thresholds
.
a
(),
pix_binary
.
a
()
);
}
else
if
(
method
==
ThreshMethod
::
TiledSauvola
)
{
r
=
pixSauvolaBinarizeTiled
(
pix_grey
,
25
,
0.40
,
300
,
300
,
pix_thresholds
.
a
(),
pix_binary
.
a
()
);
if
(
method
==
Thresh
old
Method
::
AdaptiveOtsu
)
{
r
=
pixOtsuAdaptiveThreshold
(
pix_grey
,
300
,
300
,
0
,
0
,
0.1
,
pix_thresholds
,
pix_binary
);
}
else
if
(
method
==
Thresh
old
Method
::
TiledSauvola
)
{
r
=
pixSauvolaBinarizeTiled
(
pix_grey
,
25
,
0.40
,
300
,
300
,
pix_thresholds
,
pix_binary
);
}
bool
ok
=
r
==
0
?
true
:
false
;
return
std
::
make_tuple
(
ok
,
pix_grey
,
pix_binary
,
pix_thresholds
);
}
...
...
src/ccmain/thresholder.h
浏览文件 @
43747d6e
...
...
@@ -122,7 +122,7 @@ public:
virtual
bool
ThresholdToPix
(
PageSegMode
pageseg_mode
,
Image
*
pix
);
virtual
std
::
tuple
<
bool
,
Image
,
Image
,
Image
>
Threshold
(
ThreshMethod
method
);
Thresh
old
Method
method
);
// Gets a pix that contains an 8 bit threshold value at each pixel. The
// returned pix may be an integer reduction of the binary image such that
...
...
src/ccstruct/image.h
浏览文件 @
43747d6e
...
...
@@ -31,11 +31,12 @@ public:
Image
(
Pix
*
pix
)
:
pix_
(
pix
)
{}
// service
bool
operator
==
(
decltype
(
nullptr
))
const
{
return
pix_
==
nullptr
;
}
bool
operator
!=
(
decltype
(
nullptr
))
const
{
return
pix_
!=
nullptr
;
}
explicit
operator
bool
()
const
{
return
pix_
!=
nullptr
;
}
operator
Pix
*
()
const
{
return
pix_
;
}
explicit
operator
Pix
**
()
{
return
&
pix_
;
}
operator
Pix
**
()
{
return
&
pix_
;
}
Pix
*
operator
->
()
const
{
return
pix_
;
}
Pix
**
a
()
{
return
&
pix_
;
}
// api
Image
clone
()
const
;
// increases refcount
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录