From 16bd0223c0fdfc6362f98fbd0ea8ff735e4440a5 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Mon, 16 Oct 2023 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=99=A4=E6=91=A9=E5=B0=94?= =?UTF-8?q?=E7=BA=B9=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/common_setting.h | 2 ++ hgdriver/hgdev/hg_scanner.cpp | 2 +- hgdriver/hgdev/hg_scanner_300.cpp | 46 +++++++++++++++++++++------ hgdriver/hgdev/hg_scanner_300.h | 1 + hgdriver/hgdev/image_process.cpp | 53 ++++++++++++++++++++----------- 5 files changed, 74 insertions(+), 30 deletions(-) diff --git a/hgdriver/hgdev/common_setting.h b/hgdriver/hgdev/common_setting.h index 82b7d59..96b75dd 100644 --- a/hgdriver/hgdev/common_setting.h +++ b/hgdriver/hgdev/common_setting.h @@ -723,6 +723,8 @@ namespace setting3288dsp { FLAT_INFO info; cv::Mat flat_lut; + float vratio; + float hratio; }; struct HG_JpegCompressInfo diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 0d8eedf..0a8644b 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -5048,7 +5048,7 @@ void hg_scanner::image_process(std::shared_ptr& buffer, uint32_t id (this->*dump_img_)(ImagePrc_pHandle_, "textureRemove"); } - if (img_conf_.removeMorr && (pid_ != 0x239 && pid_ != 0x439) && !firmware_sup_morr_) + if (img_conf_.removeMorr && (pid_ != 0x239 && pid_ != 0x439 && pid_ != 0x300) && !firmware_sup_morr_) { hg_imgproc::remove_morr(ImagePrc_pHandle_); (this->*dump_img_)(ImagePrc_pHandle_, "remove_morr"); diff --git a/hgdriver/hgdev/hg_scanner_300.cpp b/hgdriver/hgdev/hg_scanner_300.cpp index 496540d..3d76218 100644 --- a/hgdriver/hgdev/hg_scanner_300.cpp +++ b/hgdriver/hgdev/hg_scanner_300.cpp @@ -99,6 +99,7 @@ hg_scanner_300::hg_scanner_300(const char* dev_name,int pid, usb_io* io) : get_correction_image(3, 2, 0); get_correction_image(4, 3, 1); get_correction_image(5, 3, 0); + firmware_sup_morr_ = true; } else { @@ -948,6 +949,30 @@ int hg_scanner_300::get_device_type(bool &type) return ret; } +int hg_scanner_300::get_devs_distortion_check_val(float& data, int dpi, int dir) +{ + int ret = SCANNER_ERR_OK; + USBCB usbcb = { dir ? setting3288dsp::GET_JUST_COF_V : setting3288dsp::GET_JUST_COF_H ,0,dpi }; + int len = sizeof(usbcb); + { + ret = io_->write_bulk(&usbcb, &len); + if (ret != SCANNER_ERR_OK) + { + return ret; + } + + io_->set_timeout(3000); + ret = io_->read_bulk(&usbcb, &len); + } + if (ret != SCANNER_ERR_OK) + { + return ret; + } + + int val = usbcb.u32_Data; + data = *(float*)&val; +} + int hg_scanner_300::get_correction_image(int inx , int dpi, int mode) { for (auto it : correction_image_map_) @@ -1009,11 +1034,22 @@ int hg_scanner_300::get_correction_image(int inx , int dpi, int mode) VLOG_MINI_1(LOG_LEVEL_WARNING, "get_correction_image image is NULL:%d\n", image_info.info.params.status); return SCANNER_ERR_NO_DATA; //只要有一张图没有 直接退了 } + float f = 0.0; + + get_devs_distortion_check_val(f, dpi, i); if (i) + { + image_info.vratio = f; white_mat = mat; + } + else + { + image_info.hratio = f; black_mat = mat; + } + } } //cv::imwrite("C://image//correction_image_white_mat" + to_string(inx) + ".bmp", white_mat); @@ -1021,16 +1057,6 @@ int hg_scanner_300::get_correction_image(int inx , int dpi, int mode) ret = hg_imgproc::correction_image(ImagePrc_pHandle_, image_info.flat_lut, black_mat, white_mat); - - //cv::imwrite("C://image//correction_image_black_mat" + to_string(inx) + ".bmp", black_mat); - //for (size_t j = 0; j < correction_image_map_.size(); j++) //以防重复添加 - //{ - // if (correction_image_map_[j].info.params.dpi == dpi - // && correction_image_map_[j].info.params.colormode == mode) - // { - // return ret; - // } - //} correction_image_map_[inx] = image_info; return ret; diff --git a/hgdriver/hgdev/hg_scanner_300.h b/hgdriver/hgdev/hg_scanner_300.h index 3c7b02e..5b879a9 100644 --- a/hgdriver/hgdev/hg_scanner_300.h +++ b/hgdriver/hgdev/hg_scanner_300.h @@ -66,6 +66,7 @@ private: void writedown_image_configuration(void); void printf_devconfig(setting_hardware::HGSCANCONF_3288 *d = NULL); int get_device_type(bool &type); + int get_devs_distortion_check_val(float& data, int dpi, int dir);//获取设备畸变值 DPI=1、2、3; dir = 0,1; setting3288dsp::HG_JpegCompressInfo frame_info_; ///////////////////////7010专有协议,获取校正数据////////////////////// diff --git a/hgdriver/hgdev/image_process.cpp b/hgdriver/hgdev/image_process.cpp index b9ef163..9ed38a6 100644 --- a/hgdriver/hgdev/image_process.cpp +++ b/hgdriver/hgdev/image_process.cpp @@ -521,40 +521,55 @@ namespace hg_imgproc else mat = m_dst.clone(); - cv::imwrite("C:\\image\\imdecode" + std::to_string(img_idx++) + ".jpg", mat); + float vratio = 0.0; + float hratio = 0.0; + //cv::imwrite("C:\\image\\imdecode" + std::to_string(img_idx++) + ".jpg", mat); int dpi = param_.dpi == 600 ? 3 : (param_.dpi < 599 && param_.dpi >= 300) ? 2 : 1; int mode = param_.color_mode == COLOR_MODE_24_BITS ? 1 : 0; for (auto it : correction_image_map_) { + if (img_conf_.removeMorr && param_.dpi != 600) //除摩尔纹 使用300dpi校正数据 + { + if (it.second.info.params.dpi == 2) + { + if (it.second.info.params.status != 100) + break; + vratio = it.second.vratio; + hratio = it.second.hratio; + correctColor(mat, it.second.flat_lut); + break; + } + continue; + + + } + if (it.second.info.params.colormode == mode && it.second.info.params.dpi == dpi) { if (it.second.info.params.status != 100) { break; } + vratio = it.second.vratio; + hratio = it.second.hratio; correctColor(mat, it.second.flat_lut);//校正 + break; } - } - //for (size_t i = 0; i < correction_image_map_.size(); i++) - //{ - // if (correction_image_map_[i].info.params.colormode == mode && correction_image_map_[i].info.params.dpi == dpi) - // { - // if (correction_image_map_[i].info.params.status != 100) - // { - // continue; - // } - // correctColor(mat, correction_image_map_[i].flat_lut);//校正 - // } - //} - //cv::imwrite("C:\\image\\imdecode" + std::to_string(img_idx++) + ".jpg", mat); - //if (param_.dpi < 299)/////7010不支持 200dpi 所以需要手动拉伸宽度 - //{ - // float xy = param_.dpi / 300.0; - // cv::resize(mat, mat, cv::Size(), xy, 1); + if (!(vratio >= 0.8f && vratio <= 1.20f && hratio > 0.8f && hratio < 1.2f)) + vratio = hratio = 1.0f; - //} + if (dpi == 1 && img_conf_.removeMorr) + hratio = (200.0 / 300.0) * hratio; + + if (img_conf_.removeMorr && dpi != 3) + vratio = dpi == 1 ? vratio * 0.5186 : vratio * 0.7787; + + if (img_conf_.removeMorr) + resize(mat, mat, cv::Size(0, 0), hratio, vratio, cv::InterpolationFlags::INTER_AREA); + else + resize(mat, mat, cv::Size(0, 0), hratio, vratio); } //cv::imwrite("C:\\image\\imdecode4.png", mat);