From dd3a6c8673f3222e9481391a1cd11fc70c4324a7 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Mon, 28 Nov 2022 16:03:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B7=B3=E8=BF=87=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E9=A1=B5=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImageProcess/ImageApplyDiscardBlank.cpp | 12 ++++---- .../ImageProcess/ImageApplyDiscardBlank.h | 28 +++++++++++++++++-- hgdriver/hgdev/hg_scanner.cpp | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/hgdriver/ImageProcess/ImageApplyDiscardBlank.cpp b/hgdriver/ImageProcess/ImageApplyDiscardBlank.cpp index 2102394..0526ed5 100644 --- a/hgdriver/ImageProcess/ImageApplyDiscardBlank.cpp +++ b/hgdriver/ImageProcess/ImageApplyDiscardBlank.cpp @@ -15,7 +15,7 @@ CImageApplyDiscardBlank::~CImageApplyDiscardBlank(void) 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(); } @@ -49,7 +49,7 @@ bool maxMinCompare(const cv::Mat& img, const cv::Mat& mask, double devTh, double 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()) return true; @@ -60,11 +60,11 @@ bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int e cv::Mat threshold_img; if (img_resize.channels() == 3) 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> contours; std::vector 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 contour; for (const std::vector& sub : contours) @@ -83,7 +83,9 @@ bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int e contours.push_back(contour); cv::Mat mask = cv::Mat::zeros(img_resize.size(), CV_8UC1); 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; if (img_resize.channels() == 3) diff --git a/hgdriver/ImageProcess/ImageApplyDiscardBlank.h b/hgdriver/ImageProcess/ImageApplyDiscardBlank.h index e6f4aad..df9cb72 100644 --- a/hgdriver/ImageProcess/ImageApplyDiscardBlank.h +++ b/hgdriver/ImageProcess/ImageApplyDiscardBlank.h @@ -14,7 +14,11 @@ 2021/12/14 v1.3.2 重构算法。 2021/12/15 v1.3.3 微调参数。 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: - CImageApplyDiscardBlank(double threshold = 40, int edge = 150, double devTh = 50, double meanTh = 200); + /// + /// 空白页识别 + /// + /// 原图 + /// 轮廓阈值 + /// 边缘缩进 + /// 笔迹判定阈值。该阈值越低,越容易判定存在笔迹。 + /// 文稿底色阈值。低于该阈值的文稿底色,直接视为非空白页。 + /// + CImageApplyDiscardBlank(double threshold = 40, int edge = 50, double devTh = 30, double meanTh = 200); virtual ~CImageApplyDiscardBlank(void); @@ -36,7 +49,16 @@ public: virtual void apply(std::vector& 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); + /// + /// 空白页识别 + /// + /// 原图 + /// 轮廓阈值 + /// 边缘缩进 + /// 笔迹判定阈值。该阈值越低,越容易判定存在笔迹。 + /// 文稿底色阈值。低于该阈值的文稿底色,直接视为非空白页。 + /// + static bool apply(const cv::Mat& pDib, double threshold = 40, int edge = 50, double devTh = 30, double meanTh = 200); private: double m_threshold; diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 9409e32..296c23f 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -3537,7 +3537,7 @@ int hg_scanner::image_configuration(SCANCONF& ic) ic.is_autocontrast = 0; //鏃犲弬鏁 ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype == TwSS::USStatement); 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_switchfrontback = image_prc_param_.bits.exchange; ic.autodescrew = image_prc_param_.bits.automatic_skew;