图像处理异常时,保存异常图片;关闭设备之前,调用一次stop
This commit is contained in:
parent
ed5f19354b
commit
d0093d6199
|
@ -1100,7 +1100,9 @@ void hg_scanner::thread_handle_image_process(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
image_process(tiny_buffer, id);
|
invoke_stop = !image_process(tiny_buffer, id);
|
||||||
|
if (invoke_stop)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -1109,13 +1111,14 @@ void hg_scanner::thread_handle_image_process(void)
|
||||||
is_dpi_color_check = false;
|
is_dpi_color_check = false;
|
||||||
stop_fatal_ = SCANNER_ERR_DEVICE_DISTORTION;
|
stop_fatal_ = SCANNER_ERR_DEVICE_DISTORTION;
|
||||||
}
|
}
|
||||||
else if (strstr(e.what(), "Insufficient "))
|
else if (e.what() && strstr(e.what(), "Insufficient "))
|
||||||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||||
else
|
else
|
||||||
stop_fatal_ = SCANNER_ERR_IMAGE_PROC_FATAL;
|
stop_fatal_ = SCANNER_ERR_IMAGE_PROC_FATAL;
|
||||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "[thread_handle_image_process]:is opencv Fatal and stop scanner: %s\n", e.what());
|
VLOG_MINI_1(LOG_LEVEL_FATAL, "[thread_handle_image_process]:is opencv Fatal and stop scanner: %s\n", e.what());
|
||||||
do_stop();
|
do_stop();
|
||||||
invoke_stop = true;
|
invoke_stop = true;
|
||||||
|
save_exception_image(tiny_buffer, id, "opencv-excep");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1125,6 +1128,7 @@ void hg_scanner::thread_handle_image_process(void)
|
||||||
stop_fatal_ = SCANNER_ERR_IMAGE_PROC_FATAL;
|
stop_fatal_ = SCANNER_ERR_IMAGE_PROC_FATAL;
|
||||||
do_stop();
|
do_stop();
|
||||||
invoke_stop = true;
|
invoke_stop = true;
|
||||||
|
save_exception_image(tiny_buffer, id, "opencv-excep");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5174,11 +5178,41 @@ int hg_scanner::get_scan_is_sleep(SANE_Bool& data)
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id)
|
void hg_scanner::save_exception_image(std::shared_ptr<tiny_buffer>& buffer, int sn, const char* desc)
|
||||||
|
{
|
||||||
|
char name[128] = { 0 };
|
||||||
|
FILE* dst = nullptr;
|
||||||
|
|
||||||
|
sprintf(name, "%04d-%s.jpg", sn, desc);
|
||||||
|
dst = fopen((final_path_ + "failedimgs" + PATH_SEPARATOR + name).c_str(), "wb");
|
||||||
|
if (dst)
|
||||||
|
{
|
||||||
|
unsigned int off = 0,
|
||||||
|
len = buffer->size(),
|
||||||
|
size = len;
|
||||||
|
unsigned char* mem = buffer->data(off, &size);
|
||||||
|
while (mem)
|
||||||
|
{
|
||||||
|
fwrite(mem, 1, size, dst);
|
||||||
|
off += size;
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = len - off;
|
||||||
|
mem = buffer->data(off, &size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id)
|
||||||
{
|
{
|
||||||
if (!buffer.get() || !ImagePrc_pHandle_)
|
if (!buffer.get() || !ImagePrc_pHandle_)
|
||||||
{
|
{
|
||||||
return;
|
VLOG_MINI_1(LOG_LEVEL_FATAL, "process image %d fatal: data is empty or image-process object is not initialized, stop scanning ...\n", id);
|
||||||
|
do_stop();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
hg_imgproc::IMGPRCPARAM param = get_image_process_object(pid_);
|
hg_imgproc::IMGPRCPARAM param = get_image_process_object(pid_);
|
||||||
|
@ -5195,34 +5229,10 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id
|
||||||
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
|
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
|
||||||
if (err != SCANNER_ERR_OK)
|
if (err != SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
char name[128] = { 0 };
|
save_exception_image(buffer, id, "decode");
|
||||||
FILE *dst = nullptr;
|
|
||||||
|
|
||||||
sprintf(name, "%04d-decode.jpg", id);
|
|
||||||
dst = fopen((fimg + name).c_str(), "wb");
|
|
||||||
if (dst)
|
|
||||||
{
|
|
||||||
unsigned int off = 0,
|
|
||||||
len = buffer->size(),
|
|
||||||
size = len;
|
|
||||||
unsigned char *mem = buffer->data(off, &size);
|
|
||||||
while (mem)
|
|
||||||
{
|
|
||||||
fwrite(mem, 1, size, dst);
|
|
||||||
off += size;
|
|
||||||
if (off >= len)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size = len - off;
|
|
||||||
mem = buffer->data(off, &size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(dst);
|
|
||||||
}
|
|
||||||
VLOG_MINI_2(LOG_LEVEL_FATAL, "Decode image(%d) with bytes %u failed, stop scanning.\n", id, buffer->size());
|
VLOG_MINI_2(LOG_LEVEL_FATAL, "Decode image(%d) with bytes %u failed, stop scanning.\n", id, buffer->size());
|
||||||
do_stop();
|
do_stop();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dpi_color_check)
|
if (is_dpi_color_check)
|
||||||
|
@ -5460,7 +5470,9 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id
|
||||||
if (bmpdata.empty())
|
if (bmpdata.empty())
|
||||||
{
|
{
|
||||||
status_ = SCANNER_ERR_NO_DATA;
|
status_ = SCANNER_ERR_NO_DATA;
|
||||||
return;
|
VLOG_MINI_1(LOG_LEVEL_FATAL, "process image %d fatal: image data is empty! stop scanning ...\n", id);
|
||||||
|
do_stop();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
buf = bmpdata.data();
|
buf = bmpdata.data();
|
||||||
ih.total_bytes = bmpdata.size();
|
ih.total_bytes = bmpdata.size();
|
||||||
|
@ -5473,6 +5485,8 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id
|
||||||
save_final_image(&ih, buf, id);
|
save_final_image(&ih, buf, id);
|
||||||
id = -1;
|
id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
int hg_scanner::image_configuration(SCANCONF& ic)
|
int hg_scanner::image_configuration(SCANCONF& ic)
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,7 +130,8 @@ class hg_scanner
|
||||||
void working_begin(void*);
|
void working_begin(void*);
|
||||||
void working_done(void*);
|
void working_done(void*);
|
||||||
|
|
||||||
void image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id);
|
void save_exception_image(std::shared_ptr<tiny_buffer>& buffer, int sn, const char* desc);
|
||||||
|
bool image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id); // 返回true - continue; false - exit and invoked do_stop
|
||||||
void reset_custom_area_range(int paper);
|
void reset_custom_area_range(int paper);
|
||||||
float reset_custom_area_jsn_value(const char* name, double& var, float range_l, float range_u, float value_l, float value_u); // return cur value
|
float reset_custom_area_jsn_value(const char* name, double& var, float range_l, float range_u, float value_l, float value_u); // return cur value
|
||||||
int set_color_change(void);
|
int set_color_change(void);
|
||||||
|
|
|
@ -839,6 +839,7 @@ scanner_err hg_scanner_mgr::hg_scanner_close(scanner_handle h, bool force)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SCAN_PTR(h)->stop();
|
||||||
SCAN_PTR(h)->close(force);
|
SCAN_PTR(h)->close(force);
|
||||||
delete SCAN_PTR(h);
|
delete SCAN_PTR(h);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue