From a3af24ceab2e71acee853a36cc825ab4373fde8d Mon Sep 17 00:00:00 2001 From: lovelyyoung <1002639516@qq.com> Date: Sat, 20 Jun 2020 11:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE=E7=B1=BB?= =?UTF-8?q?=E4=BB=A5=E9=80=82=E5=BA=94=E6=96=B0=E7=9A=84GScanCap=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/Device/G400ScanConfig.cpp | 13 ++++++-- huagao/Device/G400ScanConfig.h | 6 +++- huagao/Device/GDevice.cpp | 4 +-- huagao/Device/IConfig.h | 14 ++++----- huagao/Device/ImageMatQueue.cpp | 51 ++++++++++++++++++++++---------- huagao/Device/ImageMatQueue.h | 4 +-- huagao/Device/JsonConfig.cpp | 14 +++++++-- huagao/Device/PublicFunc.cpp | 2 ++ huagao/Device/PublicFunc.h | 14 +++++++-- huagao/Device/filetools.h | 8 ++--- huagao/Device/scn_config.cpp | 21 +++++++------ 11 files changed, 102 insertions(+), 49 deletions(-) diff --git a/huagao/Device/G400ScanConfig.cpp b/huagao/Device/G400ScanConfig.cpp index ee1dfd7c..d1a7f653 100644 --- a/huagao/Device/G400ScanConfig.cpp +++ b/huagao/Device/G400ScanConfig.cpp @@ -3,16 +3,23 @@ G400ScanConfig::G400ScanConfig(GScanCap& gcap) { cfg.params.doubleFeeded = gcap.hardwarecaps.en_doublefeed == 0 ? 0 : 1; - cfg.params.dpi = gcap.resolution_dst <= 200.0f ? G400_DPI::G400_D200 : (gcap.resolution_dst <= 300.0f ? G400_DPI::G400_D300 : G400_DPI::G400_D600); + cfg.params.dpi = G400_DPI::G400_D200;//gcap.resolution_dst <= 200.0f ? G400_DPI::G400_D200 : (gcap.resolution_dst <= 300.0f ? G400_DPI::G400_D300 : G400_DPI::G400_D600); cfg.params.enableLed = 1; if (gcap.filter != 3 || gcap.enhance_color) cfg.params.isColor = 1; else cfg.params.isColor = SupPixelTypes[gcap.pixtype]; - cfg.params.enableStable = gcap.hardwarecaps.en_stapledetect==0?0:1; - cfg.params.isCorrect = 1; + cfg.params.enableStable = 0;//gcap.hardwarecaps.en_stapledetect==0?0:1; + cfg.params.isCorrect = 1;//1 机器校正 PaperStatus ps = { gcap.papertype,gcap.paperAlign }; cfg.params.pageSize = SupPaperTyps[ps]; + CSize size; +#ifdef G300 + size = PaperSize.GetPaperSize(TwSS::A4, 200.0f, gcap.paperAlign);//G300 最大支持A4幅面 +#else + size = PaperSize.GetPaperSize(gcap.papertype, 200.0f, gcap.paperAlign); +#endif// G300 + cfg.params.dstHeight = (int)((size.cy+200)/100); cfg.params.reversed1 = cfg.params.reversed2 = 0; } diff --git a/huagao/Device/G400ScanConfig.h b/huagao/Device/G400ScanConfig.h index bb19212b..ac10b8fb 100644 --- a/huagao/Device/G400ScanConfig.h +++ b/huagao/Device/G400ScanConfig.h @@ -1,6 +1,8 @@ #pragma once #include "Device/IConfig.h" #include "Device/PublicFunc.h" +#include "Device/PaperSize.h" + class G400ScanConfig : public IConfig { @@ -17,7 +19,8 @@ public: unsigned int enableLed : 1; unsigned int reversed1 : 6; unsigned int isCorrect : 1; - unsigned int reversed2 : 14; + unsigned int dstHeight : 8; + unsigned int reversed2 : 6; }params; unsigned int value; }; @@ -26,5 +29,6 @@ public: virtual unsigned int GetData() override; private: Configuration cfg; + Device::PaperSize PaperSize; }; diff --git a/huagao/Device/GDevice.cpp b/huagao/Device/GDevice.cpp index 3f89f10f..2b6e2e0b 100644 --- a/huagao/Device/GDevice.cpp +++ b/huagao/Device/GDevice.cpp @@ -351,7 +351,7 @@ void GDevice::Int_main() { //0x3fe ==>b 1111 1111 10 异常位高有效时 if (ms->value & 0x3fe) { - ((GScan200*)m_eventcall_userdata)->set_scan_status(false); + //((GScan200*)m_eventcall_userdata)->set_scan_status(false); event_call(ms->value, m_eventcall_userdata); m_run = false; } @@ -360,7 +360,7 @@ void GDevice::Int_main() int ret = get_option(Cam_Options::scanner_scan_status); if (m_run&&!ret)//电机板工作中 { - ((GScan200*)m_eventcall_userdata)->set_scan_status(false);//停止或异常停止时,通知图像处理线程扫描仪已停止 + //((GScan200*)m_eventcall_userdata)->set_scan_status(false);//停止或异常停止时,通知图像处理线程扫描仪已停止 m_run = false; } } diff --git a/huagao/Device/IConfig.h b/huagao/Device/IConfig.h index 386abaf0..db1ede24 100644 --- a/huagao/Device/IConfig.h +++ b/huagao/Device/IConfig.h @@ -27,7 +27,7 @@ static std::map SupPaperTyps = { {{TwSS::USStatement,PaperAlign::Rot0},16}, {{TwSS::MaxSize,PaperAlign::Rot0},16} #else - { {TwSS::A3,PaperAlign::Rot0},G400_A3}, + {{TwSS::A3,PaperAlign::Rot0},G400_A3}, {{TwSS::A4,PaperAlign::Rot0},G400_A4}, {{TwSS::A4,PaperAlign::Rot270},G400_A4R}, {{TwSS::A5,PaperAlign::Rot0 },G400_A5}, @@ -43,6 +43,11 @@ static std::map SupPaperTyps = { {{TwSS::USLetter,PaperAlign::Rot270},G400_LETTERR}, {{TwSS::USLedger,PaperAlign::Rot0},G400_DOUBLELETTER}, {{TwSS::USLegal,PaperAlign::Rot0},G400_LEGAL}, +#ifdef G300 + {{TwSS::None,PaperAlign::Rot0},G400_A4}, +#else // G300 + {{TwSS::None,PaperAlign::Rot0},G400_A3}, +#endif {{TwSS::MaxSize,PaperAlign::Rot0},G400_LONGLETTER}, #endif }; @@ -80,16 +85,9 @@ typedef union Config_Param { unsigned int stable_enbale : 1; unsigned int screw_detect_enable : 1; unsigned int screw_detect_level : 3;//第十四位 -#ifdef G200 - unsigned int unused_one : 6; unsigned int pc_correct : 1; unsigned int unused_two : 11; -#else // G200 - unsigned int unused_one : 3; - unsigned int correct_enable : 1; - unsigned int unused_two : 14; -#endif }; } ConfigParam; diff --git a/huagao/Device/ImageMatQueue.cpp b/huagao/Device/ImageMatQueue.cpp index 28ac6669..a2b3dcc8 100644 --- a/huagao/Device/ImageMatQueue.cpp +++ b/huagao/Device/ImageMatQueue.cpp @@ -75,8 +75,8 @@ float ImageMatQueue::getdpi() void ImageMatQueue::updatefixratio(float& hratio, float& vratio) { if (hratio > 0.80f && hratio < 1.2f && vratio >0.80f && vratio < 1.2f) { - fx = hratio; - fy = vratio; + this->fx = hratio; + this->fy = vratio; } else { @@ -123,8 +123,19 @@ void ImageMatQueue::clear() void ImageMatQueue::setparam(const GScanCap& param) { scanParam = param; - m_iaList.clear(); + scanParam.is_duplex = 0; + scanParam.imageRotateDegree = 90.0f; +#ifdef DEBUG + string outinfo = "autodescrew : " + to_string(scanParam.autodescrew) + "\n brightness : " + to_string(scanParam.brightness) + "\n contrast " + to_string(scanParam.contrast) + "\n enhance_color : " + to_string(scanParam.enhance_color) + "\n en_fold: " + to_string(scanParam.en_fold) + + "\n fillbackground : " + to_string(scanParam.fillbackground) + "\n is_fillhole : " + to_string(scanParam.fillhole.is_fillhole) + "\n fillholeratio : " + to_string(scanParam.fillhole.fillholeratio) + "\n filter : " + to_string(scanParam.filter) + "\n gamma : " + to_string(scanParam.gamma) + + "\n imageRotateDegree : " + to_string(scanParam.imageRotateDegree) + "\n is_autocrop : " + to_string(scanParam.is_autocrop) + "\n is_autodiscradblank_normal : " + to_string(scanParam.is_autodiscradblank_normal) + "\n is_autodiscradblank_vince : " + to_string(scanParam.is_autodiscradblank_vince) + + "\n is_autotext : " + to_string(scanParam.is_autotext) + "\n is_backrotate180 : " + to_string(scanParam.is_backrotate180) + "\n is_duplex : " + to_string(scanParam.is_duplex) + "\n is_switchfrontback : " + to_string(scanParam.is_switchfrontback) + "\n multi_output_red : " + to_string(scanParam.multi_output_red) + + "\n paperAlign : " + to_string(scanParam.paperAlign) + "\n papertype : " + to_string(scanParam.papertype) + "\n resolution_dst : " + to_string(scanParam.resolution_dst) + "\n scannum : " + to_string(scanParam.scannum) + "\n sharpen : " + to_string(scanParam.sharpen)+ + "Pixtype : "+to_string(scanParam.pixtype); + FileTools::write_log("2.txt", outinfo); +#endif // DEBUG + m_iaList.clear(); if (scanParam.fillhole.is_fillhole) { float ratio = scanParam.fillhole.fillholeratio / 100.0; m_iaList.push_back(shared_ptr(new CImageOutHole(200, ratio, 50))); @@ -148,8 +159,6 @@ void ImageMatQueue::setparam(const GScanCap& param) m_iaList.push_back(shared_ptr(new CImageApplyDiscardBlank(param.is_autodiscradblank_normal ? true : false))); //m_iaList.push_back(shared_ptr(new CImageApplyDiscardBlank(param.areanum,param.devnmax))); } - //if (param.pixtype != 0) //sharpen - // m_iaList.push_back(shared_ptr(new CImageApplySharpen())); //filter 0 r 1 g 2 b 3 none enhance color 0 none 1 r 2 g 3 b if (param.filter != 3 || param.enhance_color) { @@ -182,7 +191,7 @@ void ImageMatQueue::setparam(const GScanCap& param) if (param.papertype == TwSS::USStatement) islongcustomcrop = true; if (param.is_autocrop || islongcustomcrop) { - double ratio = param.resolution_dst / param.resolution_native; + double ratio = param.resolution_dst / 200.0;// apply = new CImageApplyResize(CImageApplyResize::ResizeType::RATIO, cv::Size(0, 0), ratio, ratio); } else { @@ -223,11 +232,6 @@ void ImageMatQueue::setparam(const GScanCap& param) } } -void ImageMatQueue::EnqueueBmpBuffer(std::vector& bmpdata) -{ - //std::lock_guard lock(m_Locker); - //m_imagedata.Put(bmpdata); -} void ImageMatQueue::EnqueueBmpBuffer(std::shared_ptr> bmpdata) { m_imagedata.Put(bmpdata); @@ -242,6 +246,11 @@ bool ImageMatQueue::empty() return atm_orgin_image_remains == 0 && m_imagedata.Size() == 0 && !is_scanning; } +bool ImageMatQueue::queuesempty() +{ + return atm_orgin_image_remains == 0 && m_imagedata.Size() == 0; +} + static int index = 0; void ImageMatQueue::proc() { @@ -259,7 +268,6 @@ void ImageMatQueue::proc() auto buffs = m_rawBuffs.Take()->getImageBuffs(); if (!m_rawBuffs.IsShutDown() && !buffs.empty()) { vector mats; - int k = 0; for (auto& buf : buffs) { ImreadModes rm; @@ -269,7 +277,10 @@ void ImageMatQueue::proc() rm = scanParam.pixtype == 2 ? IMREAD_COLOR : IMREAD_GRAYSCALE; try { + //StopWatch sw; cv::Mat mat = cv::imdecode(*buf, rm); + //double epl= sw.elapsed_ms(); + //FileTools::write_log("1.txt", to_string(epl)+" img index"+to_string(++index)); buf.reset(); if (mat.empty()) { writelog("decode image data error"); @@ -280,8 +291,13 @@ void ImageMatQueue::proc() mat.release(); #else // G200 //resize(mat, mat, cv::Size(), 1.001, 1.0070);//用于修正与佳能机器幅面大小不匹配问题 此系数请勿轻易动 + //cv::imwrite("D:\\org"+to_string(index)+".jpg", mat); Mat front = mat(Rect(0, 0, mat.cols / 2, mat.rows)); Mat back = mat(Rect(mat.cols / 2, 0, mat.cols / 2, mat.rows)); + if (scanParam.imageRotateDegree != 0.0&&scanParam.imageRotateDegree!=180.0) { + cv::flip(front, front, 0); + cv::flip(front, front, 1); + } mats.push_back(front); mats.push_back(back); #endif @@ -294,10 +310,16 @@ void ImageMatQueue::proc() } buffs.clear(); + if (scanParam.is_switchfrontback) + swap(mats[0], mats[1]); + //StopWatch sw; for (int j = 0; j < m_iaList.size(); j++) { m_iaList[j]->apply(mats, scanParam.is_duplex); + //FileTools::write_log("E:\\Users\\huago\\Desktop\\3.txt", "image proc "+std::to_string(j)+" time eplsed: " + std::to_string(sw.elapsed_ms())); + //sw.reset(); } - + //FileTools::write_log("E:\\Users\\huago\\Desktop\\2.txt", "image proc time eplsed: " + std::to_string(sw.elapsed_ms())); + for (int i = 0; i < mats.size(); i++) { if (!scanParam.is_duplex && i == 1) { mats[i].release(); @@ -307,7 +329,6 @@ void ImageMatQueue::proc() IMat2Bmp idata; idata = scanParam.pixtype == 0 ? (IMat2Bmp)Mat2BmpBw(mats[i], scanParam.resolution_dst) : Mat2Bmp(mats[i], scanParam.resolution_dst); auto data = idata.getBmpDataBuffer(); - //mats[i].release(); EnqueueBmpBuffer(data); } else @@ -315,7 +336,7 @@ void ImageMatQueue::proc() writelog("enqueue image is empty " + std::to_string(index++)); } } - + //FileTools::write_log("E:\\Users\\huago\\Desktop\\2.txt", "image output time eplsed: " + std::to_string(sw.elapsed_ms())); if (scanParam.multi_output_red) { for (int i = 0; i < mats.size(); i++) { if (!mats[i].empty()) { diff --git a/huagao/Device/ImageMatQueue.h b/huagao/Device/ImageMatQueue.h index daf3a929..3d975505 100644 --- a/huagao/Device/ImageMatQueue.h +++ b/huagao/Device/ImageMatQueue.h @@ -7,7 +7,7 @@ #include "BlockingQueue.h" #include #include "PaperSize.h" - +#include "filetools.h" class IMat2Bmp { public: @@ -156,6 +156,7 @@ public: void pushMat(std::shared_ptr buf); std::shared_ptr> popBmpdata(); bool empty(); + bool queuesempty(); bool valid(); void clear(); void setparam(const GScanCap& param); @@ -166,7 +167,6 @@ public: void updatefixratio(float& hratio, float& vratio); private: void proc(); - void EnqueueBmpBuffer(std::vector& bmpdata); void EnqueueBmpBuffer(std::shared_ptr>); void PaniusCount(); BlockingQueue>>m_imagedata; diff --git a/huagao/Device/JsonConfig.cpp b/huagao/Device/JsonConfig.cpp index 0d085f99..4b85c138 100644 --- a/huagao/Device/JsonConfig.cpp +++ b/huagao/Device/JsonConfig.cpp @@ -34,6 +34,7 @@ void JsonConfig::WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileNam outJson["Config"].Add(DB_AREANUM, (int)(pConfigItem->DBlank_AreaNum)); outJson["Config"].Add(DB_DEVNMAX, (int)(pConfigItem->DBlank_DevnMax)); outJson["Config"].Add(FLOD, (bool)(pConfigItem->EnFlod),false); + outJson["Config"].Add(SWITCHFRONTBACK, (bool)(pConfigItem->EnSwitchFrontBack), false); outJson["Config"].Add(BRIGHTNESS,(float)(pConfigItem->Brightness)); outJson["Config"].Add(AUTOCONTRAST,(bool)(pConfigItem->EnAutoContrast),false); @@ -97,6 +98,7 @@ void JsonConfig::WriteJsonArrayToFile(std::vector cfgArray,const s root["Config"].AddEmptySubArray(DB_AREANUM); root["Config"].AddEmptySubArray(DB_DEVNMAX); root["Config"].AddEmptySubArray(FLOD); + root["Config"].AddEmptySubArray(SWITCHFRONTBACK); root["Config"].AddEmptySubArray(BRIGHTNESS); root["Config"].AddEmptySubArray(AUTOCONTRAST); @@ -133,7 +135,8 @@ void JsonConfig::WriteJsonArrayToFile(std::vector cfgArray,const s root["Config"][DB_AREANUM].Add(cfgArray[i].DBlank_AreaNum); root["Config"][DB_DEVNMAX].Add(cfgArray[i].DBlank_DevnMax); root["Config"][FLOD].Add(i,cfgArray[i].EnFlod); - + root["Config"][SWITCHFRONTBACK].Add(i, cfgArray[i].EnSwitchFrontBack); + root["Config"][BRIGHTNESS].Add(cfgArray[i].Brightness); root["Config"][AUTOCONTRAST].Add(i,cfgArray[i].EnAutoContrast); root["Config"][CONTRAST].Add(cfgArray[i].Contrast); @@ -245,6 +248,7 @@ CONFIGPARAMS JsonConfig::GetDefaultConfigParams() params.DBlank_AreaNum = 8; params.DBlank_DevnMax = 200; params.EnFlod = FALSE; + params.EnSwitchFrontBack = FALSE; params.Brightness=0.0f;//亮度 params.EnAutoContrast=FALSE;//自动对比度 @@ -274,7 +278,6 @@ std::vector JsonConfig::parseJsonFromString(const std::string str) neb::CJsonObject root(str); vector vcConfig; - int size=0; neb::CJsonObject itmPaparSize; root["Config"].Get(PAPARSIZE,itmPaparSize); @@ -299,7 +302,8 @@ std::vector JsonConfig::parseJsonFromString(const std::string str) root["Config"].Get(DB_DEVNMAX, itmDBDevnMax); neb::CJsonObject itmEnFlod; root["Config"].Get(FLOD, itmEnFlod); - + neb::CJsonObject itmEnSwitchFrontBack; + root["Config"].Get(SWITCHFRONTBACK, itmEnSwitchFrontBack); neb::CJsonObject itmBrtnes; root["Config"].Get(BRIGHTNESS,itmBrtnes); @@ -378,6 +382,8 @@ std::vector JsonConfig::parseJsonFromString(const std::string str) cfp.DBlank_DevnMax = i_value; itmEnFlod.Get(i, b_value); cfp.EnFlod = b_value; + itmEnSwitchFrontBack.Get(i, b_value); + cfp.EnSwitchFrontBack = b_value; itmBrtnes.Get(i, i_value); cfp.Brightness= i_value; @@ -458,6 +464,8 @@ std::vector JsonConfig::parseJsonFromString(const std::string str) cfp.DBlank_DevnMax = index; root["Config"].Get(FLOD, bvalue); cfp.EnFlod = bvalue; + root["Config"].Get(SWITCHFRONTBACK, bvalue); + cfp.EnSwitchFrontBack = bvalue; root["Config"].Get(BRIGHTNESS,index); cfp.Brightness=index; diff --git a/huagao/Device/PublicFunc.cpp b/huagao/Device/PublicFunc.cpp index d26473aa..bcce2832 100644 --- a/huagao/Device/PublicFunc.cpp +++ b/huagao/Device/PublicFunc.cpp @@ -197,6 +197,8 @@ char* THCAR2char(TCHAR* tchStr) return chRtn; } +// CTwainUI 消息处理程序 + BOOL CheckAndCreateFileDir(TCHAR* p_file_path, BOOL flg) { TCHAR szTmp[MAX_PATH] = { 0 }; diff --git a/huagao/Device/PublicFunc.h b/huagao/Device/PublicFunc.h index c3fa84ee..fd3e8920 100644 --- a/huagao/Device/PublicFunc.h +++ b/huagao/Device/PublicFunc.h @@ -22,6 +22,7 @@ using namespace std; //