This commit is contained in:
13038267101 2023-11-01 10:45:27 +08:00
commit 567d030f02
16 changed files with 232 additions and 94 deletions

View File

@ -113,9 +113,9 @@ bool CImageApplyDiscardBlank::apply(const cv::Mat& pDib, double threshold, int e
return b;
}
bool CImageApplyDiscardBlank::apply(int fileSize, const cv::Size& imageSize, FileType flag)
bool CImageApplyDiscardBlank::apply(int fileSize, const cv::Size& imageSize, FileType type, double threshold, const char* data)
{
switch (flag)
switch (type)
{
case JPEG_COLOR:
if (static_cast<double>(fileSize) / static_cast<double>(imageSize.width * imageSize.height) > 0.039)

View File

@ -21,8 +21,9 @@
2022/11/29 v1.5
2022/12/03 v1.5.1
2023/10/12 v1.6 JEPG文件大小判断是否为空白页
2023/10/20 v1.6.1 JEPG文件大小判断空白页
* v1.6.1
2023/10/20 v1.6.1 JPEG文件大小判断空白页
2023/10/30 v1.7 JPEG文件大小判断空白页的算法接口
* v1.7
* ====================================================
*/
@ -74,13 +75,15 @@ public:
static bool apply(const cv::Mat& pDib, double threshold = 40, int edge = 50, double devTh = 30, double meanTh = 200, int dilate = 3);
/// <summary>
/// 空白页识别。根据jpeg文件大小进行判断。
///
/// </summary>
/// <param name="fileSize">J文件大小</param>
/// <param name="fileSize">JPG文件大小</param>
/// <param name="imageSize">图像大小</param>
/// <param name="flag">0为JPG + 彩色1为JPG + 灰度2为PNG + 彩色, 3为PNG + 灰度, 4为PNG + </param>
/// <returns></returns>
static bool apply(int fileSize, const cv::Size& imageSize, FileType type);
/// <param name="type">0为JPG + 彩色1为JPG + 灰度2为PNG + 彩色, 3为PNG + 灰度, 4为PNG + 二值图</param>
/// <param name="threshold">识别灵敏度阈值</param>
/// <param name="data">文件数据头指针</param>
/// <returns>true为空白页false为非空白页</returns>
static bool apply(int fileSize, const cv::Size& imageSize, FileType type, double threshold, const char* data = nullptr);
private:
double m_threshold;

View File

@ -69,6 +69,7 @@ g_page[] =
{MAKE_ID_AND_STR(ID_OPTION_VALUE_SMYM_SM), PAGE_DOUBLE},
{MAKE_ID_AND_STR(ID_OPTION_VALUE_SMYM_TGKBYTY), PAGE_OMIT_EMPTY},
{MAKE_ID_AND_STR(ID_OPTION_VALUE_SMYM_TGKBYFPZ), PAGE_OMIT_EMPTY_RECEIPT},
{MAKE_ID_AND_STR(ID_OPTION_VALUE_SMYM_TGKBYJYWJDX), PAGE_OMIT_EMPTY_FILE_SIZE},
{MAKE_ID_AND_STR(ID_OPTION_VALUE_SMYM_DZ), PAGE_FOLIO}
},

View File

@ -173,12 +173,14 @@ bool is_lateral(int paper);
//#define HUAGAO_SETTING_STR_PAGE_DOUBLE "双面"
//#define HUAGAO_SETTING_STR_PAGE_OMIT_EMPTY "跳过空白页(通用)"
//#define HUAGAO_SETTING_STR_PAGE_OMIT_EMPTY_RECEIPT "跳过空白页(发票纸)"
//#define HUAGAO_SETTING_STR_PAGE_OMIT_EMPTY_FILE_SIZE "跳过空白页(基于文件大小)"
//#define HUAGAO_SETTING_STR_PAGE_FOLIO "对折"
enum {
PAGE_SINGLE = 0,
PAGE_DOUBLE,
PAGE_OMIT_EMPTY,
PAGE_OMIT_EMPTY_RECEIPT,
PAGE_OMIT_EMPTY_FILE_SIZE,
PAGE_FOLIO,
};
int match_best_page(std::string& val, bool* exact);
@ -619,9 +621,7 @@ typedef struct _scan_conf
int discare_dilate; /**< 调过空白页纸张杂点阈值>*/
double discare_meanth; /**< 调过空白页文稿底色阈值>*/
bool en_contaminationdetection; /**< 脏污检测使能>*/
uint8_t contaminationdetection_threshold_1; /**< 脏污检测第一阈值,超过该阈值视为存在脏污>*/
uint8_t contaminationdetection_threshold_2; /**< 脏污检测第二阈值配合width使用超过该阈值且连续宽度达到width视为存在脏污>*/
uint32_t contaminationdetection_width; /**< 脏污检测宽度配合threshold2使用>*/
bool detect_size_diascard_blank; /**< 基于压缩图像大小跳过空白页使能*/
uint32_t reserve[1024]; /**< 预留4096字节做协议扩展*/
}SCANCONF ,*LPSCANCONF;
//图像参数设置 -OVER

