更新跳过空白页算法
This commit is contained in:
parent
ba87aeb1a4
commit
dd3a6c8673
|
@ -15,7 +15,7 @@ CImageApplyDiscardBlank::~CImageApplyDiscardBlank(void)
|
||||||
|
|
||||||
void CImageApplyDiscardBlank::apply(cv::Mat& pDib, int side)
|
void CImageApplyDiscardBlank::apply(cv::Mat& pDib, int side)
|
||||||
{
|
{
|
||||||
if (apply(pDib, m_threshold, m_edge, m_devTh))
|
if (apply(pDib, m_threshold, m_edge, m_devTh, m_meanTh))
|
||||||
pDib.release();
|
pDib.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ bool maxMinCompare(const cv::Mat& img, const cv::Mat& mask, double devTh, double
|
||||||
return (max - min) < devTh;
|
return (max - min) < devTh;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int edge, int blockSize, double devTh, double meanTh)
|
bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int edge, double devTh, double meanTh)
|
||||||
{
|
{
|
||||||
if (pDib.empty())
|
if (pDib.empty())
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,11 +60,11 @@ bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int e
|
||||||
cv::Mat threshold_img;
|
cv::Mat threshold_img;
|
||||||
if (img_resize.channels() == 3)
|
if (img_resize.channels() == 3)
|
||||||
cv::cvtColor(img_resize, threshold_img, cv::COLOR_BGR2GRAY);
|
cv::cvtColor(img_resize, threshold_img, cv::COLOR_BGR2GRAY);
|
||||||
cv::threshold(img_resize.channels() == 3 ? threshold_img : img_resize, threshold_img, threshold, 255, CV_THRESH_BINARY);
|
cv::threshold(img_resize.channels() == 3 ? threshold_img : img_resize, threshold_img, threshold, 255, cv::THRESH_BINARY);
|
||||||
|
|
||||||
std::vector<std::vector<cv::Point>> contours;
|
std::vector<std::vector<cv::Point>> contours;
|
||||||
std::vector<cv::Vec4i> h1;
|
std::vector<cv::Vec4i> h1;
|
||||||
hg::findContours(threshold_img, contours, h1, cv::RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
|
hg::findContours(threshold_img, contours, h1, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
||||||
|
|
||||||
std::vector<cv::Point> contour;
|
std::vector<cv::Point> contour;
|
||||||
for (const std::vector<cv::Point>& sub : contours)
|
for (const std::vector<cv::Point>& sub : contours)
|
||||||
|
@ -83,7 +83,9 @@ bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int e
|
||||||
contours.push_back(contour);
|
contours.push_back(contour);
|
||||||
cv::Mat mask = cv::Mat::zeros(img_resize.size(), CV_8UC1);
|
cv::Mat mask = cv::Mat::zeros(img_resize.size(), CV_8UC1);
|
||||||
hg::fillPolys(mask, contours, cv::Scalar::all(255));
|
hg::fillPolys(mask, contours, cv::Scalar::all(255));
|
||||||
cv::blur(img_resize, img_resize, cv::Size(3, 3));
|
int kSize = (devTh / 20) / 2 * 2 + 1;
|
||||||
|
if (kSize > 1)
|
||||||
|
cv::blur(img_resize, img_resize, cv::Size(kSize, kSize));
|
||||||
|
|
||||||
bool b = true;
|
bool b = true;
|
||||||
if (img_resize.channels() == 3)
|
if (img_resize.channels() == 3)
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
2021/12/14 v1.3.2 重构算法。
|
2021/12/14 v1.3.2 重构算法。
|
||||||
2021/12/15 v1.3.3 微调参数。
|
2021/12/15 v1.3.3 微调参数。
|
||||||
2021/12/17 v1.3.4 增加背景色接口,实现对纯色纸张的空白页判定
|
2021/12/17 v1.3.4 增加背景色接口,实现对纯色纸张的空白页判定
|
||||||
* 版本号:v1.3.4
|
2022/09/07 v1.3.5 修复部分参数传递的BUG
|
||||||
|
2022/09/19 v1.4 增加模糊处理,提高空白页的过滤能力
|
||||||
|
2022/09/19 v1.4.1 调整模糊处理步骤
|
||||||
|
2022/11/18 v1.4.2 调整默认参数
|
||||||
|
* 版本号:v1.4.2
|
||||||
|
|
||||||
* ====================================================
|
* ====================================================
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +32,16 @@ class GIMGPROC_LIBRARY_API CImageApplyDiscardBlank : public CImageApply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CImageApplyDiscardBlank(double threshold = 40, int edge = 150, double devTh = 50, double meanTh = 200);
|
/// <summary>
|
||||||
|
/// 空白页识别
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pDib">原图</param>
|
||||||
|
/// <param name="threshold">轮廓阈值</param>
|
||||||
|
/// <param name="edge">边缘缩进</param>
|
||||||
|
/// <param name="devTh">笔迹判定阈值。该阈值越低,越容易判定存在笔迹。</param>
|
||||||
|
/// <param name="meanTh">文稿底色阈值。低于该阈值的文稿底色,直接视为非空白页。</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
CImageApplyDiscardBlank(double threshold = 40, int edge = 50, double devTh = 30, double meanTh = 200);
|
||||||
|
|
||||||
virtual ~CImageApplyDiscardBlank(void);
|
virtual ~CImageApplyDiscardBlank(void);
|
||||||
|
|
||||||
|
@ -36,7 +49,16 @@ public:
|
||||||
|
|
||||||
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
||||||
|
|
||||||
static bool apply(const cv::Mat& pDib, double threshold = 40, int edge = 150, int blockSize = 10, double devTh = 50, double meanTh = 200);
|
/// <summary>
|
||||||
|
/// 空白页识别
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pDib">原图</param>
|
||||||
|
/// <param name="threshold">轮廓阈值</param>
|
||||||
|
/// <param name="edge">边缘缩进</param>
|
||||||
|
/// <param name="devTh">笔迹判定阈值。该阈值越低,越容易判定存在笔迹。</param>
|
||||||
|
/// <param name="meanTh">文稿底色阈值。低于该阈值的文稿底色,直接视为非空白页。</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static bool apply(const cv::Mat& pDib, double threshold = 40, int edge = 50, double devTh = 30, double meanTh = 200);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_threshold;
|
double m_threshold;
|
||||||
|
|
|
@ -3537,7 +3537,7 @@ int hg_scanner::image_configuration(SCANCONF& ic)
|
||||||
ic.is_autocontrast = 0; //无参数
|
ic.is_autocontrast = 0; //无参数
|
||||||
ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype == TwSS::USStatement);
|
ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype == TwSS::USStatement);
|
||||||
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY;
|
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY;
|
||||||
ic.discardblank_percent = omit_empty_level_ >= 70 ? 70 : omit_empty_level_;
|
ic.discardblank_percent = omit_empty_level_;
|
||||||
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
|
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
|
||||||
ic.is_switchfrontback = image_prc_param_.bits.exchange;
|
ic.is_switchfrontback = image_prc_param_.bits.exchange;
|
||||||
ic.autodescrew = image_prc_param_.bits.automatic_skew;
|
ic.autodescrew = image_prc_param_.bits.automatic_skew;
|
||||||
|
|
Loading…
Reference in New Issue