修复扫描流程及中间图像传输参数
This commit is contained in:
parent
a0461ff354
commit
5524999d51
|
@ -386,14 +386,20 @@ void scanner_hw::thread_image_capture(bool paper_ready)
|
||||||
// scanning ONE turn ...
|
// scanning ONE turn ...
|
||||||
if(paper_ready) // auto_scan_ ignore no paper
|
if(paper_ready) // auto_scan_ ignore no paper
|
||||||
{
|
{
|
||||||
|
bool over = false;
|
||||||
err = start_and_wait_lifter(to_lifter_, &over_msg_id);
|
err = start_and_wait_lifter(to_lifter_, &over_msg_id);
|
||||||
if(err)
|
if(err)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
motor_->pick_paper();
|
motor_->pick_paper();
|
||||||
err = scan_one_turn(&img, &avail_mem, &used_v4l2_mem, &over_msg_id);
|
err = scan_one_turn(&img, &avail_mem, &used_v4l2_mem, &over_msg_id, &over);
|
||||||
if(err || !auto_scan_ || !scanning_)
|
if((over && !auto_scan_) || err || !auto_scan_ || !scanning_)
|
||||||
break;
|
break;
|
||||||
|
{
|
||||||
|
scanstream.err = over_msg_id;
|
||||||
|
scanstream.mode = devui::SCAN_PAUSED;
|
||||||
|
devui::send_message(devui::UI_STATUS_SCANNING, (uint8_t*)&scanstream, sizeof(scanstream));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait paper ...
|
// wait paper ...
|
||||||
|
@ -417,7 +423,8 @@ void scanner_hw::thread_image_capture(bool paper_ready)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// retrieve v4l2-mem ...
|
// retrieve v4l2-mem ...
|
||||||
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
|
if(!count_mode_)
|
||||||
|
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
motor_->set_auto_paper(false, false);
|
motor_->set_auto_paper(false, false);
|
||||||
|
@ -484,7 +491,7 @@ int scanner_hw::start_and_wait_lifter(int to_ms, int* ui_words_id)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int scanner_hw::scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_cnt, int* ui_words)
|
int scanner_hw::scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_cnt, int* ui_words, bool* mbstopped)
|
||||||
{
|
{
|
||||||
int ret = SCANNER_ERR_OK, minh = 210 * dpi_ / 25.4,
|
int ret = SCANNER_ERR_OK, minh = 210 * dpi_ / 25.4,
|
||||||
words = 0;
|
words = 0;
|
||||||
|
@ -501,6 +508,8 @@ int scanner_hw::scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_c
|
||||||
que->save(ind);
|
que->save(ind);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(mbstopped)
|
||||||
|
*mbstopped = false;
|
||||||
while(scanning_)
|
while(scanning_)
|
||||||
{
|
{
|
||||||
if(!motor_->wait_paper_out(to_paper_out_))
|
if(!motor_->wait_paper_out(to_paper_out_))
|
||||||
|
@ -523,6 +532,8 @@ int scanner_hw::scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_c
|
||||||
}
|
}
|
||||||
else if(mbev.first == MOTOR_BORD_EVENT_SCAN_DONE)
|
else if(mbev.first == MOTOR_BORD_EVENT_SCAN_DONE)
|
||||||
{
|
{
|
||||||
|
if(mbstopped)
|
||||||
|
*mbstopped = true;
|
||||||
printf("-->scan done event received from motorboard.\n");
|
printf("-->scan done event received from motorboard.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -876,6 +887,7 @@ int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler, CHK_RES_F
|
||||||
|
|
||||||
auto cb = [this](int ev, unsigned int data) -> void
|
auto cb = [this](int ev, unsigned int data) -> void
|
||||||
{
|
{
|
||||||
|
printf("motorboard event: 0x%08X, data = %d\n", ev, data);
|
||||||
mb_events_.save(std::make_pair(ev, data), true);
|
mb_events_.save(std::make_pair(ev, data), true);
|
||||||
};
|
};
|
||||||
mb_events_.clear();
|
mb_events_.clear();
|
||||||
|
|
|
@ -103,7 +103,7 @@ class scanner_hw : public sane_opt_provider
|
||||||
void load_correct_data(std::string& text);
|
void load_correct_data(std::string& text);
|
||||||
void thread_image_capture(bool paper_ready);
|
void thread_image_capture(bool paper_ready);
|
||||||
int start_and_wait_lifter(int to_ms, int* ui_words_id = nullptr);
|
int start_and_wait_lifter(int to_ms, int* ui_words_id = nullptr);
|
||||||
int scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_cnt, int* ui_words);
|
int scan_one_turn(LPPACKIMAGE img, safe_fifo<int>* cism, int* cism_cnt, int* ui_words, bool* mbstopped);
|
||||||
int get_image_real_height(int minh);
|
int get_image_real_height(int minh);
|
||||||
void retrieve_v4l2_mem(safe_fifo<int>* mem, int* used);
|
void retrieve_v4l2_mem(safe_fifo<int>* mem, int* used);
|
||||||
void set_gain_value(bool front, bool gain, int sector, int val);
|
void set_gain_value(bool front, bool gain, int sector, int val);
|
||||||
|
|
|
@ -162,13 +162,13 @@ void imgproc_mgr::process(RAWIMG* img)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
cv::Mat mat(img->info.width, img->info.height, CV_8UC1, img->data->ptr());
|
cv::Mat mat(img->info.width, img->info.height, CV_8UC1, img->data->ptr());
|
||||||
send_image(&img->info, mat);
|
send_image(&img->info, mat, nullptr, 0, false);
|
||||||
}
|
}
|
||||||
img->data->release();
|
img->data->release();
|
||||||
|
|
||||||
for(auto& v: processors_)
|
for(auto& v: processors_)
|
||||||
{
|
{
|
||||||
send_image(*src);
|
send_image(*src, false);
|
||||||
if(v->is_enable())
|
if(v->is_enable())
|
||||||
{
|
{
|
||||||
process(v, src, dst);
|
process(v, src, dst);
|
||||||
|
@ -198,7 +198,7 @@ void imgproc_mgr::process(RAWIMG* img)
|
||||||
v.info.prc_time = t;
|
v.info.prc_time = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_image(*src);
|
send_image(*src, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -236,7 +236,7 @@ void imgproc_mgr::process(image_processor* prc, std::vector<PROCIMGINFO>* in, st
|
||||||
throw(exception_ex(msg.c_str()));
|
throw(exception_ex(msg.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void imgproc_mgr::send_image(LPPACKIMAGE head, cv::Mat& mat, void* info, size_t info_l)
|
void imgproc_mgr::send_image(LPPACKIMAGE head, cv::Mat& mat, void* info, size_t info_l, bool last)
|
||||||
{
|
{
|
||||||
auto ovr = [&](uint64_t total, uint64_t cur_size, uint32_t err, void* user_data) -> int
|
auto ovr = [&](uint64_t total, uint64_t cur_size, uint32_t err, void* user_data) -> int
|
||||||
{
|
{
|
||||||
|
@ -248,16 +248,23 @@ void imgproc_mgr::send_image(LPPACKIMAGE head, cv::Mat& mat, void* info, size_t
|
||||||
|
|
||||||
PACKIMAGE h(*head);
|
PACKIMAGE h(*head);
|
||||||
std::shared_ptr<std::vector<uchar>> compd(last_->encode(&h, mat));
|
std::shared_ptr<std::vector<uchar>> compd(last_->encode(&h, mat));
|
||||||
image_packet_ptr ptr = new image_packet(&h, compd, scan_id_, info, info_l);
|
image_packet_ptr ptr = nullptr;
|
||||||
|
|
||||||
|
if(!last)
|
||||||
|
{
|
||||||
|
h.prc_stage = head->prc_stage;
|
||||||
|
h.prc_time = head->prc_time;
|
||||||
|
}
|
||||||
|
ptr = new image_packet(&h, compd, scan_id_, info, info_l);
|
||||||
|
|
||||||
ptr->set_session_id(session_id_);
|
ptr->set_session_id(session_id_);
|
||||||
img_sender_(ptr);
|
img_sender_(ptr);
|
||||||
ptr->release();
|
ptr->release();
|
||||||
}
|
}
|
||||||
void imgproc_mgr::send_image(std::vector<PROCIMGINFO>& imgs)
|
void imgproc_mgr::send_image(std::vector<PROCIMGINFO>& imgs, bool last)
|
||||||
{
|
{
|
||||||
for(auto& v: imgs)
|
for(auto& v: imgs)
|
||||||
send_image(&v.info, v.img, v.ext_info.empty() ? nullptr : &v.ext_info[0], v.ext_info.length());
|
send_image(&v.info, v.img, v.ext_info.empty() ? nullptr : &v.ext_info[0], v.ext_info.length(), last);
|
||||||
}
|
}
|
||||||
|
|
||||||
int imgproc_mgr::set_value(const char* name, void* val)
|
int imgproc_mgr::set_value(const char* name, void* val)
|
||||||
|
|
|
@ -55,8 +55,8 @@ class imgproc_mgr : public sane_opt_provider
|
||||||
void thread_worker(void);
|
void thread_worker(void);
|
||||||
void process(RAWIMG* img);
|
void process(RAWIMG* img);
|
||||||
void process(image_processor* prc, std::vector<PROCIMGINFO>* in, std::vector<PROCIMGINFO>* out);
|
void process(image_processor* prc, std::vector<PROCIMGINFO>* in, std::vector<PROCIMGINFO>* out);
|
||||||
void send_image(LPPACKIMAGE head, cv::Mat& mat, void* info = nullptr, size_t info_l = 0);
|
void send_image(LPPACKIMAGE head, cv::Mat& mat, void* info = nullptr, size_t info_l = 0, bool last = true);
|
||||||
void send_image(std::vector<PROCIMGINFO>& imgs);
|
void send_image(std::vector<PROCIMGINFO>& imgs, bool last);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
imgproc_mgr(std::function<void(data_source_ptr)> sender, device_option* devopts, CHK_RES_FUNC res = CHK_RES_FUNC());
|
imgproc_mgr(std::function<void(data_source_ptr)> sender, device_option* devopts, CHK_RES_FUNC res = CHK_RES_FUNC());
|
||||||
|
|
|
@ -135,15 +135,16 @@ LPPACKIMAGE image_holder::get_info(void)
|
||||||
{
|
{
|
||||||
return &head_;
|
return &head_;
|
||||||
}
|
}
|
||||||
int image_holder::save_2_file(const char* root_dir, const char* alg)
|
int image_holder::save_2_file(const char* root_dir, int alg_ind, const char* alg)
|
||||||
{
|
{
|
||||||
std::string file(root_dir);
|
std::string file(root_dir);
|
||||||
FILE* dst = nullptr;
|
FILE* dst = nullptr;
|
||||||
int err = ENOTSUP;
|
int err = ENOTSUP;
|
||||||
char buf[80] = { 0 };
|
char buf[80] = { 0 };
|
||||||
|
bool bmp = false;
|
||||||
|
|
||||||
file += PATH_SEPARATOR;
|
file += PATH_SEPARATOR;
|
||||||
sprintf(buf, "%04d", head_.pos.paper_ind);
|
sprintf(buf, "%04d_%04x", (uint32_t)head_.pos.paper_ind, alg_ind);
|
||||||
file += buf;
|
file += buf;
|
||||||
if (head_.pos.paper_side == PAPER_SIDE_FRONT)
|
if (head_.pos.paper_side == PAPER_SIDE_FRONT)
|
||||||
file += "_Front";
|
file += "_Front";
|
||||||
|
@ -155,30 +156,38 @@ int image_holder::save_2_file(const char* root_dir, const char* alg)
|
||||||
file += buf;
|
file += buf;
|
||||||
if (alg && *alg)
|
if (alg && *alg)
|
||||||
file += std::string("_") + alg;
|
file += std::string("_") + alg;
|
||||||
if (head_.format == IMG_FMT_BMP)
|
if (head_.format == IMG_FMT_PNG)
|
||||||
|
file += ".png";
|
||||||
|
else if (head_.format == IMG_FMT_JPEG)
|
||||||
|
file += ".jpg";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::string bih(utils::bitmap_info_header(head_.width, head_.height, head_.bpp * head_.channels, head_.resolution_x, head_.resolution_y)),
|
|
||||||
bfh(utils::bitmap_file_header((BITMAPINFOHEADER*)&bih[0]));
|
|
||||||
file += ".bmp";
|
file += ".bmp";
|
||||||
dst = fopen(file.c_str(), "wb");
|
bmp = true;
|
||||||
if (dst)
|
}
|
||||||
|
dst = fopen(file.c_str(), "wb");
|
||||||
|
if (dst)
|
||||||
|
{
|
||||||
|
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels),
|
||||||
|
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8;
|
||||||
|
if (bmp)
|
||||||
{
|
{
|
||||||
|
std::string bih(utils::bitmap_info_header(head_.width, head_.height, head_.bpp * head_.channels, head_.resolution_x, head_.resolution_y)),
|
||||||
|
bfh(utils::bitmap_file_header((BITMAPINFOHEADER*)&bih[0]));
|
||||||
fwrite(bfh.c_str(), 1, bfh.length(), dst);
|
fwrite(bfh.c_str(), 1, bfh.length(), dst);
|
||||||
fwrite(bih.c_str(), 1, bih.length(), dst);
|
fwrite(bih.c_str(), 1, bih.length(), dst);
|
||||||
if(head_.data_size == ((LPBITMAPINFOHEADER)&bih[0])->biSizeImage)
|
}
|
||||||
fwrite(data() + head_.info_size, 1, head_.data_size, dst);
|
if(!bmp || dif == 0)
|
||||||
else
|
fwrite(data() + head_.info_size, 1, head_.data_size, dst);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char pad[4] = { 0 };
|
||||||
|
uint8_t *ptr = data() + head_.info_size;
|
||||||
|
for (int i = 0; i < head_.height; ++i)
|
||||||
{
|
{
|
||||||
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels),
|
fwrite(ptr, 1, l - dif, dst);
|
||||||
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8;
|
fwrite(pad, 1, dif, dst);
|
||||||
char pad[4] = { 0 };
|
ptr += l - dif;
|
||||||
uint8_t *ptr = data() + head_.info_size;
|
|
||||||
for (int i = 0; i < head_.height; ++i)
|
|
||||||
{
|
|
||||||
fwrite(ptr, 1, l - dif, dst);
|
|
||||||
fwrite(pad, 1, dif, dst);
|
|
||||||
ptr += l - dif;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
void set_info(LPPACKIMAGE head);
|
void set_info(LPPACKIMAGE head);
|
||||||
LPPACKIMAGE get_info(void);
|
LPPACKIMAGE get_info(void);
|
||||||
int save_2_file(const char* root_dir, const char* alg = nullptr);
|
int save_2_file(const char* root_dir, int alg_ind, const char* alg = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
class empty_holer : public data_holder
|
class empty_holer : public data_holder
|
||||||
|
|
24
ui/font.cpp
24
ui/font.cpp
|
@ -782,6 +782,30 @@ namespace custom_font
|
||||||
};
|
};
|
||||||
font_map_["\350\241\214"] = xing;
|
font_map_["\350\241\214"] = xing;
|
||||||
|
|
||||||
|
static uint8_t gai[] = {16, 16
|
||||||
|
, 0x00, 0x04, 0x24, 0x24, 0x25, 0x26, 0x24, 0xFC, 0x24, 0x26, 0x25, 0x24, 0x24, 0x04, 0x00, 0x00
|
||||||
|
, 0x81, 0x81, 0xF9, 0x89, 0x89, 0xF9, 0x89, 0x89, 0x89, 0xF9, 0x89, 0x89, 0xF9, 0x81, 0x81, 0x00
|
||||||
|
};
|
||||||
|
font_map_["\347\233\226"] = gai;
|
||||||
|
|
||||||
|
static uint8_t ban[] = {16, 16
|
||||||
|
, 0x10, 0x10, 0xD0, 0xFF, 0x90, 0x10, 0x00, 0xFC, 0x24, 0xE4, 0x24, 0x22, 0x23, 0xE2, 0x00, 0x00
|
||||||
|
, 0x04, 0x03, 0x00, 0xFF, 0x00, 0x83, 0x60, 0x1F, 0x80, 0x41, 0x26, 0x18, 0x26, 0x41, 0x80, 0x00
|
||||||
|
};
|
||||||
|
font_map_["\346\235\277"] = ban;
|
||||||
|
|
||||||
|
static uint8_t da3[] = {16, 16
|
||||||
|
, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x90, 0x04, 0x04, 0x04, 0x04, 0xFC, 0x04, 0x04, 0x04, 0x04, 0x00
|
||||||
|
, 0x04, 0x44, 0x82, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x40, 0x80, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
font_map_["\346\211\223"] = da3;
|
||||||
|
|
||||||
|
static uint8_t kai[] = {16, 16
|
||||||
|
, 0x80, 0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x80, 0x00
|
||||||
|
, 0x00, 0x80, 0x40, 0x30, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
font_map_["\345\274\200"] = kai;
|
||||||
|
|
||||||
}
|
}
|
||||||
~font_init()
|
~font_init()
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -60,8 +60,8 @@ add_packagedirs("sdk")
|
||||||
add_defines("BUILD_AS_DEVICE")
|
add_defines("BUILD_AS_DEVICE")
|
||||||
add_defines("VER_MAIN=2")
|
add_defines("VER_MAIN=2")
|
||||||
add_defines("VER_FAMILY=200")
|
add_defines("VER_FAMILY=200")
|
||||||
add_defines("VER_DATE=20240225")
|
add_defines("VER_DATE=20240228")
|
||||||
add_defines("VER_BUILD=18")
|
add_defines("VER_BUILD=2")
|
||||||
|
|
||||||
target("conf")
|
target("conf")
|
||||||
set_kind("phony")
|
set_kind("phony")
|
||||||
|
|
Loading…
Reference in New Issue