View File

@ -1454,6 +1454,11 @@ bool hg_scanner::jsn_reorganize()
{
erase_option(SANE_STD_OPT_NAME_SIZE_CHECK);
}
if (!firmware_sup_dirty_check)
{
erase_option(SANE_STD_OPT_NAME_LENS_DIRTY);
}
return true;
}
int hg_scanner::hgpaper_to_devspaper(Paper_Map papermap[], int len, int& paper, bool* exact, TwSS* type)
@ -3055,7 +3060,7 @@ int hg_scanner::on_process_double_paper(bool type)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner::on_detect_lens_dirty(bool type)
int hg_scanner::on_detect_lens_dirty(bool &type)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
@ -3459,9 +3464,22 @@ int hg_scanner::try_third_app_handle_start(bool& handled)
{
int ret = SCANNER_ERR_OK;
handled = false;
return ret;
handled = !async_io_;
if (handled)
{
if (user_cancel_)
{
if (status_ != SCANNER_ERR_OK && status_ != SCANNER_ERR_USER_CANCELED) // call stop after exception occurs, start a new scanning ...
{
handled = false;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "call start after user cancelled while status is %s, we start a new scanning\n", hg_scanner_err_description(status_));
return ret;
}
}
while (wait_usb_result_.try_wait())
std::this_thread::sleep_for(std::chrono::milliseconds(3));
@ -3505,13 +3523,14 @@ int hg_scanner::try_third_app_handle_start(bool& handled)
}
int hg_scanner::try_third_app_after_start(int err)
{
if (!async_io_)
{
while (wait_img_.is_waiting() && !wait_usb_.is_waiting())
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if (wait_img_.is_waiting() && wait_usb_.is_waiting())
err = status_;
}
//if (!async_io_)
//{
// while (wait_img_.is_waiting() && !wait_usb_.is_waiting())
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
// if (wait_img_.is_waiting() && wait_usb_.is_waiting())
// err = status_;
//
//}
return err;
}
@ -3609,7 +3628,7 @@ int hg_scanner::save_usb_data(std::shared_ptr<tiny_buffer> data)
unsigned int bytes = data->size();
usb_img_index_++;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "USB read one picture with %u bytes\n", data->size());
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "USB packet(%04d) of picture with %u bytes(status: %d)\n", usb_img_index_, data->size(), data->get_image_statu());
if (dump_usb_path_.length()) //这两台设备不是jpg的图 所以不能直接处理
{
char name[80] = { 0 };
@ -4081,11 +4100,98 @@ void hg_scanner::on_language_changed(void)
}
}
}
int hg_scanner::wait_one_image_from_start(bool& handled)
{
int ret = SCANNER_ERR_OK;
handled = false;
if (!async_io_) // non-callback
{
while (is_running() != THREAD_RUNNING_IDLE)
{
handled = true;
if (final_imgs_.size())
{
break;
}
}
if (final_imgs_.size())
{
IMH head = { 0 };
handled = true;
if (final_imgs_.front(&head))
{
if (head.statu & IMG_STATUS_DOUBLE)
ret = SCANNER_ERR_DEVICE_DOUBLE_FEEDING;
else if (head.statu & IMG_STATUS_JAM)
ret = SCANNER_ERR_DEVICE_PAPER_JAMMED;
else if (head.statu & IMG_STATUS_STAPLE)
ret = SCANNER_ERR_DEVICE_STAPLE_ON;
else if (head.statu & IMG_STATUS_SIZE_ERR)
ret = SCANNER_ERR_DEVICE_SIZE_CHECK;
else if (head.statu & IMG_STATUS_DOGEAR)
ret = SCANNER_ERR_DEVICE_DOGEAR;
}
}
else if (handled) // overed normal or exception
{
if (status_ == SCANNER_ERR_OK
|| status_ == SCANNER_ERR_DEVICE_DOUBLE_FEEDING) // 双张特殊处理,视为成功
{
SANE_Bool has_paper = SANE_FALSE;
get_scanner_paperon(has_paper);
if (has_paper == SANE_TRUE)
handled = false;
else
ret = SCANNER_ERR_DEVICE_NO_PAPER;
}
else
ret = status_;
}
}
return ret;
}
int hg_scanner::start(void)
{
user_cancel_ = false;
int ret = SCANNER_ERR_OK;
bool handled = false;
return status_;
if (user_cancel_)
{
user_cancel_ = false; // stopped by user, reset flag and starting a new scanning ...
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "start after user stopped just now while with %d image(s) in queue, a new scanning will to be started ...\n", final_imgs_.size());
}
else
{
ret = wait_one_image_from_start(handled);
if (handled)
{
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "start in previous scanning and result is %s, image count %d\n", hg_scanner_err_description(ret), final_imgs_.size());
return ret;
}
}
// clear ...
imgs_.Clear();
final_imgs_.clear();
usb_img_index_ = final_img_index_ = 0;
status_ = SCANNER_ERR_OK;
// start ...
ret = do_start();
if (ret == SCANNER_ERR_OK)
{
// wait ONE picture or stopped
ret = wait_one_image_from_start(handled);
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "start scanning result = %s\n", hg_scanner_err_description(ret));
return ret;
}
int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
{
@ -4197,9 +4303,21 @@ int hg_scanner::read_image_data(unsigned char* buf, int* len)
}
int hg_scanner::stop(void)
{
user_cancel_ = true;
int ret = SCANNER_ERR_OK;
return status_;
user_cancel_ = true;
ret = do_stop();
// wait until really stopped ...
if (ret == SCANNER_ERR_OK)
{
while (is_running() != THREAD_RUNNING_IDLE)
std::this_thread::sleep_for(std::chrono::milliseconds(3));
ret = status_;
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "user stopped result = %s\n", hg_scanner_err_description(ret));
return ret;
}
int hg_scanner::reset(void)
{
@ -5296,6 +5414,7 @@ int hg_scanner::image_configuration(SCANCONF& ic)
ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY_FILE_SIZE
|| image_prc_param_.bits.page == PAGE_FOLIO);
if (is_dpi_color_check)
@ -5334,6 +5453,7 @@ int hg_scanner::image_configuration(SCANCONF& ic)
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY || is_discardblank;
ic.discardblank_percent = omit_empty_level_;
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
ic.detect_size_diascard_blank = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_FILE_SIZE;
ic.is_switchfrontback = image_prc_param_.bits.exchange;
ic.autodescrew = image_prc_param_.bits.automatic_skew;
ic.multi_output_red = image_prc_param_.bits.rid_red; //之前加上可能导致超时,或者未知错误不可描述。
@ -5404,7 +5524,7 @@ int hg_scanner::image_configuration(SCANCONF& ic)
ic.dogeardistabce = fractate_level_;
ic.fadeback = image_prc_param_.bits.erase_bakground;
ic.fadebackrange = erase_bkg_range_;
ic.isuoloadexceptionimage = pid_ == 0x0439 ? false : (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) == DOUBLE_PAPER_SAVE_IMG;
ic.isuoloadexceptionimage = (double_paper_handle_ == DOUBLE_PAPEAR_STOP) ? false : true;
adjust_filling_hole(&ic);
ic.fold_concatmode = fold_type_;

