增加分辨率拉伸算法

This commit is contained in:
gb 2024-01-23 17:34:20 +08:00
parent 4291bca09c
commit 2dbc4e1645
9 changed files with 145 additions and 39 deletions

View File

@ -43,25 +43,17 @@
"range": ["24位彩色", "256级灰度", "黑白", "颜色自动识别"], "range": ["24位彩色", "256级灰度", "黑白", "颜色自动识别"],
"depend": "is-multiout!=true" "depend": "is-multiout!=true"
}, },
"resolution": { "dump-img": {
"cat": "base", "cat": "base",
"group": "base", "group": "高级设置",
"title": "分辨率", "title": "输出中间图像",
"desc": "设置扫描图像的分辨率", "desc": "输出各算法中间结果图像",
"type": "int", "type": "bool",
"fix-id": 34840, "ui-pos": 10,
"ui-pos": 20,
"auth": 0, "auth": 0,
"affect": 2,
"size": 4, "size": 4,
"cur": 200, "cur": false,
"default": 200, "default": false
"range": {
"min": 100,
"max": {
"default": 600,
"paper==最大扫描尺寸自动裁切 || paper==最大扫描尺寸 || paper==三联试卷": 500
},
"step": 1
}
} }
} }

View File

@ -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
}
}
}

View File

@ -13,11 +13,7 @@ static std::string device_opt_json[] = {
rebuild::rebuild() : image_processor("rebuild") rebuild::rebuild() : image_processor("rebuild")
{ {
std::string t(""); ADD_THIS_JSON();
for(auto& v: device_opt_json)
t += v;
image_processor::set_opt_json_text(&t[0]);
} }
rebuild::~rebuild() rebuild::~rebuild()
{} {}

68
imgproc/algs/stretch.cpp Normal file
View File

@ -0,0 +1,68 @@
#include "stretch.h"
#include <huagao/hgscanner_error.h>
#include <sane/sane_ex.h>
#include <base/utils.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
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<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& 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;
}

23
imgproc/algs/stretch.h Normal file
View File

@ -0,0 +1,23 @@
// stretch CIS resolution to soft/user resolution
//
// Date: 2024-01-23
#pragma once
#include <imgprc/img_processor.h>
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<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& out) override;
};

View File

@ -6,9 +6,10 @@
#include <base/packet.h> #include <base/packet.h>
#include "./algs/rebuild.h" #include "./algs/rebuild.h"
#include "./algs/stretch.h"
static std::string device_opt_json[] = { 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<void(data_source_ptr)> sender
) )
: img_sender_(sender), opts_(devopts), prc_que_("prcimg") : img_sender_(sender), opts_(devopts), prc_que_("prcimg")
{ {
std::string text(""); ADD_THIS_JSON();
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]);
if (opts_) if (opts_)
opts_->add_ref(); opts_->add_ref();
@ -139,7 +128,11 @@ void imgproc_mgr::process(RAWIMG* img)
in = std::move(out); in = std::move(out);
} }
} }
uint32_t t = watch.elapse_ms();
for(auto& v: in)
v.info.prc_time = t;
} }
send_image(in, true); send_image(in, true);
} }
else else
@ -207,6 +200,7 @@ int imgproc_mgr::load_processor(const char* path)
} }
// ADD_IMG_PROCESSOR(rebuild); // ADD_IMG_PROCESSOR(rebuild);
ADD_IMG_PROCESSOR(stretch);
std::sort(processors_.begin(), processors_.end(), &imgproc_mgr::sort_processor_by_pos); std::sort(processors_.begin(), processors_.end(), &imgproc_mgr::sort_processor_by_pos);

View File

@ -2,7 +2,7 @@ add_rules("mode.debug", "mode.release")
target("imgproc") target("imgproc")
set_kind("static") 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_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_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") --add_deps("gusb", "applog")

View File

@ -56,3 +56,10 @@ public:
virtual int process(LPPROCIIM* in, size_t cnt, bool(*result)(LPPROCIIM, void*), void* param); 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]); \
}

View File

@ -61,7 +61,7 @@ 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=20240123") add_defines("VER_DATE=20240123")
add_defines("VER_BUILD=21") add_defines("VER_BUILD=32")
target("conf") target("conf")
set_kind("phony") set_kind("phony")