新增黑白图像阈值

This commit is contained in:
13038267101 2022-06-28 16:37:45 +08:00
parent bd82f6a22d
commit 7458e8ed8e
4 changed files with 19 additions and 5 deletions

View File

@ -13,8 +13,11 @@ static int ui_default_callback(scanner_handle, int, void*, unsigned int*, void*)
{
return 0;
}
static std::string bmp_821(unsigned char* bits/*bits data*/, int w, int h, int* lbytes, bool line_align_4)
static std::string bmp_821(unsigned char* bits/*bits data*/, int w, int h, int* lbytes, bool line_align_4,int black_white_image_threshold)
{
if (black_white_image_threshold <=0)
black_white_image_threshold =128;
static unsigned int g_bmp8_pallete[] = {
0x00000000, 0x00800000, 0x00008000, 0x00808000, 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0, 0x00c0dcc0, 0x00a6caf0, 0x00402000, 0x00602000, 0x00802000, 0x00a02000, 0x00c02000, 0x00e02000
, 0x00004000, 0x00204000, 0x00404000, 0x00604000, 0x00804000, 0x00a04000, 0x00c04000, 0x00e04000, 0x00006000, 0x00206000, 0x00406000, 0x00606000, 0x00806000, 0x00a06000, 0x00c06000, 0x00e06000
@ -349,6 +352,8 @@ void hg_scanner::set_setting_map(int sn, const char* title)
setting_map_[HG_BASE_SETTING_INDEX_SKEW_CHECK_LEVEL] = sn;
else if (val == OPTION_TITLE_SCTC)
setting_map_[HG_BASE_SETTING_INDEX_COLOR_FILL] = sn;
else if (val ==OPTION_TITLE_HBTXYZ)
setting_map_[HG_BASE_SETTING_INDEX_BLACK_WGITE_THRESHOLD] = sn;
}
void hg_scanner::thread_handle_usb(void)
@ -1557,6 +1562,11 @@ int hg_scanner::setting_color_fill(void *data)
is_color_fill = *((bool *)data);
return SCANNER_ERR_OK;
}
int hg_scanner::setting_black_white_threshold(void *data)
{
black_white_image_threshold_ = *((int *)data);
return SCANNER_ERR_OK;
}
int hg_scanner::on_color_mode_changed(int& color_mode)
{
int ret = SCANNER_ERR_OK;
@ -1895,11 +1905,11 @@ int hg_scanner::save_final_image(hg_imgproc::LPIMGHEAD head, void* buf)
if (img_conf_.pixtype == 0 || (is_1bit && is_multiout))
{
int old = head->line_bytes;
bw = bmp_821((unsigned char*)buf, head->width, head->height, &head->line_bytes, async_io_);
bw = bmp_821((unsigned char*)buf, head->width, head->height, &head->line_bytes, async_io_,black_white_image_threshold_);
buf = &bw[0];
head->channels = head->bits = 1;
head->total_bytes = head->line_bytes * head->height;
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "convert to 1-bit bmp(%d * %d), total = %u, len = %u\n", head->width, head->height, head->total_bytes, bw.length());
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "convert to 1-bit bmp(%d * %d), total = %u, len = %u , black_white_image_threshold_ =%d\n", head->width, head->height, head->total_bytes, bw.length(),black_white_image_threshold_);
}
if (async_io_)
@ -2022,6 +2032,7 @@ int hg_scanner::set_setting(int setting_no, void* data, int len)
, &hg_scanner::setting_multi_out
, &hg_scanner::setting_multi_out_type
, &hg_scanner::setting_color_mode
, &hg_scanner::setting_black_white_threshold
, &hg_scanner::setting_rid_color
, &hg_scanner::setting_rid_multi_red
, &hg_scanner::setting_rid_answer_red

View File

@ -32,6 +32,7 @@ enum
HG_BASE_SETTING_INDEX_MULTI_OUT, // 多流输出
HG_BASE_SETTING_INDEX_MULTI_OUT_TYPE, // 多流输出类型
HG_BASE_SETTING_INDEX_COLOR_MODE, // 颜色模式
HG_BASE_SETTING_INDEX_BLACK_WGITE_THRESHOLD, // 黑白图像阈值
HG_BASE_SETTING_INDEX_ERASE_COLOR, // 除色
HG_BASE_SETTING_INDEX_ERASE_MULTI_OUT_RED, // 多流输出除红
HG_BASE_SETTING_INDEX_ERASE_ANSWER_RED, // 答题卡除红
@ -197,6 +198,7 @@ protected:
int setting_custom_area_bottom(void* data);
int setting_img_quality(void *data);
int setting_color_fill(void *data);
int setting_black_white_threshold(void *data);
virtual int on_color_mode_changed(int& color_mode); // COLOR_MODE_xxx
@ -251,6 +253,7 @@ protected:
int is_quality_; // 画质设置
bool is_color_fill; // 色彩填充
bool is_multiout; // 多流输出
int black_white_image_threshold_; //黑白图像阈值
SCANCONF img_conf_; //此参数外部不做任何改变请在writedown_image_configuration做修改
std::string img_type_;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long