View File

@ -264,7 +264,7 @@ protected:
virtual int on_is_auto_paper(bool isautopaper) = 0; //待纸扫描
virtual int on_cis_get_image(bool type) = 0;
virtual int on_process_double_paper(bool type) = 0; //双张图像校验
virtual int on_detect_lens_dirty(bool type); //检测镜头脏污
virtual int on_detect_lens_dirty(bool &type); //检测镜头脏污
virtual int on_set_period(int val); //PWM占空比
protected:
@ -393,8 +393,8 @@ protected:
bool firmware_sup_morr_; //固件支持 摩尔纹 139 239-3C0518
bool firmware_sup_color_fill_; //固件支持 色彩填充 139 239 439 -3C
bool firmware_sup_history_cnt; //固件支持 清除历史张数 3288 G300 220303
bool firmware_sup_double_check; //固件支持 双张校验 231021
bool firmware_sup_dirty_check; //固件支持 脏污检测 231021
bool firmware_sup_double_check; //固件支持 双张校验 231027
bool firmware_sup_dirty_check; //固件支持 脏污检测 231027
bool firmware_sup_backup_restore; //固件支持 备份还原 231021
bool firmware_sup_boardTime; //固件支持 板级时间校验 231021
bool firmware_sup_device_7010; //G300 设备但是7010 2023/9/21
@ -439,6 +439,7 @@ protected:
int save_final_image(hg_imgproc::LPIMGHEAD head, void* buf, uint32_t id = -1);
void adjust_filling_hole(LPSCANCONF conf);
int wait_one_image_from_start(bool& handled);
////////////////////////////////////////////////////////////////
// 新增自定义伽玛曲线及扫描区域属性 - 2022-05-05
@ -461,6 +462,9 @@ protected:
bool is_white_0_; // 是否0代表白色
public:
int start(void);
int stop(void);
void set_ui_callback(sane_callback cb, bool enable_async_io);
void set_dev_family(const char* family);
void set_read_over_with_no_data(bool no_data);
@ -487,10 +491,10 @@ public:
int is_running(void); // return thread_running
public:
virtual int start(void);
virtual int do_start(void) = 0;
virtual int do_stop(void) = 0;
virtual int get_image_info(SANE_Parameters* ii, int len);
virtual int read_image_data(unsigned char* buf, int* len);
virtual int stop(void);
virtual int reset(void);
virtual int device_io_control(unsigned long code, void* data, unsigned* len);
virtual int discard_all_images(void) = 0;

