修复扫描丢图问题

This commit is contained in:
masayume 2021-07-23 10:49:05 +08:00
parent e580e312a8
commit 6a8302a066
2 changed files with 82 additions and 53 deletions

View File

@ -42,7 +42,10 @@ GScanO1003399::GScanO1003399():
{ {
im_data.reset(new std::vector<char>()); im_data.reset(new std::vector<char>());
open(0, 0); open(0, 0);
if (!m_usbthread.get()) {
b_usbthread = true;
m_usbthread.reset(new thread(&GScanO1003399::usb_run, this));
}
devState = DEV_STOP; devState = DEV_STOP;
} }
@ -113,7 +116,6 @@ void GScanO1003399::DogEar_callback(std::function<void(int)> fun)
} }
static int aquirenum = 0; static int aquirenum = 0;
static int getimgnum = 0; static int getimgnum = 0;
static StopWatch stopwatch;
int GScanO1003399::aquire_bmpdata(std::vector<unsigned char>& bmpdata) int GScanO1003399::aquire_bmpdata(std::vector<unsigned char>& bmpdata)
{ {
StopWatch sw; StopWatch sw;
@ -150,8 +152,6 @@ int GScanO1003399::aquire_bmpdata(std::vector<unsigned char>& bmpdata)
UpdateScanInfo(get_imgnReaded(), countNTransfered()); UpdateScanInfo(get_imgnReaded(), countNTransfered());
image--; image--;
sw.reset(); sw.reset();
FileTools::writelog(log_DEBUG, "3399上层取图间隔 " + to_string(stopwatch.elapsed_ms()));
stopwatch.reset();
return 0; return 0;
} }
DoEvents(); DoEvents();
@ -327,6 +327,7 @@ void GScanO1003399::Scanner_StartScan(UINT16 count)
{ {
devState = DEV_WRONG; devState = DEV_WRONG;
Set_ErrorCode(COUNT_MODE); Set_ErrorCode(COUNT_MODE);
scanflag = false;
return; return;
} }
//if (!Get_Scanner_PaperOn()) //if (!Get_Scanner_PaperOn())
@ -337,10 +338,6 @@ void GScanO1003399::Scanner_StartScan(UINT16 count)
//} //}
start(); start();
if (!m_usbthread.get()) {
b_usbthread = true;
m_usbthread.reset(new thread(&GScanO1003399::usb_run, this));
}
} }
void GScanO1003399::Stop_scan() void GScanO1003399::Stop_scan()
@ -533,52 +530,53 @@ bool GScanO1003399::is_dev_tx()
{ {
return scanner_read_reg(m_usb, SR_IM_TXING); return scanner_read_reg(m_usb, SR_IM_TXING);
} }
static StopWatch swatch;
void GScanO1003399::im_rx() void GScanO1003399::im_rx()
{ {
if (!is_rx() && !is_dev_tx())
{ fu_rx = m_imgthread.enqueue([this] {
fu_rx = m_imgthread.enqueue([this] { while (im_dev_count()){
while (im_dev_count()){ /* code */
/* code */ if (is_dev_tx())
if (keeplastimg) {
{ this_thread::sleep_for(chrono::microseconds(20));
this_thread::sleep_for(chrono::microseconds(10)); continue;
if (m_param.is_duplex) {
if(im_dev_count()<3)
continue;
}
if(im_dev_count()<2)
continue;
}
//auto &buffi = im_data;
std::shared_ptr<std::vector<char>> buffi(new std::vector<char>);
int count = front_datasize();
buffi->resize(count);
rx_cmd();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024));
pop_dev_im();
vector<cv::Mat> mats;
if (m_param.multi_output_red)
image += 2;
else
image++;
UpdateScanInfo(countNReaded(), get_imgTransfered());
FileTools::writelog(log_DEBUG, "3399usb取图间隔 " + to_string(swatch.elapsed_ms()));
swatch.reset();
imgs.Put(buffi);
fu_imgpro.push(m_imgprocthread.enqueue([this] {
imgproce(imgs.Take());
}));
while (fu_imgpro.size()>1)
{
fu_imgpro.front().get();
fu_imgpro.pop();
}
} }
}); if (keeplastimg)
} {
this_thread::sleep_for(chrono::microseconds(10));
if (m_param.is_duplex) {
if(im_dev_count()<3)
continue;
}
if(im_dev_count()<2)
continue;
}
//auto &buffi = im_data;
std::shared_ptr<std::vector<char>> buffi(new std::vector<char>);
int count = front_datasize();
buffi->resize(count);
rx_cmd();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024));
pop_dev_im();
vector<cv::Mat> mats;
if (m_param.multi_output_red)
image += 2;
else
image++;
UpdateScanInfo(countNReaded(), get_imgTransfered());
imgs.Put(buffi);
fu_imgpro.push(m_imgprocthread.enqueue([this] {
imgproce(imgs.Take());
}));
while (fu_imgpro.size()>1)
{
fu_imgpro.front().get();
fu_imgpro.pop();
}
}
});
} }
int GScanO1003399::read_data(void* data, int length, int timeout) int GScanO1003399::read_data(void* data, int length, int timeout)
@ -643,8 +641,38 @@ void GScanO1003399::imgproce(std::shared_ptr<std::vector<char>>& buff)
FileTools::writelog(log_ERROR, e.what()); FileTools::writelog(log_ERROR, e.what());
} }
} }
FileTools::writelog(log_DEBUG, "3399图像解码耗时 " + to_string(sw.elapsed_ms())); FileTools::writelog(log_DEBUG, "图像解码耗时 " + to_string(sw.elapsed_ms()));
sw.reset();
buffs.clear(); buffs.clear();
if (m_param.imageRotateDegree != 0.0 || m_param.is_backrotate180 || m_param.is_autotext)
{
CImageApplyRotation::RotationType type;
if (m_param.imageRotateDegree > 89.0f && m_param.imageRotateDegree < 91.0f)
type = CImageApplyRotation::RotationType::Rotate_90_clockwise;
else if (m_param.imageRotateDegree > 269.0f && m_param.imageRotateDegree < 271.0f)
type = CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
else if (m_param.imageRotateDegree > 179.0f && m_param.imageRotateDegree < 181.0f)
type = CImageApplyRotation::RotationType::Rotate_180;
else
type = CImageApplyRotation::RotationType::Invalid;
if (m_param.is_autotext)
type = CImageApplyRotation::RotationType::AutoTextOrientation;
TCHAR szIniFile[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_WINDOWS, TRUE);
#ifdef LANXUM
_tcscat(szIniFile, _T("\\twain_32\\LANXUMSCAN\\tessdata"));
#else
_tcscat(szIniFile, _T("\\twain_32\\HuaGoScan\\tessdata"));
#endif //
int iLen = WideCharToMultiByte(CP_ACP, 0, szIniFile, -1, NULL, 0, NULL, NULL);
char* chRtn = new char[iLen * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, szIniFile, -1, chRtn, iLen, NULL, NULL);
CImageApplyRotation(type, m_param.is_backrotate180, m_param.resolution_dst, chRtn).apply(mats,m_param.is_duplex);
delete[] chRtn;
}
FileTools::writelog(log_DEBUG, "图像旋转耗时 " + to_string(sw.elapsed_ms()));
if (m_param.automaticcolor) if (m_param.automaticcolor)
{ {
CImageApplyColorRecognition(m_param.automaticcolortype == 1 ? CImageApplyColorRecognition::ColorRecognitionMode::Color_Gray : CImageApplyColorRecognition::ColorRecognitionMode::Color_Mono).apply(mats,m_param.is_duplex); CImageApplyColorRecognition(m_param.automaticcolortype == 1 ? CImageApplyColorRecognition::ColorRecognitionMode::Color_Gray : CImageApplyColorRecognition::ColorRecognitionMode::Color_Mono).apply(mats,m_param.is_duplex);

View File

@ -819,7 +819,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
if (vid == 0 || pid == 0) if (vid == 0 || pid == 0)
{ {
//ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("201"), NULL, SW_HIDE); //ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("201"), NULL, SW_HIDE);
showmsg("¾¯¸æ", msgs[(UsbSupported)201]); //showmsg("警告", msgs[(UsbSupported)201]);
ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("未找到扫描仪!请检查电源或者USB连接线是否接通! 警告"), NULL, SW_HIDE);
if (hMutex) { if (hMutex) {
CloseHandle(hMutex); CloseHandle(hMutex);
hMutex = NULL; hMutex = NULL;