1.ui界面增加答题卡除红选项;

2.增加相应的协议,增加json配置文件;
3.关闭锐化与二值化的互斥效果;
This commit is contained in:
lovelyyoung 2020-06-23 17:31:43 +08:00
parent cc07cedfbf
commit 14b55e0c2c
10 changed files with 73 additions and 21 deletions

View File

@ -36,6 +36,7 @@ CImageProcPage::CImageProcPage(CWnd* pParent /*=nullptr*/)
, m_ckbAutoDeskrew(FALSE) , m_ckbAutoDeskrew(FALSE)
, m_ckbMultioutput(FALSE) , m_ckbMultioutput(FALSE)
, m_ckbRemoveHole(FALSE) , m_ckbRemoveHole(FALSE)
, m_ckbHSVCorrect(FALSE)
{ {
} }
@ -68,11 +69,11 @@ void CImageProcPage::ImageProcPageUpdate(int val)
t_chMultiOutput->EnableWindow(FALSE); t_chMultiOutput->EnableWindow(FALSE);
} }
bool enabele = ival <= 1;//彩色或灰度 //bool enabele = ival <= 1;//彩色或灰度
if (!enabele) { //if (!enabele) {
m_temp_sharpen->SetCurSel(0); // m_temp_sharpen->SetCurSel(0);
} //}
m_temp_sharpen->EnableWindow(enabele); //m_temp_sharpen->EnableWindow(enabele);
} }
void CImageProcPage::ImageAutoDescrewUpdate(int val) void CImageProcPage::ImageAutoDescrewUpdate(int val)
@ -96,6 +97,7 @@ void CImageProcPage::DoDataExchange(CDataExchange* pDX)
DDX_Check(pDX, IDC_CKAUTODESKREW, m_ckbAutoDeskrew); DDX_Check(pDX, IDC_CKAUTODESKREW, m_ckbAutoDeskrew);
DDX_Check(pDX, IDC_CKMULTIOUTPUT, m_ckbMultioutput); DDX_Check(pDX, IDC_CKMULTIOUTPUT, m_ckbMultioutput);
DDX_Check(pDX, IDC_CKREMOVEHOLE, m_ckbRemoveHole); DDX_Check(pDX, IDC_CKREMOVEHOLE, m_ckbRemoveHole);
DDX_Check(pDX, IDC_CKHSVCORRECT, m_ckbHSVCorrect);
} }
BOOL CImageProcPage::OnInitDialog() BOOL CImageProcPage::OnInitDialog()

View File

@ -21,6 +21,7 @@ public:
BOOL m_ckbAutoDeskrew; BOOL m_ckbAutoDeskrew;
BOOL m_ckbMultioutput; BOOL m_ckbMultioutput;
BOOL m_ckbRemoveHole; BOOL m_ckbRemoveHole;
BOOL m_ckbHSVCorrect;
void ImageProcPageUpdate(int val); void ImageProcPageUpdate(int val);
void ImageAutoDescrewUpdate(int val); void ImageAutoDescrewUpdate(int val);
@ -39,4 +40,6 @@ protected:
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
afx_msg void OnCtrlChange(); afx_msg void OnCtrlChange();
}; };

View File

