From 2dbc4e16456fb5de2bba18666c6d3099b660d87e Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Tue, 23 Jan 2024 17:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E8=BE=A8=E7=8E=87?= =?UTF-8?q?=E6=8B=89=E4=BC=B8=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sane-opts/imgprc_mgr.txt | 28 ++++++--------- docs/sane-opts/stretch.txt | 26 ++++++++++++++ imgproc/algs/rebuild.cpp | 6 +--- imgproc/algs/stretch.cpp | 68 +++++++++++++++++++++++++++++++++++ imgproc/algs/stretch.h | 23 ++++++++++++ imgproc/imgprc_mgr.cpp | 22 +++++------- imgproc/xmake.lua | 2 +- sdk/imgprc/img_processor.h | 7 ++++ xmake.lua | 2 +- 9 files changed, 145 insertions(+), 39 deletions(-) create mode 100644 docs/sane-opts/stretch.txt create mode 100644 imgproc/algs/stretch.cpp create mode 100644 imgproc/algs/stretch.h diff --git a/docs/sane-opts/imgprc_mgr.txt b/docs/sane-opts/imgprc_mgr.txt index 9364443..3916ef3 100644 --- a/docs/sane-opts/imgprc_mgr.txt +++ b/docs/sane-opts/imgprc_mgr.txt @@ -43,25 +43,17 @@ "range": ["24位彩色", "256级灰度", "黑白", "颜色自动识别"], "depend": "is-multiout!=true" }, - "resolution": { + "dump-img": { "cat": "base", - "group": "base", - "title": "分辨率", - "desc": "设置扫描图像的分辨率", - "type": "int", - "fix-id": 34840, - "ui-pos": 20, + "group": "高级设置", + "title": "输出中间图像", + "desc": "输出各算法中间结果图像", + "type": "bool", + "ui-pos": 10, "auth": 0, + "affect": 2, "size": 4, - "cur": 200, - "default": 200, - "range": { - "min": 100, - "max": { - "default": 600, - "paper==最大扫描尺寸自动裁切 || paper==最大扫描尺寸 || paper==三联试卷": 500 - }, - "step": 1 - } + "cur": false, + "default": false } -} +} \ No newline at end of file diff --git a/docs/sane-opts/stretch.txt b/docs/sane-opts/stretch.txt new file mode 100644 index 0000000..b03cd65 --- /dev/null +++ b/docs/sane-opts/stretch.txt @@ -0,0 +1,26 @@ +{ + "resolution": { + "cat": "imgp", + "group": "base", + "title": "分辨率", + "desc": "设置扫描图像的分辨率", + "type": "int", + "pos": 20, + "fix-id": 34840, + "ui-pos": 20, + "auth": 0, + "affect": 6, + "unit": "DPI", + "size": 4, + "cur": 200, + "default": 200, + "range": { + "min": 100, + "max": { + "default": 600, + "paper==最大扫描尺寸自动裁切 || paper==最大扫描尺寸 || paper==三联试卷": 500 + }, + "step": 1 + } + } +} \ No newline at end of file diff --git a/imgproc/algs/rebuild.cpp b/imgproc/algs/rebuild.cpp index 25f5ccc..f7a846d 100644 --- a/imgproc/algs/rebuild.cpp +++ b/imgproc/algs/rebuild.cpp @@ -13,11 +13,7 @@ static std::string device_opt_json[] = { rebuild::rebuild() : image_processor("rebuild") { - std::string t(""); - - for(auto& v: device_opt_json) - t += v; - image_processor::set_opt_json_text(&t[0]); + ADD_THIS_JSON(); } rebuild::~rebuild() {} diff --git a/imgproc/algs/stretch.cpp b/imgproc/algs/stretch.cpp new file mode 100644 index 0000000..f660589 --- /dev/null +++ b/imgproc/algs/stretch.cpp @@ -0,0 +1,68 @@ +#include "stretch.h" + + +#include +#include +#include + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +static std::string device_opt_json[] = { + "{\"resolution\":{\"cat\":\"imgp\",\"group\":\"base\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"pos\":20,\"fix-id\":34840,\"ui-pos\":20,\"auth\":0,\"affect\":6,\"unit\":\"DPI\",\"size\":4,\"cur\":200,\"default\":200,\"range\":{\"min\":100,\"max\":{\"default\":600,\"paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207 || paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8 || paper==\\u4e09\\u8054\\u8bd5\\u5377\":500},\"step\":1}}}" +}; + + + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +stretch::stretch() : image_processor("stretch") +{ + ADD_THIS_JSON(); +} +stretch::~stretch() +{} + +int stretch::set_value(const char* name/*nullptr for all options*/, void* val/*nullptr for restore*/) +{ + int ret = SCANNER_ERR_OK; + + if(strcmp(name, SANE_FULL_NAME(RESOLUTION)) == 0) + dpi_ = *(int*)val; + else + ret = SCANNER_ERR_DEVICE_NOT_SUPPORT; + + return ret; +} +int stretch::process(std::vector& in, std::vector& out) +{ + for(auto& v: in) + { + if(v.info.resolution_x == dpi_ && + v.info.resolution_y == dpi_) + { + out.push_back(v); + out[out.size() - 1].info.prc_stage = get_position(); + out[out.size() - 1].info.prc_time = 0; + } + else + { + PROCIMGINFO o; + chronograph watch; + + o.info = v.info; + o.info.prc_stage = get_position(); + cv::resize(v.img, o.img, cv::Size(0, 0), dpi_ * 1.0f / v.info.resolution_x, dpi_ * 1.0f / v.info.resolution_y); + o.info.prc_time = watch.elapse_ms(); + o.info.resolution_x = o.info.resolution_y = dpi_; + o.info.width = o.img.cols; + o.info.height = o.img.rows; + o.info.info_size = 0; + o.info.data_size = o.info.width * o.info.height * o.info.channels; + out.push_back(o); + } + } + + return SCANNER_ERR_OK; +} diff --git a/imgproc/algs/stretch.h b/imgproc/algs/stretch.h new file mode 100644 index 0000000..4490f5a --- /dev/null +++ b/imgproc/algs/stretch.h @@ -0,0 +1,23 @@ +// stretch CIS resolution to soft/user resolution +// +// Date: 2024-01-23 +#pragma once + +#include + +class stretch : public image_processor +{ + uint32_t dpi_ = 200; + +public: + stretch(); + +protected: + ~stretch(); + +public: + virtual int set_value(const char* name/*nullptr for all options*/, void* val/*nullptr for restore*/) override; + +public: + virtual int process(std::vector& in, std::vector& out) override; +}; diff --git a/imgproc/imgprc_mgr.cpp b/imgproc/imgprc_mgr.cpp index 5d0dd5c..c044451 100644 --- a/imgproc/imgprc_mgr.cpp +++ b/imgproc/imgprc_mgr.cpp @@ -6,9 +6,10 @@ #include #include "./algs/rebuild.h" +#include "./algs/stretch.h" static std::string device_opt_json[] = { - "{\"is-multiout\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"fix-id\":34817,\"ui-pos\":10,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"multiout-type\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"fix-id\":34818,\"ui-pos\":11,\"auth\":0,\"enabled\":false,\"size\":66,\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend\":\"is-multiout==true\"},\"mode\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"fix-id\":34819,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend\":\"is-multiout!=true\"},\"resolution\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"fix-id\":34840,\"ui-pos\":20,\"auth\":0,\"size\":4,\"cur\":200,\"default\":200,\"range\":{\"min\":100,\"max\":{\"default\":600,\"paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207 || paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8 || paper==\\u4e09\\u8054\\u8bd5\\u5377\":500},\"step\":1}},\"dump-img\":{\"cat\":\"base\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u8f93\\u51fa\\u4e2d\\u95f4\\u56fe\\u50cf\",\"desc\":\"\\u8f93\\u51fa\\u5404\\u7b97\\u6cd5\\u4e2d\\u95f4\\u7ed3\\u679c\\u56fe\\u50cf\",\"type\":\"bool\",\"ui-pos\":10,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":false,\"default\":false}}" + "{\"is-multiout\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"fix-id\":34817,\"ui-pos\":10,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"multiout-type\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"fix-id\":34818,\"ui-pos\":11,\"auth\":0,\"enabled\":false,\"size\":66,\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend\":\"is-multiout==true\"},\"mode\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"fix-id\":34819,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend\":\"is-multiout!=true\"},\"dump-img\":{\"cat\":\"base\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u8f93\\u51fa\\u4e2d\\u95f4\\u56fe\\u50cf\",\"desc\":\"\\u8f93\\u51fa\\u5404\\u7b97\\u6cd5\\u4e2d\\u95f4\\u7ed3\\u679c\\u56fe\\u50cf\",\"type\":\"bool\",\"ui-pos\":10,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":false,\"default\":false}}" }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -19,19 +20,7 @@ imgproc_mgr::imgproc_mgr(std::function sender ) : img_sender_(sender), opts_(devopts), prc_que_("prcimg") { - std::string text(""); - gb_json *jsn = new gb_json(); - - for (auto& v : device_opt_json) - text += v; - - if (jsn->attach_text(&text[0])) - { - text = jsn->to_string(); - } - jsn->release(); - - set_opt_json_text(&text[0]); + ADD_THIS_JSON(); if (opts_) opts_->add_ref(); @@ -139,7 +128,11 @@ void imgproc_mgr::process(RAWIMG* img) in = std::move(out); } } + uint32_t t = watch.elapse_ms(); + for(auto& v: in) + v.info.prc_time = t; } + send_image(in, true); } else @@ -207,6 +200,7 @@ int imgproc_mgr::load_processor(const char* path) } // ADD_IMG_PROCESSOR(rebuild); + ADD_IMG_PROCESSOR(stretch); std::sort(processors_.begin(), processors_.end(), &imgproc_mgr::sort_processor_by_pos); diff --git a/imgproc/xmake.lua b/imgproc/xmake.lua index 0004778..3eb5636 100644 --- a/imgproc/xmake.lua +++ b/imgproc/xmake.lua @@ -2,7 +2,7 @@ add_rules("mode.debug", "mode.release") target("imgproc") set_kind("static") - add_syslinks("pthread", "dl", "opencv_imgcodecs", "opencv_core") + add_syslinks("pthread", "dl", "opencv_imgcodecs", "opencv_core", "opencv_imgproc") add_includedirs("../sdk", "../hardware") add_files("*.cpp", "./algs/*.c*", "../sdk/base/*.c*", "../sdk/imgprc/*.c*", "../sdk/json/*.c*", "../sdk/sane/*.c*", "../sdk/sane_opt_json/*.c*") --add_deps("gusb", "applog") diff --git a/sdk/imgprc/img_processor.h b/sdk/imgprc/img_processor.h index 038e282..5d17465 100644 --- a/sdk/imgprc/img_processor.h +++ b/sdk/imgprc/img_processor.h @@ -56,3 +56,10 @@ public: virtual int process(LPPROCIIM* in, size_t cnt, bool(*result)(LPPROCIIM, void*), void* param); }; +#define ADD_THIS_JSON() \ + { \ + std::string t(""); \ + for(auto& v: device_opt_json) \ + t += v; \ + set_opt_json_text(&t[0]); \ + } diff --git a/xmake.lua b/xmake.lua index 969993a..c265a71 100644 --- a/xmake.lua +++ b/xmake.lua @@ -61,7 +61,7 @@ add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=200") add_defines("VER_DATE=20240123") -add_defines("VER_BUILD=21") +add_defines("VER_BUILD=32") target("conf") set_kind("phony")