newtx/imgproc/algs/color_correct.cpp

92 lines
3.9 KiB
C++
Raw Normal View History

2024-01-25 06:13:24 +00:00
#include "color_correct.h"
#include <huagao/hgscanner_error.h>
#include <sane/sane_ex.h>
#include <opencv2/imgproc/hal/hal.hpp>
#include "ImageProcess_Public.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
static std::string device_opt_json[] = {
"{\"clr-correct\":{\"cat\":\"imgp\",\"group\":\"imgp\",\"title\":\"\\u989c\\u8272\\u6821\\u6b63\",\"desc\":\"\\u6839\\u636e\\u6821\\u6b63\\u53c2\\u6570\\uff0c\\u8c03\\u6574\\u4eceCIS\\u51fa\\u6765\\u7684\\u539f\\u59cb\\u56fe\\u50cf\\u989c\\u8272\",\"type\":\"bool\",\"pos\":24,\"ui-pos\":-1,\"auth\":0,\"size\":4,\"cur\":true,\"default\":true},\"lut-file\":{\"cat\":\"imgp\",\"group\":\"imgp\",\"title\":\"\\u6821\\u6b63\\u6a21\\u677f\",\"desc\":\"\\u989c\\u8272\\u6821\\u6b63\\u4f7f\\u7528\\u7684\\u57fa\\u51c6\\u56fe\\u50cf\\u6570\\u636e\",\"type\":\"string\",\"pos\":25,\"ui-pos\":-1,\"auth\":0,\"bind\":true,\"size\":80,\"default\":{\"cis-mode==\\u5f69\\u8272&&resolution>200&&resolution<400\":\"\\/usr\\/local\\/huago\\/Textlut300clr.bmp\",\"cis-mode==\\u5f69\\u8272&&resolution>=400\":\"\\/usr\\/local\\/huago\\/Textlut600clr.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution<=200\":\"\\/usr\\/local\\/huago\\/Textlut200gray.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution>200&&resolution<400\":\"\\/usr\\/local\\/huago\\/Textlut300gray.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution>=400\":\"\\/usr\\/local\\/huago\\/Textlut600gray.bmp\",\"default\":\"\\/usr\\/local\\/huago\\/Textlut200clr.bmp\"}},\"cis-mode\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"CIS\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u955c\\u5934\\u8272\\u5f69\\u5de5\\u4f5c\\u6a21\\u5f0f\",\"type\":\"string\",\"pos\":1000,\"ui-pos\":10,\"auth\":0,\"bind\":true,\"size\":12,\"default\":{\"(mode.enabled&&(mode==256\\u7ea7\\u7070\\u5ea6||mode==\\u9ed1\\u767d)) || (multiout-type.enabled&&multiout-type==\\u7070\\u5ea6+\\u9ed1\\u767d)\":\"\\u7070\\u5ea6\",\"default\":\"\\u5f69\\u8272\"},\"range\":[\"\\u5f69\\u8272\",\"\\u7070\\u5ea6\"]}}"
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
color_correct::color_correct() : image_processor("color_correct")
{
ADD_THIS_JSON();
hg::initLut(lut_path_.c_str(), clr_);
}
color_correct::~color_correct()
{}
int color_correct::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(COLOR_CORRECT)) == 0)
2024-01-27 09:43:13 +00:00
enabled_ = correct_ = *(bool*)val;
2024-01-25 06:13:24 +00:00
else if(strcmp(name, SANE_FULL_NAME(LUT_FILE)) == 0)
{
2024-01-27 09:43:13 +00:00
if(lut_path_ != (char*)val)
{
lut_path_ = (char*)val;
hg::initLut(lut_path_.c_str(), clr_);
}
2024-01-25 06:13:24 +00:00
}
else if(strcmp(name, SANE_FULL_NAME(CIS_MODE)) == 0)
{
2024-01-27 09:43:13 +00:00
bool pre = clr_;
2024-01-25 06:13:24 +00:00
clr_ = strcmp((char*)val, WORDS_COLOR_COLOR) == 0;
2024-01-27 09:43:13 +00:00
if(pre != clr_)
hg::initLut(lut_path_.c_str(), clr_);
2024-01-25 06:13:24 +00:00
}
else
ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
return ret;
}
int color_correct::process(std::vector<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& out)
{
int ret = SCANNER_ERR_OK;
if(correct_)
{
for(auto& v: in)
{
PROCIMGINFO o = v;
chronograph watch;
hg::correctColor(o.img, o.info.resolution_x, 1, true);
o.info.prc_time = watch.elapse_ms();
o.info.prc_stage = get_position();
o.info.width = o.img.cols;
o.info.height = o.img.rows;
out.push_back(o);
}
}
else
{
out = in;
for(auto& v: out)
{
v.info.prc_stage = get_position();
v.info.prc_time = 0;
}
}
return ret;
}