新增tesseract文字方向识别 调整整个图像处理流程

This commit is contained in:
13038267101 2022-11-01 17:20:57 +08:00
parent e5ccb09174
commit d5d27bd93c
18 changed files with 273 additions and 1273 deletions

View File

@ -146,6 +146,7 @@ hg_scanner::hg_scanner(ScannerSerial serial
wait_usb_result_.set_debug_info("start");
thread_usb_read_.reset(new std::thread(&hg_scanner::thread_handle_usb, this));
thread_img_handle_.reset(new std::thread(&hg_scanner::thread_image_handle, this));
ImagePrc_pHandle_ = hg_imgproc::init(pid_);;
}
hg_scanner::~hg_scanner()
{
@ -156,6 +157,7 @@ hg_scanner::~hg_scanner()
if (thread_img_handle_.get() && thread_img_handle_->joinable())
thread_img_handle_->join();
delete custom_gamma_val_;
hg_imgproc::release(ImagePrc_pHandle_);
name_.insert(0, "\350\256\276\345\244\207\342\200\234");
name_ += "\342\200\235\345\267\262\347\273\217\345\205\263\351\227\255\343\200\202";
@ -768,9 +770,19 @@ void hg_scanner::thread_handle_image_process(void)
if (tiny_buffer->swap())
{
try
{
if (ImagePrc_pHandle_)
{
image_process(tiny_buffer);
}
else
{
VLOG_MINI_1(LOG_LEVEL_FATAL, "Get Image Process is NULL pid is %d.\n",pid_);
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
stop();
break;
}
}
catch (...)
{
VLOG_MINI_1(LOG_LEVEL_FATAL, "FATAL: Insufficient memory when proecss image with %d bytes.\n", tiny_buffer->size());
@ -1892,9 +1904,17 @@ int hg_scanner::setting_text_direction(int sn, void* data)
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Change text direction from '%s' to '%s' = %s\n", text_direction_string(image_prc_param_.bits.text_direction).c_str()
, (char*)data, hg_scanner_err_name(ret));
image_prc_param_.bits.text_direction = match_best_text_direction(str, NULL);
if (!exact)
strcpy((char*)data, str.c_str());
if (image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO && ImagePrc_pHandle_)
{
hg_imgproc::init_auto_txt_hanld(ImagePrc_pHandle_);
}
else if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO && ImagePrc_pHandle_)
{
hg_imgproc::free_auto_txt_hanld(ImagePrc_pHandle_);
}
return ret;
}
int hg_scanner::setting_rotate_bkg_180(int sn, void* data)
@ -2314,7 +2334,7 @@ void hg_scanner::adjust_color(hg_imgproc::HIMGPRC handle)
}
hg_imgproc::adjust_color(handle, buffer1, tableLength);
}
hg_imgproc::HIMGPRC hg_scanner::get_image_process_object(int model)
hg_imgproc::IMGPRCPARAM hg_scanner::get_image_process_object(int model)
{
hg_imgproc::IMGPRCPARAM param;
hg_imgproc::HIMGPRC handle = nullptr;
@ -2331,11 +2351,10 @@ hg_imgproc::HIMGPRC hg_scanner::get_image_process_object(int model)
img_conf_.brightness = (float)bright_;
img_conf_.contrast = (float)contrast_;
handle = hg_imgproc::init(&img_conf_, &param, model);
img_conf_.brightness = bright;
img_conf_.contrast = contrast;
return handle;
return param;
}
SANE_Image_Statu hg_scanner::last_usb_image_statu(int err)
{
@ -3597,71 +3616,75 @@ int hg_scanner::get_scan_is_sleep(void)
void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer)
{
if (!buffer.get() || !ImagePrc_pHandle_)
{
return;
}
int ret = SCANNER_ERR_OK;
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGPRCPARAM param = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
hg_imgproc::load_buffer(handle, buffer);
hg_imgproc::decode(handle, pid_);
(this->*dump_img_)(handle, "decode");
hg_imgproc::load_buffer(ImagePrc_pHandle_, buffer);
hg_imgproc::decode(ImagePrc_pHandle_, pid_, &img_conf_, &param);
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
if ((isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole) && (pid_ != 0x239 && pid_ != 0x439))
{
ret = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
(this->*dump_img_)(handle, "fillhole");
ret = hg_imgproc::fillhole(ImagePrc_pHandle_, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
(this->*dump_img_)(ImagePrc_pHandle_, "fillhole");
}
if (pid_ != 0x239 && pid_ != 0x439)
{
ret = hg_imgproc::auto_crop(handle);
(this->*dump_img_)(handle, "auto_crop");
ret = hg_imgproc::auto_crop(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "auto_crop");
}
if ((img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince) && (pid_ != 0x239 && pid_ != 0x439))
{
ret = hg_imgproc::discardBlank(handle);
(this->*dump_img_)(handle, "discardBlank");
ret = hg_imgproc::discardBlank(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "discardBlank");
}
if (img_conf_.fadeback) //239
{
hg_imgproc::fadeback(handle);
(this->*dump_img_)(handle, "fadeback");
hg_imgproc::fadeback(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "fadeback");
}
if ((img_conf_.resolution_dst != img_conf_.resolution_native) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::resolution_change(handle);
(this->*dump_img_)(handle, "resolution_change");
hg_imgproc::resolution_change(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "resolution_change");
}
if ((img_conf_.cropRect.enable && !img_conf_.is_autocrop) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::croprect(handle);
(this->*dump_img_)(handle, "resolution_change");
hg_imgproc::croprect(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "resolution_change");
}
if ((img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY)) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::channel(handle);
(this->*dump_img_)(handle, "channel");
hg_imgproc::channel(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "channel");
}
if (pid_ != 0x239 && pid_ != 0x439)
{
adjust_color(handle);
(this->*dump_img_)(handle, "channel");
adjust_color(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "channel");
}
if ((img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::answerSheetFilterRed(handle);
(this->*dump_img_)(handle, "answerSheetFilterRed");
hg_imgproc::answerSheetFilterRed(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "answerSheetFilterRed");
}
if ((img_conf_.refuseInflow) && (pid_ != 0x239 && pid_ != 0x439))
@ -3679,95 +3702,96 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer)
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle, lv);
(this->*dump_img_)(handle, "antiInflow");
hg_imgproc::antiInflow(ImagePrc_pHandle_, lv);
(this->*dump_img_)(ImagePrc_pHandle_, "antiInflow");
}
if ((img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::colorCorrection(handle);
(this->*dump_img_)(handle, "colorCorrection");
hg_imgproc::colorCorrection(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "colorCorrection");
}
if (((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext)) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::orentation(handle);
(this->*dump_img_)(handle, "orentation");
hg_imgproc::orentation(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "orentation");
}
if ((img_conf_.removeMorr) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::textureRemove(handle);
(this->*dump_img_)(handle, "textureRemove");
hg_imgproc::textureRemove(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "textureRemove");
}
if ((img_conf_.detachnoise.is_detachnoise) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::nosieDetach(handle);
(this->*dump_img_)(handle, "nosieDetach");
hg_imgproc::nosieDetach(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "nosieDetach");
}
if ((img_conf_.pixtype == COLOR_MODE_BLACK_WHITE) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::errorextention(handle);
(this->*dump_img_)(handle, "errorextention");
hg_imgproc::errorextention(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "errorextention");
}
if ((img_conf_.en_fold && pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::fold(handle);
(this->*dump_img_)(handle, "fold");
hg_imgproc::fold(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "fold");
}
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)//239
{
err = hg_imgproc::multi_out_red(handle);
(this->*dump_img_)(handle, "multi_out_red");
err = hg_imgproc::multi_out_red(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "multi_out_red");
}
if ((img_conf_.sharpen) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::sharpenType(handle);
(this->*dump_img_)(handle, "sharpenType");
hg_imgproc::sharpenType(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "sharpenType");
}
if (image_prc_param_.bits.split) //239
{
split3399_++;
err = hg_imgproc::split(handle,split3399_);
(this->*dump_img_)(handle, "split");
err = hg_imgproc::split(ImagePrc_pHandle_,split3399_);
(this->*dump_img_)(ImagePrc_pHandle_, "split");
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red || !is_multiout) //239
{
if (img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle, img_conf_.automaticcolortype);
(this->*dump_img_)(handle, "auto_matic_color");
hg_imgproc::auto_matic_color(ImagePrc_pHandle_, img_conf_.automaticcolortype);
(this->*dump_img_)(ImagePrc_pHandle_, "auto_matic_color");
}
}
if (img_conf_.is_autotext)//239
{
hg_imgproc::ocr_auto_txtdirect(handle);
(this->*dump_img_)(handle, "ocr_auto_txtdirect");
//hg_imgproc::ocr_auto_txtdirect(ImagePrc_pHandle_);
hg_imgproc::tesseract_auto_txtdirect(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "ocr_auto_txtdirect");
}
if ((is_quality_ == IMG_SPEED && (pid_ == 0x239 || pid_ == 0x439)) && resolution_ >= 300)//239
{
err = hg_imgproc::quality(handle, resolution_);
(this->*dump_img_)(handle, "quality");
err = hg_imgproc::quality(ImagePrc_pHandle_, resolution_);
(this->*dump_img_)(ImagePrc_pHandle_, "quality");
}
if (is_multiout)//239
{
int multi_out = img_conf_.multiOutput;
err = hg_imgproc::multi_out(handle, multi_out);
(this->*dump_img_)(handle, "multi_out");
err = hg_imgproc::multi_out(ImagePrc_pHandle_, multi_out);
(this->*dump_img_)(ImagePrc_pHandle_, "multi_out");
}
hg_imgproc::final(handle);
(this->*dump_img_)(handle, "final");
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
hg_imgproc::final(ImagePrc_pHandle_);
(this->*dump_img_)(ImagePrc_pHandle_, "final");
while (hg_imgproc::get_final_data(ImagePrc_pHandle_, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
@ -3776,7 +3800,7 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer)
{
std::vector<unsigned char>bmpdata;
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
hg_imgproc::imgtypechange(handle, img_type_, buf, bmpdata);
hg_imgproc::imgtypechange(ImagePrc_pHandle_, img_type_, buf, bmpdata);
if (bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
@ -3790,5 +3814,4 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer)
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}

View File

@ -194,9 +194,9 @@ protected:
// adjust color or apply custom gamma
void adjust_color(hg_imgproc::HIMGPRC handle);
hg_imgproc::HIMGPRC get_image_process_object(int model);
hg_imgproc::IMGPRCPARAM get_image_process_object(int model);
SANE_Image_Statu last_usb_image_statu(int err);
hg_imgproc::HIMGPRC ImagePrc_pHandle_;
protected:
ScannerSerial serial_;
volatile bool run_;

View File

@ -413,184 +413,6 @@ int hg_scanner_200::get_img_data(unsigned int bytes, SANE_Image_Statu statu)
return ret;
}
void hg_scanner_200::image_process(std::shared_ptr<tiny_buffer>& buffer)
{
int ret = SCANNER_ERR_OK;
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
hg_imgproc::load_buffer(handle, buffer);
hg_imgproc::decode(handle,pid_);
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
ret = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold,isremove_left_hole_threshold,isremove_right_hole_threshold);
}
/////////////////////////////////////111111111111111111111111111//////////////////////////////////
ret = hg_imgproc::auto_crop(handle);
if (img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince)
{
ret = hg_imgproc::discardBlank(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"丢弃空白页开启\r\n");
}
if(img_conf_.fadeback)
{
hg_imgproc::fadeback(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"背景除色开启\r\n");
}
if (img_conf_.resolution_dst != img_conf_.resolution_native)
{
hg_imgproc::resolution_change(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"dpi改变开启\r\n");
}
if (img_conf_.cropRect.enable && !img_conf_.is_autocrop)
{
hg_imgproc::croprect(handle);
//printf("手动裁图开启\r\n");
}
if (img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY))
{
hg_imgproc::channel(handle);
//printf("除色开启\r\n");
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除色开启\r\n");
}
/////////////////////////////////////2222222222222222222222222222222222222//////////////////////////////////
adjust_color(handle);
if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect)
{
hg_imgproc::answerSheetFilterRed(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"答题卡出红开启\r\n");
}
if (img_conf_.refuseInflow)
{
int lv = 5;
if (image_prc_param_.bits.is_permeate_lv_ == 0)
lv = 5;
else if (image_prc_param_.bits.is_permeate_lv_ == 1)
lv = 15;
else if (image_prc_param_.bits.is_permeate_lv_ == 2)
lv = 25;
else if (image_prc_param_.bits.is_permeate_lv_ == 3)
lv = 35;
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle,lv);
}
if (img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::colorCorrection(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"颜色校正开启\r\n");
}
if ((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext))
{
hg_imgproc::orentation(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"自动旋转开启\r\n");
}
if (img_conf_.removeMorr)
{
hg_imgproc::textureRemove(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除摩尔纹开启\r\n");
}
if (img_conf_.detachnoise.is_detachnoise)
{
hg_imgproc::nosieDetach(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"噪点优化开启\r\n");
}
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::errorextention(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"黑白图处理开启\r\n");
}
if (img_conf_.en_fold)
{
hg_imgproc::fold(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"对折开启\r\n");
}
///////////////////////////////////
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
{
err = hg_imgproc::multi_out_red(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"多流出红开启\r\n");
}
if (img_conf_.sharpen)
{
hg_imgproc::sharpenType(handle);
}
if (img_conf_.splitImage)
{
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,-1);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"图像拆分开启\r\n");
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red || !is_multiout)
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"颜色自动识别开启\r\n");
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = image_prc_param_.bits.multi_out;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
std::vector<unsigned char>bmpdata;
if(!img_type_.empty())
{
hg_imgproc::imgtypechange(handle, img_type_, buf, bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_200::writedown_device_configuration(bool type,setting_hardware::HGSCANCONF_DSP *d)
{

View File

@ -26,7 +26,6 @@ class hg_scanner_200 : public hg_scanner
protected:
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff) ;
virtual int on_color_mode_changed(int& color_mode); // COLOR_MODE_xxx

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,6 @@ protected:
virtual void on_device_reconnected(void) override;
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff) ;
public:
hg_scanner_239(const char* dev_name, int pid,usb_io* io);

View File

@ -379,186 +379,6 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
return ret;
}
void hg_scanner_300::image_process(std::shared_ptr<tiny_buffer>& buffer)
{
int ret = SCANNER_ERR_OK;
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
hg_imgproc::load_buffer(handle, buffer);
hg_imgproc::decode(handle,pid_);
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
ret = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
}
/////////////////////////////////////111111111111111111111111111//////////////////////////////////
ret = hg_imgproc::auto_crop(handle); //首次必须先调用这个算法
if (img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince)
{
ret = hg_imgproc::discardBlank(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"丢弃空白页开启\r\n");
}
if(img_conf_.fadeback)
{
hg_imgproc::fadeback(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"背景除色开启\r\n");
}
if (img_conf_.resolution_dst != img_conf_.resolution_native)
{
hg_imgproc::resolution_change(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"dpi改变开启\r\n");
}
if (img_conf_.cropRect.enable && !img_conf_.is_autocrop)
{
hg_imgproc::croprect(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"手动裁图开启\r\n");
}
if (img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY))
{
hg_imgproc::channel(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除色开启\r\n");
}
/////////////////////////////////////2222222222222222222222222222222222222//////////////////////////////////
adjust_color(handle);
if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect)
{
hg_imgproc::answerSheetFilterRed(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"答题卡出红开启\r\n");
}
if (img_conf_.refuseInflow)
{
int lv = 5;
if (image_prc_param_.bits.is_permeate_lv_ == 0)
lv = 5;
else if (image_prc_param_.bits.is_permeate_lv_ == 1)
lv = 15;
else if (image_prc_param_.bits.is_permeate_lv_ == 2)
lv = 25;
else if (image_prc_param_.bits.is_permeate_lv_ == 3)
lv = 35;
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle,lv);
}
if (img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::colorCorrection(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"颜色校正开启\r\n");
}
if ((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext))
{
hg_imgproc::orentation(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"自动旋转开启\r\n");
}
if (img_conf_.removeMorr)
{
hg_imgproc::textureRemove(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除摩尔纹开启\r\n");
}
if (img_conf_.detachnoise.is_detachnoise)
{
hg_imgproc::nosieDetach(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"噪点优化开启\r\n");
}
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::errorextention(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"黑白图处理开启\r\n");
}
if (img_conf_.en_fold)
{
hg_imgproc::fold(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"对折开启\r\n");
}
///////////////////////////////////
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
{
err = hg_imgproc::multi_out_red(handle);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"多流出红开启\r\n");
}
if (img_conf_.sharpen)
{
hg_imgproc::sharpenType(handle);
}
if (img_conf_.splitImage)
{
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,-1);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"图像拆分开启\r\n");
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red || !is_multiout)
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
//HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"颜色自动识别开启\r\n");
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = img_conf_.multiOutput;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_300::writedown_device_configuration(bool type,setting_hardware::HGSCANCONF_3288 *d)
{

View File

@ -25,8 +25,6 @@ class hg_scanner_300 : public hg_scanner
protected:
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff) ;
virtual int on_color_mode_changed(int& color_mode); // COLOR_MODE_xxx
virtual int on_paper_changed(int& paper); // PAPER_xxx

