#include "fill_hole.h" #include #include #include static std::string device_opt_json[] = { "{\"is-rid-hole-l\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u5de6\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u5de6\\u4fa7\",\"type\":\"bool\",\"pos\":10,\"fix-id\":34879,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"search-hole-range-l\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\" \\u5de6\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"pos\":10,\"fix-id\":34880,\"auth\":0,\"size\":8,\"cur\":0.000000,\"default\":0.000000,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend\":\"is-rid-hole-l==true\"},\"is-rid-hole-r\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u53f3\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u53f3\\u4fa7\",\"type\":\"bool\",\"pos\":10,\"fix-id\":34881,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"search-hole-range-r\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\" \\u53f3\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"pos\":10,\"fix-id\":34882,\"auth\":0,\"size\":8,\"cur\":0.000000,\"default\":0.000000,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend\":\"is-rid-hole-r==true\"},\"is-rid-hole-t\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0a\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0a\\u90e8\",\"type\":\"bool\",\"pos\":10,\"fix-id\":34883,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"search-hole-range-t\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\" \\u4e0a\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"pos\":10,\"fix-id\":34884,\"auth\":0,\"size\":8,\"cur\":0.000000,\"default\":0.000000,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend\":\"is-rid-hole-t==true\"},\"is-rid-hole-b\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0b\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0b\\u90e8\",\"type\":\"bool\",\"pos\":10,\"fix-id\":34885,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"search-hole-range-b\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\" \\u4e0b\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"pos\":10,\"fix-id\":34886,\"auth\":0,\"size\":8,\"cur\":0.000000,\"default\":0.000000,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend\":\"is-rid-hole-b==true\"},\"hole-threshold\":{\"cat\":\"base\",\"group\":\"imgp\",\"title\":\"\\u5b54\\u6d1e\\u9608\\u503c\",\"desc\":\"\\u5b54\\u6d1e\\u50cf\\u7d20\\u5927\\u5c0f\\u9608\\u503c\\uff08\\u5c0f\\u4e8e\\u9608\\u503c\\u4e0d\\u5f53\\u4f5c\\u5b54\\u6d1e\\uff09\",\"type\":\"int\",\"auth\":0,\"unit\":\"pixel\",\"size\":4,\"cur\":50,\"default\":50,\"range\":{\"min\":5,\"max\":100,\"step\":1},\"depend\":\"is-rid-hole-l==true || is-rid-hole-r==true || is-rid-hole-t==true || is-rid-hole-b==true\"},\"resolution\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"pos\":10,\"fix-id\":34840,\"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}}}" }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // image_processor hole_filler::hole_filler() : image_processor("hole_filler") { std::string json(""); for (auto& v : device_opt_json) json += v; set_opt_json_text(&json[0]); } hole_filler::~hole_filler() {} int hole_filler::set_value(const char* name, void* val) { int ret = SCANNER_ERR_OK; // SCANNER_ERR_DEVICE_NOT_SUPPORT; if (strcmp(name, SANE_STD_OPT_NAME_RID_HOLE_T) == 0) top_ = *(bool*)val; else if (strcmp(name, SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_T) == 0) top_ratio_ = *(double*)val; else if (strcmp(name, SANE_STD_OPT_NAME_RID_HOLE_B) == 0) bottom_ = *(bool*)val; else if (strcmp(name, SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_B) == 0) bottom_ratio_ = *(double*)val; else if (strcmp(name, SANE_STD_OPT_NAME_RID_HOLE_L) == 0) left_ = *(bool*)val; else if (strcmp(name, SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_L) == 0) left_ratio_ = *(double*)val; else if (strcmp(name, SANE_STD_OPT_NAME_RID_HOLE_R) == 0) right_ = *(bool*)val; else if (strcmp(name, SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_R) == 0) right_ratio_ = *(double*)val; else if (strcmp(name, SANE_STD_OPT_NAME_RESOLUTION) == 0) dpi_ = *(int*)val; else if (strcmp(name, SANE_STD_OPT_NAME_HOLE_THRESHOLD) == 0) threshold_ = *(int*)val; else ret = SCANNER_ERR_DEVICE_NOT_SUPPORT; return ret; } void hole_filler::enable(const char* name, bool able) { enabled_ = able; } int hole_filler::process(std::vector& in, std::vector& out) { int ret = SCANNER_ERR_OK; if (!enabled_ || (IS_DOUBLE_EQUAL(left_ratio_, .0f) && IS_DOUBLE_EQUAL(right_ratio_, .0f) && IS_DOUBLE_EQUAL(top_ratio_, .0f) && IS_DOUBLE_EQUAL(bottom_ratio_, .0f)) ) out = in; else { cv::Vec4f ratio; ratio[0] = top_ ? top_ratio_ : .0f; ratio[1] = bottom_ ? bottom_ratio_ : .0f; ratio[2] = left_ ? left_ratio_ : .0f; ratio[3] = right_ ? right_ratio_ : .0f; CImageApplyOutHole worker(dpi_ * 1.0f / 10, ratio, threshold_); for (auto& v : in) { std::vector src; PROCIMGINFO result; src.push_back(v.img); result.info = v.info; worker.apply(src, result.info.paper_side != PAPER_SIDE_FRONT && result.info.paper_side != PAPER_SIDE_BACK); if (src.size()) { result.img = src[0]; out.push_back(result); } } } return ret; }