@ -162,6 +162,7 @@ void CTwainUI::UpdateUI()
m_pageImageProc->m_ckbMultioutput = settings->multi_output_red == TRUE ? TRUE : FALSE;//多流除红 m_pageImageProc->m_ckbMultioutput = settings->multi_output_red == TRUE ? TRUE : FALSE;//多流除红
else else
m_pageImageProc->m_ckbMultioutput = FALSE;//多流除红 m_pageImageProc->m_ckbMultioutput = FALSE;//多流除红
m_pageImageProc->m_ckbHSVCorrect = settings->hsvcorrect == TRUE ? TRUE : FALSE;//答题卡除红
m_pageImageProc->GetDlgItem(IDC_CKMULTIOUTPUT)->EnableWindow(settings->pixtype == 2);//彩色可用 m_pageImageProc->GetDlgItem(IDC_CKMULTIOUTPUT)->EnableWindow(settings->pixtype == 2);//彩色可用
m_pageImageProc->UpdateData(FALSE); m_pageImageProc->UpdateData(FALSE);
@ -368,6 +369,7 @@ void CTwainUI::UpDateScanParam(PCONFIGPARAMS configItem, bool updateDs)
configItem->EnOutHole = m_pageImageProc->m_ckbRemoveHole;//除穿孔可用性 configItem->EnOutHole = m_pageImageProc->m_ckbRemoveHole;//除穿孔可用性
configItem->OutHoleRatio = WndCtrl2f(&(m_pageImageProc->m_edit_hole)) * 100;//穿孔搜索范围比例系数 configItem->OutHoleRatio = WndCtrl2f(&(m_pageImageProc->m_edit_hole)) * 100;//穿孔搜索范围比例系数
configItem->EnMultiOutPutR = m_pageImageProc->m_ckbMultioutput;//多流除红 configItem->EnMultiOutPutR = m_pageImageProc->m_ckbMultioutput;//多流除红
configItem->EnHsvCorrect = m_pageImageProc->m_ckbHSVCorrect;//答题卡除红
//!< Page feed paper //!< Page feed paper
m_pageFeedPaper->UpdateData(); m_pageFeedPaper->UpdateData();
@ -459,6 +461,7 @@ void CTwainUI::UpDateScanParam(PCONFIGPARAMS configItem, bool updateDs)
settings->fillhole.is_fillhole = configItem->EnOutHole; settings->fillhole.is_fillhole = configItem->EnOutHole;
settings->fillhole.fillholeratio = configItem->OutHoleRatio; settings->fillhole.fillholeratio = configItem->OutHoleRatio;
settings->multi_output_red = configItem->EnMultiOutPutR; settings->multi_output_red = configItem->EnMultiOutPutR;
settings->hsvcorrect = configItem->EnHsvCorrect;
#ifdef REAL300DPI #ifdef REAL300DPI
settings->resolution_native = settings->resolution_dst > 240.0f ? 300.0f : 200.0f; settings->resolution_native = settings->resolution_dst > 240.0f ? 300.0f : 200.0f;
#else // REAL300DPI #else // REAL300DPI

View File

@ -20,9 +20,10 @@ G4Tiff::G4Tiff(cv::Mat & mat, int threshold)
except(TIFFSetField(pTiffHandle, TIFFTAG_IMAGELENGTH, height), "length"); except(TIFFSetField(pTiffHandle, TIFFTAG_IMAGELENGTH, height), "length");
except(TIFFSetField(pTiffHandle, TIFFTAG_BITSPERSAMPLE, 1), "bits per sample"); except(TIFFSetField(pTiffHandle, TIFFTAG_BITSPERSAMPLE, 1), "bits per sample");
except(TIFFSetField(pTiffHandle, TIFFTAG_SAMPLESPERPIXEL, 1), "samples per pixel"); except(TIFFSetField(pTiffHandle, TIFFTAG_SAMPLESPERPIXEL, 1), "samples per pixel");
except(TIFFSetField(pTiffHandle, TIFFTAG_ROWSPERSTRIP, 1), "rows per strip"); except(TIFFSetField(pTiffHandle, TIFFTAG_ROWSPERSTRIP, height), "rows per strip");
except(TIFFSetField(pTiffHandle, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4), "compression"); //except(TIFFSetField(pTiffHandle, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4), "compression");
except(TIFFSetField(pTiffHandle, TIFFTAG_COMPRESSION, COMPRESSION_CCITT_T6), "compression");
except(TIFFSetField(pTiffHandle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE), "photometric"); except(TIFFSetField(pTiffHandle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE), "photometric");
except(TIFFSetField(pTiffHandle, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB), "photometric"); except(TIFFSetField(pTiffHandle, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB), "photometric");
except(TIFFSetField(pTiffHandle, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG), "planar config"); except(TIFFSetField(pTiffHandle, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG), "planar config");
@ -33,8 +34,9 @@ G4Tiff::G4Tiff(cv::Mat & mat, int threshold)
except(TIFFSetField(pTiffHandle, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH), "res unit"); except(TIFFSetField(pTiffHandle, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH), "res unit");
std::vector<uchar> _buffer(width / 8 + 8, 0); std::vector<uchar> _buffer(width / 8 + 8, 0);
//std::vector<uchar> _buffer(width / 8 + 1, 0);
uchar* buffer = &_buffer[0]; uchar* buffer = &_buffer[0];
int bytes = int(width / 8.0 + 0.5); //int bytes = int(width / 8.0 + 0.5);
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
uint8_t* src_row = mat.ptr(y); uint8_t* src_row = mat.ptr(y);
@ -46,7 +48,7 @@ G4Tiff::G4Tiff(cv::Mat & mat, int threshold)
eight_pixels = eight_pixels | 1; // eight_pixels = eight_pixels | 1; //
buffer[x / 8] = eight_pixels; buffer[x / 8] = eight_pixels;
} }
except(TIFFWriteScanline(pTiffHandle, buffer, y, bytes) != -1, "write scanline"); except(TIFFWriteScanline(pTiffHandle, buffer, y, 0) != -1, "write scanline");
} }
} }
@ -76,16 +78,20 @@ void G4Tiff::GetCompressedData(std::vector<uchar>& cmpeddata)
FILE* file = fopen(m_tmppath.c_str(), "rb"); FILE* file = fopen(m_tmppath.c_str(), "rb");
if (file) if (file)
{ {
int filesize = _lseek(_fileno(file), 0, SEEK_END); // seek to EOF int filesize = _lseek(_fileno(file), 0, SEEK_END); // seek to EOF
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
std::vector<uchar> ifh(8, 0);
fread(ifh.data(), 1, ifh.size(), file);
int size = (int)(*(int*)(ifh.data() + 4));
fseek(file, 8, SEEK_SET);
if (filesize) if (filesize)
{ {
cmpeddata.resize(filesize); cmpeddata.resize(size);
fread(cmpeddata.data(), 1, filesize, file); fread(cmpeddata.data(), 1, size, file);
} }
FILE* file1 = fopen("d:\\1.tiff", "wb");
fwrite(cmpeddata.data(), filesize, 1, file1);
fclose(file1);
} }
fclose(file); fclose(file);