View File

@ -265,7 +265,7 @@ void hg_scanner_200::thread_handle_usb_read(void)
}
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_description(status_));
}
int hg_scanner_200::start(void)
int hg_scanner_200::do_start(void)
{
bool handled = false;
int ret = try_third_app_handle_start(handled),
@ -318,7 +318,7 @@ int hg_scanner_200::start(void)
return ret;
}
int hg_scanner_200::stop(void)
int hg_scanner_200::do_stop(void)
{
int ret = SCANNER_ERR_OK;
@ -337,7 +337,8 @@ int hg_scanner_200::stop(void)
{
status_ = SCANNER_ERR_DEVICE_STOPPED;
}
return status_;
return ret;
}
int hg_scanner_200::writeusb(USBCB &usb)
{

View File

@ -50,8 +50,8 @@ public:
~hg_scanner_200();
public:
virtual int start(void)override;
virtual int stop(void)override;
virtual int do_start(void) override;
virtual int do_stop(void) override;
private:
int initdevice();

File diff suppressed because one or more lines are too long

View File

@ -76,7 +76,7 @@ protected:
virtual int on_is_auto_paper(bool isautopaper)override; //待纸扫描
virtual int on_cis_get_image(bool isautopaper) override; //cis 原图获取
virtual int on_process_double_paper(bool type) override; //双张图像校验
virtual int on_detect_lens_dirty(bool type) override; //检测镜头脏污
virtual int on_detect_lens_dirty(bool &type) override; //检测镜头脏污
public:
@ -86,8 +86,8 @@ public:
public:
//virtual int get_image_info(IMG_PARAM* ii) override;
//virtual int read_image_data(unsigned char* buf, int* len) override;
virtual int start(void) override;
virtual int stop(void) override;
virtual int do_start(void) override;
virtual int do_stop(void) override;
virtual int reset(void) override;
virtual int device_io_control(unsigned long code, void* data, unsigned* len) override;
virtual int get_roller_life(void) override;

File diff suppressed because one or more lines are too long

View File

@ -45,14 +45,15 @@ protected:
virtual int on_is_auto_paper(bool isautopaper)override; //待纸扫描
virtual int on_cis_get_image(bool isautopaper) override; //cis 原图获取
virtual int on_process_double_paper(bool type) override; //双张图像校验
virtual int on_detect_lens_dirty(bool type) override; //检测镜头脏污
virtual int on_detect_lens_dirty(bool &type) override; //检测镜头脏污
public:
hg_scanner_300(const char* dev_name,int pid, usb_io* io);
~hg_scanner_300();
public:
virtual int start(void)override;
virtual int stop(void)override;
virtual int do_start(void) override;
virtual int do_stop(void) override;
private:
int set_kernelsnap_ver();
int agreement(TwSS tw,int align);

View File

@ -1020,7 +1020,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
VLOG_MINI_1(LOG_LEVEL_FATAL, "V4L2 error: %d\n", info->Code);
{
bool cancel = user_cancel_;
stop();
do_stop();
user_cancel_ = cancel;
go = false;
}
@ -1052,7 +1052,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
}
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_));
}
int hg_scanner_302::start(void)
int hg_scanner_302::do_start(void)
{
bool handled = false;
@ -1129,7 +1129,7 @@ int hg_scanner_302::start(void)
return ret;
}
int hg_scanner_302::stop(void)
int hg_scanner_302::do_stop(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK;
@ -1139,7 +1139,7 @@ int hg_scanner_302::stop(void)
// io_->set_timeout(500);
//final_imgs_.clear();
return status_;
return ret;
}
int hg_scanner_302::reset(void)
{

View File

@ -83,10 +83,9 @@ public:
~hg_scanner_302();
public:
virtual int start(void) override;
//virtual int get_image_info(IMG_PARAM* ii) override;
//virtual int read_image_data(unsigned char* buf, int* len) override;
virtual int stop(void) override;
virtual int do_start(void) override;
virtual int do_stop(void) override;
virtual int reset(void) override;
virtual int device_io_control(unsigned long code, void* data, unsigned* len) override;

View File

@ -293,7 +293,7 @@ int hg_scanner_306::get_roller_life(void)
{
return pid_ == 300 ? 150000 : 200000;
}
int hg_scanner_306::start(void)
int hg_scanner_306::do_start(void)
{
bool handled = false;
int ret = try_third_app_handle_start(handled), //sane调用是每次都会调用一次start和stop
@ -367,7 +367,7 @@ int hg_scanner_306::start(void)
VLOG_MINI_1(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret));
return ret;
}
int hg_scanner_306::stop(void)
int hg_scanner_306::do_stop(void)
{
int ret = SCANNER_ERR_OK;
@ -390,7 +390,7 @@ int hg_scanner_306::stop(void)
}
//final_imgs_.clear();
return status_;
return ret;
}
int hg_scanner_306::writeusb(USBCB &usb)
{

View File

@ -52,8 +52,9 @@ public:
hg_scanner_306(const char* dev_name,int pid, usb_io* io);
~hg_scanner_306();
public:
virtual int start(void)override;
virtual int stop(void)override;
virtual int do_start(void) override;
virtual int do_stop(void) override;
private:
int set_kernelsnap_ver();
int agreement(TwSS tw,int align);