From 3ff93b1dcacd46b1c69861b15f88d2487f9893e6 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Wed, 22 Nov 2023 15:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=BB=91=E7=99=BD=E9=98=88?= =?UTF-8?q?=E5=80=BC=E7=AE=97=E6=B3=95=EF=BC=8C=E8=A7=A3=E5=86=B3=E9=BB=91?= =?UTF-8?q?=E7=99=BD=E9=98=88=E5=80=BC=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/ImageProcess/ImageApplyBWBinaray.cpp | 14 +++++++------- hgdriver/ImageProcess/ImageApplyBWBinaray.h | 3 ++- hgdriver/hgdev/hg_scanner.cpp | 2 +- hgdriver/hgdev/image_process.cpp | 8 ++++---- hgdriver/hgdev/image_process.h | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/hgdriver/ImageProcess/ImageApplyBWBinaray.cpp b/hgdriver/ImageProcess/ImageApplyBWBinaray.cpp index 1c29d94..b3637f5 100644 --- a/hgdriver/ImageProcess/ImageApplyBWBinaray.cpp +++ b/hgdriver/ImageProcess/ImageApplyBWBinaray.cpp @@ -1,5 +1,7 @@ #include "ImageApplyBWBinaray.h" +#define THRESHOLD_LOW 30 +#define THRESHOLD_UP 245 CImageApplyBWBinaray::CImageApplyBWBinaray(ThresholdType type, int threshold, int blockSize, int constant) : m_threshold(threshold) , m_type(type) @@ -27,8 +29,6 @@ CImageApplyBWBinaray::~CImageApplyBWBinaray(void) delete[] m_table; } -#define THRESHOLD_LOW 30 -#define THRESHOLD_UP 245 void CImageApplyBWBinaray::apply(cv::Mat& pDib, int side) { (void)side; @@ -40,7 +40,7 @@ void CImageApplyBWBinaray::apply(cv::Mat& pDib, int side) cv::Mat integ; int blockSize = m_blockSize;//邻域尺寸 int threshold = m_constant; - int low = THRESHOLD_LOW; + int low = m_threshold; int up = THRESHOLD_UP; int halfSize = blockSize / 2; int square_blockSize = blockSize * blockSize; @@ -71,13 +71,13 @@ void CImageApplyBWBinaray::apply(cv::Mat& pDib, int side) cv::threshold(pDib(cv::Rect(0, pDib.rows - halfSize, pDib.cols, halfSize)), pDib(cv::Rect(0, pDib.rows - halfSize, pDib.cols, halfSize)), m_threshold, 255, cv::THRESH_BINARY); break; case ThresholdType::THRESH_OTSU: - cv::threshold(pDib, pDib, m_threshold, 255, CV_THRESH_OTSU); + cv::threshold(pDib, pDib, m_threshold, 255, cv::THRESH_OTSU); break; case ThresholdType::ADAPTIVE_GAUSSIAN: - cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, m_blockSize, m_constant); + cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, m_blockSize, m_constant); break; case ThresholdType::ADAPTIVE_MEAN: - cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, m_blockSize, m_constant); + cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, m_blockSize, m_constant); break; case ThresholdType::ERROR_DIFFUSION: errorDiffuse(pDib); @@ -108,7 +108,7 @@ void CImageApplyBWBinaray::errorDiffuse(cv::Mat& image) { if (image.rows < 3 || image.cols < 3) { - cv::threshold(image, image, m_threshold, 255, CV_THRESH_BINARY); + cv::threshold(image, image, m_threshold, 255, cv::THRESH_BINARY); return; } diff --git a/hgdriver/ImageProcess/ImageApplyBWBinaray.h b/hgdriver/ImageProcess/ImageApplyBWBinaray.h index 56bb0bc..99a2c6b 100644 --- a/hgdriver/ImageProcess/ImageApplyBWBinaray.h +++ b/hgdriver/ImageProcess/ImageApplyBWBinaray.h @@ -10,7 +10,8 @@ 2020/12/21 v1.3.1 调整自适应阈值上下限 2020/12/21 v1.3.2 调整blockSize,从原来的51调整到25 2022/05/25 v1.3.3 调整blockSize和constant,对THRESH_BINARY同样有效 - * 版本号:v1.3.3 + 2023/11/22 v1.4 当THRESH_BINARY模式时,参数m_threshold作为THRESHOLD_LOW使用。 + * 版本号:v1.4 * ==================================================== */ diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 73fe831..5b3de60 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -5372,7 +5372,7 @@ void hg_scanner::image_process(std::shared_ptr& buffer, uint32_t id if ((img_conf_.pixtype == COLOR_MODE_BLACK_WHITE) && (pid_ != 0x239 && pid_ != 0x439)) { - hg_imgproc::errorextention(ImagePrc_pHandle_); + hg_imgproc::errorextention(ImagePrc_pHandle_, bw_threshold_); (this->*dump_img_)(ImagePrc_pHandle_, "errorextention"); } diff --git a/hgdriver/hgdev/image_process.cpp b/hgdriver/hgdev/image_process.cpp index c1560a8..728f7f4 100644 --- a/hgdriver/hgdev/image_process.cpp +++ b/hgdriver/hgdev/image_process.cpp @@ -1124,7 +1124,7 @@ namespace hg_imgproc return SCANNER_ERR_OK; } - int errorextention() + int errorextention(int bw_threshold) { int ret = SCANNER_ERR_OK; std::vector mats(mats_); @@ -1136,7 +1136,7 @@ namespace hg_imgproc else thrtype = CImageApplyBWBinaray::ThresholdType::THRESH_BINARY; - CImageApplyBWBinaray BWBinaray(thrtype); + CImageApplyBWBinaray BWBinaray(thrtype, bw_threshold); for (size_t i = 0; i < mats.size(); ++i) { BWBinaray.apply(mats[i],img_conf_.is_duplex); @@ -2025,9 +2025,9 @@ namespace hg_imgproc { return ((imgproc*)himg)->nosieDetach(); } - int errorextention(HIMGPRC himg) + int errorextention(HIMGPRC himg, int bw_threshold) { - return ((imgproc*)himg)->errorextention(); + return ((imgproc*)himg)->errorextention(bw_threshold); } int discardBlank(HIMGPRC himg) { diff --git a/hgdriver/hgdev/image_process.h b/hgdriver/hgdev/image_process.h index c4bcb41..47dbfec 100644 --- a/hgdriver/hgdev/image_process.h +++ b/hgdriver/hgdev/image_process.h @@ -196,7 +196,7 @@ namespace hg_imgproc int remove_morr(HIMGPRC himg); int sharpenType(HIMGPRC himg); int nosieDetach(HIMGPRC himg); - int errorextention(HIMGPRC himg); + int errorextention(HIMGPRC himg, int bw_threshold); int discardBlank(HIMGPRC himg); int answerSheetFilterRed(HIMGPRC himg); int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector &bmpdata);