View File

@ -47,6 +47,7 @@ GScanCap GscanJsonConfig::GetDefaultGscancapValue()
gcap.filter = 3;//¶ÔÓ¦Filter::None gcap.filter = 3;//¶ÔÓ¦Filter::None
gcap.multi_output_red = FALSE; gcap.multi_output_red = FALSE;
gcap.sharpen = SharpenBlur::Sharpen_None; gcap.sharpen = SharpenBlur::Sharpen_None;
gcap.hsvcorrect = FALSE;//默认不开启答题卡除红
/*< feeder setting*/ /*< feeder setting*/
gcap.hardwarecaps.en_doublefeed = TRUE;//ĬÈÏ¿ªÆôË«ÕÅ gcap.hardwarecaps.en_doublefeed = TRUE;//ĬÈÏ¿ªÆôË«ÕÅ
@ -93,6 +94,7 @@ void GscanJsonConfig::SaveGscanCapConfig(const GScanCap & gcap, const std::strin
outJson["Config"].Add(MULTIOUTPUT, (bool)(gcap.multi_output_red), false); outJson["Config"].Add(MULTIOUTPUT, (bool)(gcap.multi_output_red), false);
outJson["Config"].Add(OUTHOLE, (bool)(gcap.fillhole.is_fillhole), false); outJson["Config"].Add(OUTHOLE, (bool)(gcap.fillhole.is_fillhole), false);
outJson["Config"].Add(OUTHOLERATIO, (int)(gcap.fillhole.fillholeratio)); outJson["Config"].Add(OUTHOLERATIO, (int)(gcap.fillhole.fillholeratio));
outJson["Config"].Add(HSVCORRECT, (bool)(gcap.hsvcorrect));
outJson["Config"].Add(ULTRADETECT, (bool)(gcap.hardwarecaps.en_doublefeed), false); outJson["Config"].Add(ULTRADETECT, (bool)(gcap.hardwarecaps.en_doublefeed), false);
outJson["Config"].Add(BINDINGDETECT, (bool)(gcap.hardwarecaps.en_stapledetect), false); outJson["Config"].Add(BINDINGDETECT, (bool)(gcap.hardwarecaps.en_stapledetect), false);
@ -143,6 +145,7 @@ void GscanJsonConfig::WriteJsonArrayToFile(std::vector<GScanCap> cfgArray, const
root["Config"].AddEmptySubArray(MULTIOUTPUT); root["Config"].AddEmptySubArray(MULTIOUTPUT);
root["Config"].AddEmptySubArray(OUTHOLE); root["Config"].AddEmptySubArray(OUTHOLE);
root["Config"].AddEmptySubArray(OUTHOLERATIO); root["Config"].AddEmptySubArray(OUTHOLERATIO);
root["Config"].AddEmptySubArray(HSVCORRECT);
/*< feeder settings*/ /*< feeder settings*/
root["Config"].AddEmptySubArray(ULTRADETECT); root["Config"].AddEmptySubArray(ULTRADETECT);
@ -185,6 +188,7 @@ void GscanJsonConfig::WriteJsonArrayToFile(std::vector<GScanCap> cfgArray, const
root["Config"][MULTIOUTPUT].Add(i, (bool)cfgArray[i].multi_output_red); root["Config"][MULTIOUTPUT].Add(i, (bool)cfgArray[i].multi_output_red);
root["Config"][OUTHOLE].Add(i, (bool)cfgArray[i].fillhole.is_fillhole); root["Config"][OUTHOLE].Add(i, (bool)cfgArray[i].fillhole.is_fillhole);
root["Config"][OUTHOLERATIO].Add(cfgArray[i].fillhole.fillholeratio); root["Config"][OUTHOLERATIO].Add(cfgArray[i].fillhole.fillholeratio);
root["Config"][HSVCORRECT].Add(i, (bool)cfgArray[i].hsvcorrect);
root["Config"][ULTRADETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_doublefeed); root["Config"][ULTRADETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_doublefeed);
root["Config"][BINDINGDETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_stapledetect); root["Config"][BINDINGDETECT].Add(i, (bool)cfgArray[i].hardwarecaps.en_stapledetect);
@ -329,6 +333,8 @@ std::vector<GScanCap> GscanJsonConfig::parseJsonFromString(const std::string str
root["Config"].Get(OUTHOLE, itmOutHole); root["Config"].Get(OUTHOLE, itmOutHole);
neb::CJsonObject itmOutHoleRatio; neb::CJsonObject itmOutHoleRatio;
root["Config"].Get(OUTHOLERATIO, itmOutHoleRatio); root["Config"].Get(OUTHOLERATIO, itmOutHoleRatio);
neb::CJsonObject itmHsvCorrect;
root["Config"].Get(HSVCORRECT, itmHsvCorrect);
neb::CJsonObject itmUltDetect; neb::CJsonObject itmUltDetect;
root["Config"].Get(ULTRADETECT, itmUltDetect); root["Config"].Get(ULTRADETECT, itmUltDetect);
@ -415,6 +421,8 @@ std::vector<GScanCap> GscanJsonConfig::parseJsonFromString(const std::string str
cfp.fillhole.is_fillhole = b_value ? 1 : 0; cfp.fillhole.is_fillhole = b_value ? 1 : 0;
itmOutHoleRatio.Get(i, i_value); itmOutHoleRatio.Get(i, i_value);
cfp.fillhole.fillholeratio = i_value; cfp.fillhole.fillholeratio = i_value;
itmHsvCorrect.Get(i, b_value);
cfp.hsvcorrect = b_value ? 1 : 0;
itmUltDetect.Get(i, b_value); itmUltDetect.Get(i, b_value);
cfp.hardwarecaps.en_doublefeed = b_value ? 1 : 0; cfp.hardwarecaps.en_doublefeed = b_value ? 1 : 0;
@ -503,6 +511,9 @@ std::vector<GScanCap> GscanJsonConfig::parseJsonFromString(const std::string str
cfp.fillhole.is_fillhole = bvalue?1:0; cfp.fillhole.is_fillhole = bvalue?1:0;
root["Config"].Get(OUTHOLERATIO, index); root["Config"].Get(OUTHOLERATIO, index);
cfp.fillhole.fillholeratio = index; cfp.fillhole.fillholeratio = index;
root["Config"].Get(HSVCORRECT, bvalue);
cfp.hsvcorrect = bvalue ? 1 : 0;
root["Config"].Get(ULTRADETECT, bvalue); root["Config"].Get(ULTRADETECT, bvalue);
cfp.hardwarecaps.en_doublefeed = bvalue?1:0; cfp.hardwarecaps.en_doublefeed = bvalue?1:0;

View File

@ -42,7 +42,8 @@ enum class CapTypeEx : unsigned short {
TwEx_DBDevnMax = 0x8028, TwEx_DBDevnMax = 0x8028,
TwEx_StableDetectEnable = 0x8090, TwEx_StableDetectEnable = 0x8090,
TwEx_UVModel = 0x8093, TwEx_UVModel = 0x8093,
TwEx_SwitchFrontBack = 0x8094 TwEx_SwitchFrontBack = 0x8094,
TwEx_HsvCorrect = 0x8095
}; };
using namespace Twpp; using namespace Twpp;
@ -1367,6 +1368,31 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
} }
}; };
//´ðÌ⿨³ýºì
m_query[(CapType)(CapTypeEx::TwEx_HsvCorrect)] = msgSupportGetAllSetReset;
m_caps[(CapType)(CapTypeEx::TwEx_HsvCorrect)] = [this](Msg msg, Capability& data)->Result {
switch (msg) {
case Msg::Get:
data = Capability::createEnumeration<Bool>((CapType)(CapTypeEx::TwEx_HsvCorrect), { Bool(),Bool(true) }, Bool(m_scanparam->hsvcorrect), 0);
return success();
case Msg::GetCurrent:
data = Capability::createOneValue<Bool>((CapType)(CapTypeEx::TwEx_HsvCorrect), m_scanparam->hsvcorrect);
return success();
case Msg::Reset:
m_scanparam->hsvcorrect = false;
case Msg::GetDefault:
data = Capability::createOneValue<Bool>((CapType)(CapTypeEx::TwEx_HsvCorrect), Bool(false));
return success();
case Msg::Set: {
auto mech = data.currentItem<Bool>();
m_scanparam->hsvcorrect = mech;
return success();
}
default:
return capBadOperation();
}
};
m_query[CapType::IFilter] = msgSupportGetAllSetReset; m_query[CapType::IFilter] = msgSupportGetAllSetReset;
m_caps[CapType::IFilter] = [this](Msg msg, Capability& data)->Result { m_caps[CapType::IFilter] = [this](Msg msg, Capability& data)->Result {
switch (msg) { switch (msg) {
@ -1720,6 +1746,7 @@ Result HuagaoDs::identityCloseDs(const Identity&) {
if (guiBridge.get()) if (guiBridge.get())
guiBridge.reset(); guiBridge.reset();
scanner.reset(); scanner.reset();
if (hMutex) if (hMutex)
@ -1745,7 +1772,7 @@ Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) {
scanner->Set_ErrorCode(0); scanner->Set_ErrorCode(0);
guiIndicator.reset(); guiIndicator.reset();
if (ret != -1) { if (ret != -1) {
MessageBox(guiTwain ? guiTwain->m_hWnd : NULL, noticeMsgMap[ret], _T("Ìáʾ"), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION); MessageBox(guiTwain ? guiTwain->m_hWnd : NULL, noticeMsgMap[ret], _T("Ìáʾ"), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION);//
#ifndef G200 #ifndef G200
scanner->clear_hwerror(); scanner->clear_hwerror();
#endif // G200 #endif // G200
@ -1900,11 +1927,11 @@ Result HuagaoDs::imageMemXferGet(const Identity& origin, ImageMemXfer& data) {
if (rows == 0) { if (rows == 0) {
return seqError(); // image already transfered in this session return seqError(); // image already transfered in this session
} }
//cv::Mat mat = cv::imdecode(bmpData, cv::IMREAD_GRAYSCALE); cv::Mat mat = cv::imdecode(bmpData, cv::IMREAD_GRAYSCALE);
//G4Tiff gt(mat); //G4Tiff gt(mat);
//vector<uchar> cmpdata; //vector<uchar> cmpdata;
//gt.GetCompressedData(cmpdata); //gt.GetCompressedData(cmpdata);
////int aa = 1; //int aa = 1;
data.setBytesPerRow(bpl); data.setBytesPerRow(bpl);
data.setColumns(static_cast<UInt32>(dib->biWidth)); data.setColumns(static_cast<UInt32>(dib->biWidth));
data.setRows(rows); data.setRows(rows);
@ -2145,8 +2172,8 @@ void HuagaoDs::updataGscanCap()
Twpp::Result HuagaoDs::startScan() Twpp::Result HuagaoDs::startScan()
{ {
if (!scanner->IsConnected()) //if (!scanner->IsConnected())
return checkDeviceOnline(); // return checkDeviceOnline();
scanner->ResetScanner(); scanner->ResetScanner();

View File

@ -63,7 +63,7 @@ protected:
virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override; virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override; virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override; virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override;
static void SetResoluton(const char* path, int resolution); void SetResoluton(const char* path, int resolution);
private: private:
Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false); Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false);
Twpp::Result startScan(); Twpp::Result startScan();

Binary file not shown.

Binary file not shown.

Binary file not shown.