diff --git a/hgdriver/ImageProcess/ImageMulti.cpp b/hgdriver/ImageProcess/ImageMulti.cpp index 4c8761b..c36b53a 100644 --- a/hgdriver/ImageProcess/ImageMulti.cpp +++ b/hgdriver/ImageProcess/ImageMulti.cpp @@ -1,9 +1,10 @@ #include "ImageMulti.h" -IMageMulti::IMageMulti(int multiType,int thre) +IMageMulti::IMageMulti(int multiType, int thre, short thresholdType, int blockSize, int constant) + : m_multiType(multiType) + , m_BWBinaray((CImageApplyBWBinaray::ThresholdType)thresholdType, thre, blockSize, constant) { - m_multiType = multiType; - m_thre = thre; + } IMageMulti::~IMageMulti(void) @@ -27,8 +28,7 @@ std::vector IMageMulti::apply(cv::Mat& pDib) } cv::Mat dstThre; cv::cvtColor(pDib, dstThre,cv::COLOR_BGR2GRAY); - //cv::threshold(dstThre, dstThre, m_thre, 255, cv::THRESH_BINARY); - cv::adaptiveThreshold(dstThre,dstThre,255,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,25,5); + m_BWBinaray.apply(dstThre, 0); if (!dstThre.empty()) { retMats.push_back(dstThre); @@ -49,20 +49,17 @@ std::vector IMageMulti::apply(cv::Mat& pDib) if (pDib.channels() == 3) { cv::Mat dstGray; cv::cvtColor(pDib, dstGray, cv::COLOR_BGR2GRAY); - cv::Mat dstBW; - cv::adaptiveThreshold(dstGray,dstBW,255,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,25,5); - retMats.push_back(dstBW); + m_BWBinaray.apply(dstGray, 0); + retMats.push_back(dstGray); } } break; case GRAYBW://pDib should be GreyImage(channels() == 1) { - cv::Mat dstBW; - cv::adaptiveThreshold(pDib,dstBW,255,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,25,5); + cv::Mat dstBW = pDib.clone(); + m_BWBinaray.apply(dstBW, 0); if (!dstBW.empty()) - { retMats.push_back(dstBW); - } } break; default: diff --git a/hgdriver/ImageProcess/ImageMulti.h b/hgdriver/ImageProcess/ImageMulti.h index ae290ae..5589a7e 100644 --- a/hgdriver/ImageProcess/ImageMulti.h +++ b/hgdriver/ImageProcess/ImageMulti.h @@ -1,6 +1,19 @@ +/* + * ==================================================== + + * 功能:多流输出。 + * 作者:刘丁维 + * 生成时间:2022/11/18 + * 最近修改时间:2022/11/18 v1.0 替换二值化方案,改用CImageApplyBWBinaray进行二值化操作。 + * 版本号:v1.0 + + * ==================================================== + */ + #ifndef IMAGE_MULTI_H #define IMAGE_MULTI_H #include "IMulti.h" +#include "ImageApplyBWBinaray.h" class GIMGPROC_LIBRARY_API IMageMulti :public IMulti @@ -15,12 +28,23 @@ public: GRAYBW }; public: - IMageMulti(int multiType = 0,int thre = 128); + /// + /// 构造函数 + /// + /// 多流输出类型。详情见enum MultiOutput + /// 二值化阈值CImageApplyBWBinaray::threshold + /// 二值化方式。详情见CImageApplyBWBinaray::ThresholdType + /// 二值化blockSize。详情见CImageApplyBWBinaray::blockSize + /// 二值化constant。详情见CImageApplyBWBinaray::constant + IMageMulti(int multiType = 0, int thre = 40, short thresholdType = 0, int blockSize = 51, int constant = 41); + virtual ~IMageMulti(void); + virtual std::vector apply(cv::Mat& pDib); private: int m_multiType; - int m_thre; + + CImageApplyBWBinaray m_BWBinaray; }; #endif // !IMAGE_MULTI_H \ No newline at end of file diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index a9aaebc..3813b05 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -1572,12 +1572,12 @@ int hg_scanner::setting_resolution(void* data) // check paper ... if (!check_paper_and_resolution(resolution_, image_prc_param_.bits.paper)) { - resolution_ = old; - *((int*)data) = old; + //resolution_ = old; + //*((int*)data) = old; return SCANNER_ERR_DEVICE_NOT_SUPPORT; } - if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str())) + /*if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str())) { if (resolution_ == 600 && old < 300) { @@ -1595,7 +1595,7 @@ int hg_scanner::setting_resolution(void* data) return SCANNER_ERR_DEVICE_NOT_SUPPORT; } - } + }*/ sub = on_resolution_changed(resolution_); if (sub == SCANNER_ERR_NOT_EXACT) @@ -1604,7 +1604,7 @@ int hg_scanner::setting_resolution(void* data) ret = sub; VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Change resolution from %d to %d = %s\n", old, *((int*)data), hg_scanner_err_name(ret)); - *((int*)data) = resolution_; + //*((int*)data) = resolution_; return ret; } @@ -2028,13 +2028,13 @@ int hg_scanner::setting_img_quality(void* data) , (char*)data, hg_scanner_err_name(ret)); is_quality_ = match_best_img_quality(str,NULL); - if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str())) + /*if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str())) { is_quality_ = old; strcpy((char*)data, is_img_quality(is_quality_).c_str()); return SCANNER_ERR_DEVICE_NOT_SUPPORT; - } + }*/ return SCANNER_ERR_OK; } diff --git a/hgdriver/hgdev/hg_scanner_200.cpp b/hgdriver/hgdev/hg_scanner_200.cpp index 26f9ef4..8af704e 100644 --- a/hgdriver/hgdev/hg_scanner_200.cpp +++ b/hgdriver/hgdev/hg_scanner_200.cpp @@ -746,7 +746,6 @@ else else if ((image_prc_param_.bits.multi_out == MULTI_OUT_ALL ||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_GRAY||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_BW) && is_multiout) { ic.pixtype = 2; - } if (is_multiout) { diff --git a/hgdriver/hgdev/hg_scanner_239.cpp b/hgdriver/hgdev/hg_scanner_239.cpp index 6b60bef..9626ab5 100644 --- a/hgdriver/hgdev/hg_scanner_239.cpp +++ b/hgdriver/hgdev/hg_scanner_239.cpp @@ -500,9 +500,71 @@ int hg_scanner_239::writedown_image_configuration(void) ic.isuoloadexceptionimage = (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) == DOUBLE_PAPER_SAVE_IMG; adjust_filling_hole(&ic); ic.fold_concatmode = fold_type_; +//澶氭祦杈撳嚭浼樺厛绾ф渶楂 + if (is_multiout) + { + ic.pixtype = image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW ? COLOR_MODE_256_GRAY : COLOR_MODE_24_BITS; + ic.filter = 3; + ic.hsvcorrect = 0; + ic.multi_output_red = 0; + ic.fadeback = false; + ic.sharpen = 0; + ic.removeMorr = 0; + ic.textureRemove = 0; + ic.errorExtention = 0; + ic.detachnoise.is_detachnoise = 0; + } + else if(image_prc_param_.bits.multi_out == COLOR_MODE_24_BITS) + { + ic.filter = 3; + ic.errorExtention = 0; + ic.detachnoise.is_detachnoise = 0; + } + else if (image_prc_param_.bits.multi_out == COLOR_MODE_256_GRAY) + { + int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 }; + ic.filter = filter_clr[image_prc_param_.bits.rid_color]; + ic.multi_output_red = 0; + ic.hsvcorrect = 0; + ic.fadeback = false; + ic.errorExtention = 0; + ic.detachnoise.is_detachnoise = 0; + } + else if (image_prc_param_.bits.multi_out == COLOR_MODE_BLACK_WHITE) + { + int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 }; + ic.filter = filter_clr[image_prc_param_.bits.rid_color]; + ic.multi_output_red = 0; + ic.hsvcorrect = 0; + ic.fadeback = false; + ic.sharpen = 0; + ic.removeMorr = 0; + ic.textureRemove = 0; + } + else if (image_prc_param_.bits.multi_out == COLOR_MODE_AUTO_MATCH) + { + ic.pixtype = 2; + ic.filter = 3; + ic.hsvcorrect = 0; + ic.multi_output_red = 0; + ic.fadeback = false; + ic.sharpen = 0; + ic.removeMorr = 0; + ic.textureRemove = 0; + ic.errorExtention = 0; + ic.detachnoise.is_detachnoise = 0; - int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 }; - if(image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH) + } + + + + /*if (ic.filter != 3 && (image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE || image_prc_param_.bits.color_mode != COLOR_MODE_256_GRAY)) + { + ic.hsvcorrect = 0; + ic.multi_output_red = 0; + ic.multiOutput = MultiOutput::Unused; + } + if (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH) ic.filter = 3; else { @@ -523,20 +585,8 @@ int hg_scanner_239::writedown_image_configuration(void) else if ((image_prc_param_.bits.multi_out == MULTI_OUT_ALL ||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_GRAY||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_BW) && is_multiout) { ic.pixtype = 2; - } - if (is_multiout) - { - ic.hsvcorrect = 0; - ic.multi_output_red = 0; - ic.fadeback = false; - ic.sharpen = 0; - ic.removeMorr = 0; - ic.textureRemove = 0; - ic.errorExtention = 0; - ic.detachnoise.is_detachnoise = 0; - } if (ic.pixtype == 0) { ic.hsvcorrect = 0; @@ -545,7 +595,7 @@ int hg_scanner_239::writedown_image_configuration(void) ic.sharpen = 0; ic.removeMorr = 0; ic.textureRemove = 0; - } + }*/ //鑷畾涔夎鍒 if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH @@ -1272,7 +1322,7 @@ void hg_scanner_239::thread_handle_usb_read(void) if (status_ == SCANNER_ERR_DEVICE_STOPPED) { SANE_Bool b = false; - status_ = ret = get_scanner_paperon(&b); + //status_ = ret = get_scanner_paperon(&b); } VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_name(status_)); } diff --git a/hgdriver/hgdev/image_process.cpp b/hgdriver/hgdev/image_process.cpp index 9eb9ac4..e4d65e2 100644 --- a/hgdriver/hgdev/image_process.cpp +++ b/hgdriver/hgdev/image_process.cpp @@ -287,7 +287,7 @@ namespace hg_imgproc } ~imgproc() { - free_auto_txt_hanld(); + //free_auto_txt_hanld(); } // load data