View File

@ -616,210 +616,6 @@ void hg_scanner_302::init_version(void)
else
is_kernelsnap_211209_ = false;
}
void hg_scanner_302::image_process(std::shared_ptr<tiny_buffer>& buff)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size());
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
err = hg_imgproc::load_buffer(handle, buff);
err = hg_imgproc::decode(handle,pid_);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Image process parameter: 0x%x%08x, multi out: %s\n", ((unsigned int*)&image_prc_param_.value)[1], ((unsigned int*)&image_prc_param_.value)[0], is_multiout ? "true" : "false");
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
err = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
}
/////////////////////////////////////111111111111111111111111111//////////////////////////////////
err = hg_imgproc::auto_crop(handle);
if (img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince)
{
err = hg_imgproc::discardBlank(handle);
printf("丢弃空白页开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "丢弃空白页开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.fadeback)
{
hg_imgproc::fadeback(handle);
//printf("背景除色开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "背景除色开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.resolution_dst != img_conf_.resolution_native)
{
hg_imgproc::resolution_change(handle);
//printf("dpi改变开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "dpi改变开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.cropRect.enable && !img_conf_.is_autocrop)
{
hg_imgproc::croprect(handle);
//printf("手动裁图开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "手动裁图开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY))
{
printf("除色开启\r\n");
hg_imgproc::channel(handle);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除色开启:%s\n",hg_scanner_err_name(ret));
}
/////////////////////////////////////2222222222222222222222222222222222222//////////////////////////////////
adjust_color(handle);
if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect)
{
hg_imgproc::answerSheetFilterRed(handle);
//printf("答题卡出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "答题卡出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.refuseInflow)
{
int lv = 5;
if (image_prc_param_.bits.is_permeate_lv_ == 0)
lv = 5;
else if (image_prc_param_.bits.is_permeate_lv_ == 1)
lv = 15;
else if (image_prc_param_.bits.is_permeate_lv_ == 2)
lv = 25;
else if (image_prc_param_.bits.is_permeate_lv_ == 3)
lv = 35;
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle, lv);
}
if (img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::colorCorrection(handle);
//printf("颜色校正开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "颜色校正开启:%s\n",hg_scanner_err_name(ret));
}
if ((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext))
{
printf("手动旋转开启\r\n");
hg_imgproc::orentation(handle);
}
if (img_conf_.removeMorr)
{
hg_imgproc::textureRemove(handle);
//printf("除摩尔纹开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除摩尔纹开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.detachnoise.is_detachnoise)
{
hg_imgproc::nosieDetach(handle);
//printf("噪点优化开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "噪点优化开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::errorextention(handle);
//printf("黑白图处理开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "黑白图处理开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.en_fold)
{
hg_imgproc::fold(handle);
//printf("对折开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "对折开启:%s\n",hg_scanner_err_name(ret));
}
///////////////////////////////////
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
{
err = hg_imgproc::multi_out_red(handle);
//printf("多流出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "多流出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.sharpen)
{
hg_imgproc::sharpenType(handle);
}
if(image_prc_param_.bits.erase_bakground)
{
err = hg_imgproc::fadeback(handle);
}
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
err = hg_imgproc::multi_out_red(handle);
if (img_conf_.splitImage)
{
//split3399_++;
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,-1);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red || !is_multiout)
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
if (is_quality_ == IMG_SPEED && resolution_ >= 300)
{
err = hg_imgproc::quality(handle,resolution_);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = image_prc_param_.bits.multi_out;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_302::get_device_sleep_stautus(void)
{

View File

@ -71,7 +71,6 @@ protected:
virtual void on_device_reconnected(void) override;
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff) ;
public:
hg_scanner_302(const char* dev_name, int pid,usb_io* io);

View File

@ -375,202 +375,6 @@ int hg_scanner_400::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
return ret;
}
void hg_scanner_400::image_process(std::shared_ptr<tiny_buffer>& buffer)
{
int ret = SCANNER_ERR_OK;
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
hg_imgproc::load_buffer(handle, buffer);
hg_imgproc::decode(handle,pid_);
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
ret = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
}
/////////////////////////////////////111111111111111111111111111//////////////////////////////////
ret = hg_imgproc::auto_crop(handle);
if (img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince)
{
ret = hg_imgproc::discardBlank(handle);
printf("丢弃空白页开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "丢弃空白页开启:%s\n",hg_scanner_err_name(ret));
}
if(img_conf_.fadeback)
{
hg_imgproc::fadeback(handle);
//printf("背景除色开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "背景除色开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.resolution_dst != img_conf_.resolution_native)
{
hg_imgproc::resolution_change(handle);
//printf("dpi改变开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "dpi改变开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.cropRect.enable && !img_conf_.is_autocrop)
{
hg_imgproc::croprect(handle);
//printf("手动裁图开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "手动裁图开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY))
{
printf("除色开启\r\n");
hg_imgproc::channel(handle);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除色开启:%s\n",hg_scanner_err_name(ret));
}
/////////////////////////////////////2222222222222222222222222222222222222//////////////////////////////////
adjust_color(handle);
if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect)
{
hg_imgproc::answerSheetFilterRed(handle);
//printf("答题卡出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "答题卡出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.refuseInflow)
{
int lv = 5;
if (image_prc_param_.bits.is_permeate_lv_ == 0)
lv = 5;
else if (image_prc_param_.bits.is_permeate_lv_ == 1)
lv = 15;
else if (image_prc_param_.bits.is_permeate_lv_ == 2)
lv = 25;
else if (image_prc_param_.bits.is_permeate_lv_ == 3)
lv = 35;
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle,lv);
}
if (img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::colorCorrection(handle);
//printf("颜色校正开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "颜色校正开启:%s\n",hg_scanner_err_name(ret));
}
if ((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext))
{
printf("手动旋转开启\r\n");
hg_imgproc::orentation(handle);
}
if (img_conf_.removeMorr)
{
hg_imgproc::textureRemove(handle);
//printf("除摩尔纹开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除摩尔纹开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.detachnoise.is_detachnoise)
{
hg_imgproc::nosieDetach(handle);
//printf("噪点优化开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "噪点优化开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::errorextention(handle);
//printf("黑白图处理开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "黑白图处理开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.en_fold)
{
hg_imgproc::fold(handle);
//printf("对折开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "对折开启:%s\n",hg_scanner_err_name(ret));
}
///////////////////////////////////
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
{
err = hg_imgproc::multi_out_red(handle);
//printf("多流出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "多流出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.sharpen)
{
hg_imgproc::sharpenType(handle);
}
if (img_conf_.splitImage)
{
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,-1);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "图像拆分开启:%s\n",hg_scanner_err_name(ret));
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red || !is_multiout)
{
if(img_conf_.automaticcolor)
{
ret = hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "颜色自动识别模式开启:%s\n",hg_scanner_err_name(ret));
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别开启\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = image_prc_param_.bits.multi_out;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_400::writedown_device_configuration(bool type,setting_hardware::HGSCANCONF_3288 *d)
{
if (!type)

View File

@ -25,8 +25,6 @@ class hg_scanner_400 : public hg_scanner
protected:
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff) ;
virtual int on_color_mode_changed(int& color_mode); // COLOR_MODE_xxx
virtual int on_paper_changed(int& paper); // PAPER_xxx

View File

@ -494,211 +494,6 @@ void hg_scanner_402::init_version(void)
else
is_kernelsnap_211209_ = false;
}
void hg_scanner_402::image_process(std::shared_ptr<tiny_buffer>& buff)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size());
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
err = hg_imgproc::load_buffer(handle, buff);
err = hg_imgproc::decode(handle,pid_);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Image process parameter: 0x%x%08x, multi out: %s\n", ((unsigned int*)&image_prc_param_.value)[1], ((unsigned int*)&image_prc_param_.value)[0], is_multiout ? "true" : "false");
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
err = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
}
/////////////////////////////////////111111111111111111111111111//////////////////////////////////
err = hg_imgproc::auto_crop(handle);
if (img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince)
{
err = hg_imgproc::discardBlank(handle);
printf("丢弃空白页开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "丢弃空白页开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.fadeback)
{
hg_imgproc::fadeback(handle);
//printf("背景除色开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "背景除色开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.resolution_dst != img_conf_.resolution_native)
{
hg_imgproc::resolution_change(handle);
//printf("dpi改变开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "dpi改变开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.cropRect.enable && !img_conf_.is_autocrop)
{
hg_imgproc::croprect(handle);
//printf("手动裁图开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "手动裁图开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.filter != ColorFilter::FILTER_NONE && (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY))
{
printf("除色开启\r\n");
hg_imgproc::channel(handle);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除色开启:%s\n",hg_scanner_err_name(ret));
}
/////////////////////////////////////2222222222222222222222222222222222222//////////////////////////////////
adjust_color(handle);
if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect)
{
hg_imgproc::answerSheetFilterRed(handle);
//printf("答题卡出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "答题卡出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.refuseInflow)
{
int lv = 5;
if (image_prc_param_.bits.is_permeate_lv_ == 0)
lv = 5;
else if (image_prc_param_.bits.is_permeate_lv_ == 1)
lv = 15;
else if (image_prc_param_.bits.is_permeate_lv_ == 2)
lv = 25;
else if (image_prc_param_.bits.is_permeate_lv_ == 3)
lv = 35;
else if (image_prc_param_.bits.is_permeate_lv_ == 4)
lv = 45;
hg_imgproc::antiInflow(handle, lv);
}
if (img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::colorCorrection(handle);
//printf("颜色校正开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "颜色校正开启:%s\n",hg_scanner_err_name(ret));
}
if ((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext))
{
printf("手动旋转开启\r\n");
hg_imgproc::orentation(handle);
}
if (img_conf_.removeMorr)
{
hg_imgproc::textureRemove(handle);
//printf("除摩尔纹开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除摩尔纹开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.detachnoise.is_detachnoise)
{
hg_imgproc::nosieDetach(handle);
//printf("噪点优化开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "噪点优化开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE)
{
hg_imgproc::errorextention(handle);
//printf("黑白图处理开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "黑白图处理开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.en_fold)
{
hg_imgproc::fold(handle);
//printf("对折开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "对折开启:%s\n",hg_scanner_err_name(ret));
}
///////////////////////////////////
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
{
err = hg_imgproc::multi_out_red(handle);
//printf("多流出红开启\r\n");
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "多流出红开启:%s\n",hg_scanner_err_name(ret));
}
if (img_conf_.sharpen)
{
hg_imgproc::sharpenType(handle);
}
if(img_conf_.fadeback)
{
err = hg_imgproc::fadeback(handle);
}
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
err = hg_imgproc::multi_out_red(handle);
if (img_conf_.splitImage)
{
//split3399_++;
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,-1);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
}
if (!img_conf_.splitImage || !img_conf_.multi_output_red|| !is_multiout)
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
if (is_quality_ == IMG_SPEED && resolution_ >= 300)
{
err = hg_imgproc::quality(handle,resolution_);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = img_conf_.multiOutput;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_402::get_device_sleep_stautus(void)
{
int ret =read_register(setting3399::SR_GET_SLEEP_STAUTUS,0);
@ -1785,15 +1580,7 @@ int hg_scanner_402::get_scan_is_sleep()
}
int hg_scanner_402::get_device_log(string &log)
{
int ret = SCANNER_ERR_OK;
int len = log.size();
ret = write_register(setting3399::SR_SET_JSON_PATH, len);
if (ret == SCANNER_ERR_OK)
ret = io_->write_bulk(&log[0],&len);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s\n", log.c_str(),hg_scanner_err_name(ret));
return ret;
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
int hg_scanner_402::notify_sleep()
{

View File

@ -71,7 +71,6 @@ protected:
virtual void on_device_reconnected(void) override;
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff);
public:
hg_scanner_402(const char* dev_name, int pid,usb_io* io);

View File

@ -478,113 +478,6 @@ void hg_scanner_439::init_version(void)
else
is_kernelsnap_211209_ = false;
}
void hg_scanner_439::image_process(std::shared_ptr<tiny_buffer>& buff)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size());
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
index = 0;
void* buf = NULL;
err = hg_imgproc::load_buffer(handle, buff);
err = hg_imgproc::decode(handle,pid_);
if (!isremove_left_hole)
{
isremove_top_hole_threshold = 0;
}
if (!isremove_right_hole)
{
isremove_right_hole_threshold = 0;
}
if (!isremove_top_hole)
{
isremove_top_hole_threshold = 0;
}
if (!isremove_low_hole)
{
isremove_low_hole_threshold = 0;
}
if (isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole)
{
err = hg_imgproc::fillhole(handle, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
}
if(image_prc_param_.bits.erase_bakground)
{
err = hg_imgproc::fadeback(handle);
}
if (image_prc_param_.bits.rid_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
err = hg_imgproc::multi_out_red(handle);
if (image_prc_param_.bits.split)
{
split3399_++;
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
err = hg_imgproc::split(handle,split3399_);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
}
if (!image_prc_param_.bits.split || !image_prc_param_.bits.rid_red || !is_multiout)
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
}
}
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
if (is_quality_ == IMG_SPEED && resolution_ >= 300)
{
err = hg_imgproc::quality(handle,resolution_);
}
//多流输出最后处理
if (is_multiout)
{
int multi_out = image_prc_param_.bits.multi_out;
err = hg_imgproc::multi_out(handle,multi_out);
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK)
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_439::get_device_sleep_stautus(void)
{

View File

@ -68,7 +68,6 @@ protected:
virtual void on_device_reconnected(void) override;
virtual int on_scanner_closing(bool force) override;
virtual void thread_handle_usb_read(void) override;
virtual void image_process(std::shared_ptr<tiny_buffer>& buff);
public:
hg_scanner_439(const char* dev_name, int pid,usb_io* io);

View File

@ -46,7 +46,7 @@ typedef struct BITMAPINFOHEADER
#include "../ImageProcess/ImageApplyHeaders.h"
#include "ImageMultiOutput.h"
#include "PaperSize.h"
#include "imgproc/HGOCR.H"
#if defined(WIN32) || defined(_WIN64)
#include "scanner_manager.h"
#include "ocr/hanwangOCRdetect.h"
@ -59,7 +59,7 @@ extern "C"
#endif
#include "hg_ipc.h"
#include "../ImageProcess/G4Tiff.h"
#include "base/HGImage.h"
#include <opencv2/imgcodecs.hpp>
#define CV_MAT_DEPTH_SET(flags, depth) (((flags) & ~(CV_MAT_DEPTH_MASK)) | (depth & CV_MAT_DEPTH_MASK))
@ -69,11 +69,10 @@ using namespace std;
#define MAKE_INT(a, b, c, d) (GET_BYTE(a) | (GET_BYTE(b) << 8) | (GET_BYTE(c) << 16) | (GET_BYTE(d) << 24))
#define IMAGE_DATA_BUF_CVMAT (void*)MAKE_INT('M', 'T', 'R', 'X')
#define IMAGE_DATA_BUF_CHAR (void*)MAKE_INT('C', 'H', 'A', 'R')
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// functional ...
////////////////////////////////////////////////////////////////////////////////
// NEW£¬flow ...
//
static int num=0;
namespace hg_imgproc
@ -125,6 +124,10 @@ namespace hg_imgproc
return ret;
}
};
typedef unsigned int (*SDKInitialize_)(unsigned int ocrtype, void** pstOcrHandle);
typedef unsigned int (*SDKExit_)(void* pstOcrHandle);
typedef unsigned int (*SDKGetFileDirectImage_)(void* pstOcrHandle, void* image, unsigned int* pDirect);
class imgproc
{
std::string my_path_;
@ -137,6 +140,16 @@ namespace hg_imgproc
Device::PaperSize papersize_;
SANE_Image_Statu img_statu_;
SDKInitialize_ ocrinit_ = NULL;
SDKGetFileDirectImage_ ocrgetdirectimage_ = NULL;
SDKExit_ ocrexit_ = NULL;
void* Auto_Txt_pHanld = NULL;
#ifndef WIN32
void Dynamicopen_pHandle_;
#else
HINSTANCE Dynamicopen_pHandle_;
#endif
void swap_rgb(cv::Mat& mat)
{
@ -156,10 +169,9 @@ namespace hg_imgproc
first += line_bytes;
}
}
// construction
public:
imgproc(LPSCANCONF img_param,LPIMGPRCPARAM param,int pid) : img_conf_(*img_param),param_(*param),pid_(pid),papersize_(pid_)
imgproc(int pid) : pid_(pid),papersize_(pid_)
, img_statu_(SANE_Image_Statu_OK)
{
my_path_ = hg_log::pe_path();
@ -224,14 +236,80 @@ namespace hg_imgproc
return SCANNER_ERR_OK;
}
// image-processing
public:
int decode(int pid)
int init_auto_txt_hanld()
{
int ret = 0;
#ifndef WIN32
#ifdef OEM_HANWANG
string libname = "libHGImgProc.so";
#elif defined(OEM_LISICHENG)
string libname = "libLscImgProc.so";
#else
string libname = "libHwImgProc.so";
#endif
string scanner_path = hg_log::get_module_full_path(libname.c_str());
if (scanner_path.empty())
{
return SCANNER_ERR_OUT_OF_RANGE;
}
printf("auto txt libpath is:%s\r\n", scanner_path.c_str());
if (access(scanner_path.c_str(), F_OK) != 0)
{
return SCANNER_ERR_OUT_OF_RANGE;
}
#endif
#if (!defined WIN32)
Dynamicopen_pHandle_ = dlopen(scanner_path.c_str(), RTLD_LAZY);
if (!handle_)
{
return SCANNER_ERR_OUT_OF_RANGE;
}
ocrinit_ = (SDKInitialize)dlsym(Dynamicopen_pHandle_, "HGImgProc_CreateOCRMgr");
ocrgetdirectimage_ = (SDKGetFileDirectImage_)dlsym(Dynamicopen_pHandle_, "HGImgProc_ImageTextDirectOCR");
ocrexit_ = (SDKExit_)dlsym(Dynamicopen_pHandle_, "HGImgProc_DestroyOCRMgr");
#else
Dynamicopen_pHandle_ = LoadLibrary(L"HGImgProc.dll");
if (Dynamicopen_pHandle_)
{
ocrinit_ = (SDKInitialize_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_CreateOCRMgr");
ocrgetdirectimage_ = (SDKGetFileDirectImage_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_ImageTextDirectOCR");
ocrexit_ = (SDKExit_)GetProcAddress(Dynamicopen_pHandle_, "HGImgProc_DestroyOCRMgr");
}
#endif
ret = ocrinit_(HGIMGPROC_OCRALGO_TESSERACT, &Auto_Txt_pHanld);
return ret;
}
int free_auto_txt_hanld()
{
int ret = 0;
if (Dynamicopen_pHandle_ != NULL)
{
#if (!defined WIN32)
ret = dlclose(Dynamicopen_pHandle_);
#else
ret = FreeLibrary(Dynamicopen_pHandle_);
#endif
Dynamicopen_pHandle_ = NULL;
}
if (Auto_Txt_pHanld != NULL)
{
int ret = ocrexit_(Auto_Txt_pHanld);
Auto_Txt_pHanld = NULL;
}
return ret;
}
int decode(int pid, LPSCANCONF img_param, LPIMGPRCPARAM param)
{
if (!buffer_)
return SCANNER_ERR_NO_DATA;
img_conf_ = *img_param;
param_ = *param;
size_t origin = buffer_->size();
std::vector<std::shared_ptr<std::vector<char>>> buffs;
if(pid == 0x100 || pid == 0x200)
@ -326,8 +404,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int split(int split3399)
{
std::vector<cv::Mat> mats(mats_);
@ -456,7 +532,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int multi_out(int out_type)
{
std::vector<cv::Mat> mats(mats_);
@ -701,7 +776,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int antiInflow(int permeate_lv)
{
int ret = SCANNER_ERR_OK;
@ -721,7 +795,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int colorCorrection()
{
int ret = SCANNER_ERR_OK;
@ -738,7 +811,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int orentation()
{
int ret = SCANNER_ERR_OK;
@ -783,7 +855,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int textureRemove()
{
int ret = SCANNER_ERR_OK;
@ -863,7 +934,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int discardBlank()
{
int ret = SCANNER_ERR_OK;
@ -909,7 +979,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
//对折
int fold()
{
int ret = SCANNER_ERR_OK;
@ -926,8 +995,6 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
//画质
int quality(int dpi_dst)
{
int ret = SCANNER_ERR_OK;
@ -1007,7 +1074,7 @@ namespace hg_imgproc
}
#endif
#if ((!defined x86_64) && (!defined WIN32))
//linux x86_64 暂时没有OCR三方
//linux x86_64
void *hanlde = dlopen(scanner_path.c_str(),RTLD_LAZY);
if(!hanlde)
@ -1027,7 +1094,7 @@ namespace hg_imgproc
ocrgetdirectimage = (SDKGetFileDirectImage)GetProcAddress(handle, "HWOCR_GetFileDirectImage");
ocrexit = (SDKExit)GetProcAddress(handle, "HWOCR_SDKExit");
}
#endif // WIN32 //暂时保留文本方向旋转
#endif // WIN32
#endif
int r = ocrinit(&pHanld);
for (size_t i = 0; i < mats.size(); i++)
@ -1054,6 +1121,51 @@ namespace hg_imgproc
}
return SCANNER_ERR_OK;
}
int tesseract_auto_txtdirect()
{
std::vector<cv::Mat> mats(mats_);
mats_.clear();
unsigned int pDirect = 0,
ret = SCANNER_ERR_OK;
HGImage image;
if (ocrinit_ && ocrgetdirectimage_ && ocrexit_)
{
for (size_t i = 0; i < mats.size(); i++)
{
HGImage b = opencv_to_hgbase_image(mats[i]);
ret = ocrgetdirectimage_(Auto_Txt_pHanld, b, &pDirect);
HGBase_DestroyImage(b);
switch (pDirect)
{
case HGIMGPROC_OCRTEXTDIRECT_ORI:
pDirect = (int)CImageApplyRotation::RotationType::Invalid;
break;
case HGIMGPROC_OCRTEXTDIRECT_RIGHT:
pDirect = (int)CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
break;
case HGIMGPROC_OCRTEXTDIRECT_LEFT:
pDirect = (int)CImageApplyRotation::RotationType::Rotate_90_clockwise;
break;
case HGIMGPROC_OCRTEXTDIRECT_180:
pDirect = (int)CImageApplyRotation::RotationType::Rotate_180;
break;
default:
pDirect = (int)CImageApplyRotation::RotationType::Invalid;
break;
}
CImageApplyRotation(CImageApplyRotation::RotationType(pDirect)).apply(mats[i], false);
mats_.push_back(mats[i]);
}
}
if (mats_.empty())
{
return SCANNER_ERR_NO_DATA;
}
return SCANNER_ERR_OK;
}
int size_detection()
{
int ret = SCANNER_ERR_OK;
@ -1073,6 +1185,26 @@ namespace hg_imgproc
}
HGImage opencv_to_hgbase_image(const cv::Mat& mats)
{
if (mats.empty())
{
//return SCANNER_ERR_NO_DATA;
}
HGImage image;
HGImageInfo info;
info.height = mats.rows;
info.width = mats.cols;
info.origin = 1L;
int bits = mats.channels() == 8 ? 8 : 24;
info.widthStep = mats.step; //opencv ԭʼֵ ÎÞÐè¼ÆËã¶ÔÆë
info.type = mats.channels() == 1 ? HGBASE_IMGTYPE_GRAY : HGBASE_IMGTYPE_BGR;
int ret = HGBase_CreateImageWithData(const_cast<uchar*>(mats.data), &info, &image);
return image;
//return ret;
}
/// <summary>
/// 8位图转1位图
/// </summary>
@ -1081,6 +1213,8 @@ namespace hg_imgproc
/// <param name="reverse">true为反色即黑0白1反之亦然</param>
/// <param name="align">true为四字节对齐</param>
/// <returns>1位图</returns>
///
static cv::Mat convert_8bit_2_1bit(const cv::Mat& image, uchar threshold, bool reverse, bool align)
{
if (image.channels() != 1)
@ -1247,9 +1381,9 @@ namespace hg_imgproc
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// api ...
HIMGPRC init(LPSCANCONF parameter,LPIMGPRCPARAM param,int pid)
HIMGPRC init(int pid)
{
imgproc* obj = new imgproc(parameter,param,pid);
imgproc* obj = new imgproc(pid);
return (HIMGPRC)obj;
}
@ -1262,9 +1396,17 @@ namespace hg_imgproc
return ((imgproc*)himg)->load_file(path_file);
}
int decode(HIMGPRC himg,int pid)
int decode(HIMGPRC himg, int pid, LPSCANCONF img_param, LPIMGPRCPARAM param)
{
return ((imgproc*)himg)->decode(pid);
return ((imgproc*)himg)->decode(pid, img_param, param);
}
int init_auto_txt_hanld(HIMGPRC himg)
{
return ((imgproc*)himg)->init_auto_txt_hanld();
}
int free_auto_txt_hanld(HIMGPRC himg)
{
return ((imgproc*)himg)->free_auto_txt_hanld();
}
int correct_text(HIMGPRC himg)
{
@ -1374,7 +1516,10 @@ namespace hg_imgproc
{
return ((imgproc*)himg)->ocr_auto_txtdirect();
}
int tesseract_auto_txtdirect(HIMGPRC himg)
{
return ((imgproc*)himg)->tesseract_auto_txtdirect();
}
int size_detection(HIMGPRC himg)
{
return ((imgproc*)himg)->size_detection();

View File

@ -161,14 +161,16 @@ namespace hg_imgproc
}IMGHEAD, *LPIMGHEAD;
HIMGPRC init(LPSCANCONF parameter,LPIMGPRCPARAM param,int pid);
HIMGPRC init(int pid);
int load_buffer(HIMGPRC himg,std::shared_ptr<tiny_buffer> buff);
int load_file(HIMGPRC himg, const char* path_file);
//图像数据转换
int decode(HIMGPRC himg,int pid);
int decode(HIMGPRC himg,int pid, LPSCANCONF img_param, LPIMGPRCPARAM param);
int correct_text(HIMGPRC himg);
int init_auto_txt_hanld(HIMGPRC himg);
int free_auto_txt_hanld(HIMGPRC himg);
//拆分
int split(HIMGPRC himg,int split3399);
int fadeback(HIMGPRC himg);
@ -191,11 +193,11 @@ namespace hg_imgproc
int errorextention(HIMGPRC himg);
int discardBlank(HIMGPRC himg);
int answerSheetFilterRed(HIMGPRC himg);
int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata);
int fold(HIMGPRC himg);
int quality(HIMGPRC himg,int dpi);
int ocr_auto_txtdirect(HIMGPRC himg);
int tesseract_auto_txtdirect(HIMGPRC himg);
int size_detection(HIMGPRC himg);
int final(HIMGPRC himg);