code_device/hgdriver/hgdev/image_process.cpp

998 lines
25 KiB
C++
Raw Blame History

#include "image_process.h"
#include "../../sdk/hginclude/hg_log.h"
#include <vector>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <Windows.h>
#include <shlobj.h>
#pragma comment(lib, "Shell32.lib")
#pragma comment(lib, "hanwangOCRdetect.lib")
#endif
#include <memory>
#include "ImageMatQueue.h"
#include "../ImageProcess/ImageApplyHeaders.h"
#include "ImageMultiOutput.h"
#include "PaperSize.h"
#ifdef WIN32
#include "scanner_manager.h"
#include "ocr/hanwangOCRdetect.h"
#else
#include <dlfcn.h>
extern "C"
{
#include "ocr/hanwangOCRdetect.h"
}
#endif
using namespace std;
#define GET_BYTE(a) ((a) & 0x0ff)
#define MAKE_INT(a, b, c, d) (GET_BYTE(a) | (GET_BYTE(b) << 8) | (GET_BYTE(c) << 16) | (GET_BYTE(d) << 24))
#define IMAGE_DATA_BUF_CVMAT (void*)MAKE_INT('M', 'T', 'R', 'X')
#define IMAGE_DATA_BUF_CHAR (void*)MAKE_INT('C', 'H', 'A', 'R')
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// functional ...
////////////////////////////////////////////////////////////////////////////////
// NEW£¬flow ...
static int num=0;
namespace hg_imgproc
{
class imgproc
{
std::string my_path_;
IMGPRCPARAM param_;
SCANCONF img_conf_;
std::shared_ptr<std::string> raw_data_;
std::shared_ptr<vector<char>> buffer_;
std::vector<cv::Mat> mats_;
int pid_;
Device::PaperSize papersize_;
void swap_rgb(cv::Mat& mat)
{
unsigned char* first = (unsigned char*)mat.data,
* oper = first;
int line_bytes = mat.rows ? mat.total() * mat.channels() / mat.rows : mat.cols * mat.channels();
for (int i = 0; i < mat.rows; ++i)
{
oper = first;
for (int j = 0; j < mat.cols; ++j)
{
unsigned char ch = oper[0];
oper[0] = oper[2];
oper[2] = ch;
oper += 3;
}
first += line_bytes;
}
}
// construction
public:
imgproc(LPSCANCONF img_param,LPIMGPRCPARAM param,int pid) : img_conf_(*img_param),param_(*param),pid_(pid),papersize_(pid_)
{
my_path_ = hg_log::pe_path();
}
~imgproc()
{}
// load data
public:
int load_raw_data(std::shared_ptr<std::vector<char>> buff)
{
buffer_.reset(new std::vector<char >(*buff));
mats_.clear();
return SCANNER_ERR_OK;
}
int load_file(const char* path_file)
{
mats_.clear();
FILE* src = fopen(path_file, "rb");
if (!src)
return SCANNER_ERR_OPEN_FILE_FAILED;
long len = 0;
fseek(src, 0, SEEK_END);
len = ftell(src);
fseek(src, 0, SEEK_SET);
if (len > 1 * 1024 * 1024 * 1024)
{
fclose(src);
return SCANNER_ERR_INSUFFICIENT_MEMORY;
}
raw_data_.reset(new std::string());
raw_data_->resize(len);
fread(&(*raw_data_)[0], 1, len, src);
fclose(src);
return SCANNER_ERR_OK;
}
// image-processing
public:
int decode(int pid)
{
if (!buffer_)
return SCANNER_ERR_NO_DATA;
size_t origin = buffer_->size();
std::vector<std::shared_ptr<std::vector<char>>> buffs;
if(pid == 0x100 || pid == 0x200)
buffs = G200Decode(buffer_,img_conf_.is_duplex,img_conf_.is_switchfrontback).getImageBuffs();
else if(pid == 0x139 || pid == 0x239)
buffs = GRawDecode(buffer_).getImageBuffs();
else if(pid == 0x300 || pid == 0x400)
buffs = G400Decode(buffer_,img_conf_.is_duplex).getImageBuffs();
if(buffs.empty())
return -1;
buffer_.reset(new std::vector<char >());
int i=0;
for (auto& buf : buffs) {
i++;
cv::ImreadModes rmc = param_.channels > 1 ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE;
try
{
if (buf->at(0) == -119 && buf->at(1) == 0x50 && buf->at(2) == 0x4e && buf->at(3) == 0x47)
{
rmc = cv::IMREAD_GRAYSCALE;
param_.black_white = true;
}
else
param_.black_white = false;
if((pid == 0x100 || pid == 0x200 || pid == 0x300 || pid == 0x400)
&& (img_conf_.filter != 3
|| img_conf_.multiOutput == 1
|| img_conf_.multiOutput == 2
|| img_conf_.multiOutput == 0))
{
rmc = cv::IMREAD_COLOR;
}
cv::Mat mat(cv::imdecode(*buf, rmc));
//("/home/huagao/Desktop/1.jpg",mat);
if (mat.empty())
{
HG_LOG(LOG_LEVEL_FATAL, "decode image data error\n");
continue;
}
if(pid == 0x100 || pid == 0x200 || pid == 0x139 || pid == 0x239)
{
mats_.push_back(mat);
//cv::imwrite(std::to_string(i)+"_decode.jpg",mat);
}
else if(pid == 0x300 || pid == 0x400)
{
cv::Mat front = mat(cv::Rect(0, 0, mat.cols / 2, mat.rows));
cv::Mat back = mat(cv::Rect(mat.cols / 2, 0, mat.cols / 2, mat.rows));
if(img_conf_.is_duplex)
{
mats_.push_back(img_conf_.is_switchfrontback ? back :front);
mats_.push_back(img_conf_.is_switchfrontback ? front :back);
}
else
{
mats_.push_back(front);
}
back.release();
front.release();
}
//#ifndef mips64
buffer_.reset(new std::vector<char >());
//#endif
}
catch (const std::exception& e)
{
HG_LOG(LOG_LEVEL_FATAL, e.what());
}
}
buffs.clear();
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Decode %u bytes to %u picture(s)\n", origin, mats_.size());
if(mats_.size() == 0)
{
return SCANNER_ERR_NO_DATA;
}
return SCANNER_ERR_OK;
}
public:
int correct_text(void)
{
std::string sample(my_path_ + "/data/img/osd.traineddata");
CImageApplyRotation rot(CImageApplyRotation::RotationType::AutoTextOrientation, false, param_.dpi, sample.c_str());
rot.apply(mats_, img_conf_.is_duplex);
return SCANNER_ERR_OK;
}
int split(int multioutputtype,bool is_msplit,bool is_multiout_red,int colortype,bool is_duplex)
{
std::vector<cv::Mat> mats(mats_);
CImageApplySplit split(multioutputtype, is_msplit, is_multiout_red, colortype);;
mats_.clear();
auto matexs = split.SplitMats(mats,is_duplex);
std::string filename ;
for(auto &matex : matexs)
{
cv::flip(matex.mat,matex.mat,0);
cv::flip(matex.mat,matex.mat,1);
if(!matex.mat.empty())
mats_.push_back(matex.mat);
}
return SCANNER_ERR_OK;
}
int fadeback(int range,bool is_duplex)
{
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyFadeBackGroudColor fade(100,0,range);
for(size_t i = 0; i < mats.size();i++)
{
fade.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
// std::string filename = "/home/huagao/Desktop/fadeback("+std::to_string(num++)+").jpg";
// cv::imwrite(filename,mats_[i]);
// printf("fadeback.size :%d ,filename is =%s\r\n",mats_.size(),filename.c_str());
}
return SCANNER_ERR_OK;
}
int multi_out(void)
{
std::vector<cv::Mat> mats(mats_);
mats_.clear();
for (size_t i = 0; i < mats.size(); ++i)
{
if (mats[i].empty())
continue;
vector<cv::Mat> retmats;
std::vector<std::shared_ptr<IMulti>> m_multiprc_list;
int multiout = 1,
colormode = 1;
//if (m_param.imageProcess.filter == ColorFilter::FILTER_NONE)
//{
// colormode = m_param.pixelType;
//}
if (param_.channels > 1)
m_multiprc_list.push_back(shared_ptr<IMulti>(new ImageMultiOutputRed(2)));
m_multiprc_list.push_back(shared_ptr<IMulti>(new IMageMulti(multiout)));
for (int j = 0; j < m_multiprc_list.size(); j++)
{
retmats = m_multiprc_list[j]->apply(mats[i]);
}
CImageApplySplit isp(multiout, false, 1, colormode);
if (!retmats.size())
{
std::vector<cv::Mat> matse;
matse.push_back(mats[i]);
auto matexs = isp.SplitMats(matse, img_conf_.is_duplex);
for (auto& matex : matexs)
{
mats_.push_back(matex.mat);
}
break;
}
else
{
auto matexs = isp.SplitMats(retmats, img_conf_.is_duplex);
for (auto& matex : matexs)
{
mats_.push_back(matex.mat);
}
}
}
return SCANNER_ERR_OK;
}
int multi_out(int out_type)
{
std::vector<cv::Mat> mats(mats_);
std::vector<cv::Mat> mat;
mats_.clear();
IMageMulti output(out_type);
for(size_t i = 0;i < mats.size();i++)
{
mat = output.apply(mats[i]);
for(size_t j = 0;j < mat.size();j++)
{
mats_.push_back(mat[j]);
// std::string filename = "multi_out("+std::to_string(num++)+").jpg";
// cv::imwrite(filename,mat[j]);
}
}
return SCANNER_ERR_OK;
}
int multi_out_red()
{
std::vector<cv::Mat> mats(mats_);
std::vector<cv::Mat> mat;
mats_.clear();
mat.clear();
ImageMultiOutputRed outred(2);
for(size_t i = 0;i < mats.size();i++)
{
mat = outred.apply(mats[i]);
for(size_t j = 0;j < mat.size();j++)
{
mats_.push_back(mat[j]);
}
// std::string filename = "/home/huagao/Desktop/multi_out_red("+std::to_string(num++)+").jpg";
// cv::imwrite(filename,mats_[i]);
// printf("fadeback.size :%d ,filename is =%s\r\n",mats_.size(),filename.c_str());
}
return SCANNER_ERR_OK;
}
int auto_matic_color(int color_type)
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
for(size_t i = 0;i < mats.size();i++)
{
CImageApplyColorRecognition ColorRecognition(color_type==1?
CImageApplyColorRecognition::ColorRecognitionMode::Color_Gray :
CImageApplyColorRecognition::ColorRecognitionMode::Color_Mono);
ColorRecognition.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
/*pixtype 0 colcor; 1 gray; 2 bw*/
int auto_crop()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
SIZE temp_Size = papersize_.GetPaperSize(img_conf_.papertype,200,img_conf_.paperAlign);
cv::Size cvSize(temp_Size.cx, temp_Size.cy);
CImageApplyAutoCrop crop(img_conf_.is_autocrop,img_conf_.autodescrew,img_conf_.fillbackground,cvSize,true,img_conf_.isfillcolor);
crop.apply(mats,img_conf_.is_duplex);
mats_ = mats;
//cv::imwrite("/home/huagao/Desktop/mats_.jpg",mats_[0]);
return ret;
}
int fillhole()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
float scale = img_conf_.fillhole.fillholeratio / 100.0;
CImageApplyOutHole outh(200,scale,50);
outh.apply(mats,img_conf_.is_duplex);
mats_ = mats;
return ret;
}
int resolution_change()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyResize::ResizeType resizeType;
double ratio = 1.0;
SIZE reSize = papersize_.GetPaperSize(img_conf_.papertype, img_conf_.resolution_dst,img_conf_.paperAlign);
cv::Size cvSize(reSize.cx, reSize.cy);
if (img_conf_.is_autocrop || img_conf_.cropRect.enable)
{
resizeType = CImageApplyResize::ResizeType::RATIO;
ratio = img_conf_.resolution_dst / (float)img_conf_.resolution_native;
}
else
resizeType = CImageApplyResize::ResizeType::DSIZE;
CImageApplyResize resize(resizeType,cvSize,ratio,ratio);
resize.apply(mats,img_conf_.is_duplex);
if(!mats.empty())
mats_ = mats;
return ret;
}
int croprect()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyCustomCrop rect(cv::Rect(img_conf_.cropRect.x, img_conf_.cropRect.y, img_conf_.cropRect.width, img_conf_.cropRect.height));
for (size_t i = 0; i < mats.size(); ++i)
{
rect.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
int channel()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyChannel chl((CImageApplyChannel::channel)(img_conf_.filter));
for (size_t i = 0; i < mats.size(); i++)
{
chl.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
int customgamma(bool is_customgamma,unsigned char* table,int tableLength)
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
if(is_customgamma)
{
CImageApplyCustomGamma gamme(table,tableLength);
gamme.apply(mats,img_conf_.is_duplex);
}
else
{
if (img_conf_.brightness != 128 ||img_conf_.contrast != 4 || ((img_conf_.gamma < (1.0f - 1e-2)) || (img_conf_.gamma > (1.0f + 1e-2))) )
{
int temp_contrast = (img_conf_.contrast - 4) * 12;
CImageApplyAdjustColors justColors(img_conf_.brightness - 128, temp_contrast, img_conf_.gamma);
for (size_t i = 0; i < mats.size(); ++i)
{
justColors.apply(mats[i],img_conf_.is_duplex);
}
}
//cv::imwrite("/home/huagao/Desktop/customgamma2.jpg",mats_[0]);
}
mats_ = mats;
return ret;
}
//防止渗<E6ADA2>?
int antiInflow(int permeate_lv)
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyRefuseInflow Inflow(permeate_lv);
for (size_t i = 0; i < mats.size(); ++i)
{
Inflow.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
//色彩校正
int colorCorrection()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyAutoContrast con;
con.apply(mats,img_conf_.is_duplex);
mats_= mats;
return ret;
}
//图像旋转
int orentation()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
mats_.resize(mats.size());
CImageApplyRotation::RotationType rotatetype = CImageApplyRotation::RotationType::Invalid;
switch ((CImageApplyRotation::RotationType)img_conf_.imageRotateDegree)
{
case CImageApplyRotation::RotationType::Rotate_90_clockwise:
rotatetype = CImageApplyRotation::RotationType::Rotate_90_clockwise;
break;
case CImageApplyRotation::RotationType::Rotate_180:
rotatetype = CImageApplyRotation::RotationType::Rotate_180;
break;
case CImageApplyRotation::RotationType::Rotate_90_anti_clockwise:
rotatetype = CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
break;
default:
break;
}
if (img_conf_.is_autotext)
rotatetype = CImageApplyRotation::RotationType::AutoTextOrientation;
#ifdef WIN32
char szIniFile[MAX_PATH] = {0};
SHGetSpecialFolderPathA(NULL, szIniFile, CSIDL_WINDOWS, TRUE);
strcat(szIniFile, "\\twain_32\\HuaGoScan\\tessdata");
// m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyRotation(rotatetype, imgparams.BackRotate180, imgparams.DestResulution, szIniFile)));
#else // WIN32
CImageApplyRotation Rotation(rotatetype,img_conf_.is_backrotate180,img_conf_.resolution_native,"./tessdata");
Rotation.apply(mats,img_conf_.is_duplex);
mats_ = mats;
#endif
return ret;
}
//除网<E999A4>?
int textureRemove()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyTextureRemoval Removal;
Removal.apply(mats,img_conf_.is_duplex);
mats_ = mats;
return ret;
}
//锐化
int sharpenType()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyFilter::FilterMode sharpenType = (CImageApplyFilter::FilterMode)img_conf_.sharpen;
CImageApplyFilter Filte(sharpenType);
for (size_t i = 0; i < mats.size(); ++i)
{
Filte.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
//黑白降噪
int nosieDetach()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyDetachNoise Noise(img_conf_.detachnoise.detachnoise);
for (size_t i = 0; i < mats.size(); ++i)
{
Noise.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
//错误扩散
int errorextention()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyBWBinaray::ThresholdType thrtype;
if(img_conf_.errorExtention)
thrtype = CImageApplyBWBinaray::ThresholdType::ERROR_DIFFUSION;
else
thrtype = CImageApplyBWBinaray::ThresholdType::THRESH_BINARY;
CImageApplyBWBinaray BWBinaray(thrtype);
for (size_t i = 0; i < mats.size(); ++i)
{
BWBinaray.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
int discardBlank()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
double threshold = 40; //默认<E9BB98>?
int edge = 150;
CImageApplyDiscardBlank(threshold,edge,img_conf_.discardblank_percent);
for (size_t i = 0; i < mats.size(); ++i)
{
bool b = CImageApplyDiscardBlank::apply(mats[i]);
if (b)
mats[i].release();
else
mats_.push_back(mats[i]);
}
return ret;
}
//答题卡出<E58DA1>?
int answerSheetFilterRed()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyHSVCorrect correct((CImageApplyHSVCorrect::Red_Removal));
for (size_t i = 0; i < mats.size(); ++i)
{
correct.apply(mats[i],img_conf_.is_duplex);
mats_.push_back(mats[i]);
}
return ret;
}
//对折
int fold()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplyConcatenation fold(CImageApplyConcatenation::horizontal);
fold.apply(mats,img_conf_.is_duplex);
mats_= mats;
return ret;
}
//画质
int quality(int dpi_dst)
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
//mats_.resize(mats.size());
float xy = (float)dpi_dst/200.0;
for (size_t i = 0; i < mats.size(); ++i)
{
cv::Mat out;
cv::resize(mats[i],out, cv::Size(),xy,xy);
mats_.push_back(out);
}
return SCANNER_ERR_OK;
}
int ocr_auto_txtdirect()
{
int pDirect = -1;
int ret = SCANNER_ERR_OK;
void *pHanld = NULL;
#ifndef x86_64 //linux x86_64 暂时没有OCR三方
std::vector<cv::Mat> mats(mats_);
mats_.clear();
ret = HWOCR_SDKInitialize(&pHanld);
for (size_t i = 0; i < mats.size(); i++)
{
ret = HWOCR_GetFileDirectImage(const_cast<uchar*>(mats[i].data),mats[i].cols,mats[i].rows,mats[i].channels()== 1 ? TColorType::EGray256:TColorType::EColor16M,pHanld,&pDirect);
if(ret != 0)
{
return SCANNER_ERR_NO_DATA;
}
if(pDirect == 1)
pDirect = 3;
else if(pDirect == 3)
pDirect = 1;
CImageApplyRotation(CImageApplyRotation::RotationType(pDirect)).apply(mats[i],false);
mats_.push_back(mats[i]);
}
HWOCR_SDKExit(pHanld);
#endif
return ret;
}
int size_detection()
{
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
CImageApplySizeDetection paper(img_conf_.papertype);
for (size_t i = 0; i < mats.size(); ++i)
{
ret = paper.apply(mats[i]);
mats_.push_back(mats[i]);
}
if(ret == 1)
{
return SCANNER_ERR_DEVICE_SIZE_CHECK;
}
return SCANNER_ERR_OK;
}
// final
public:
int final(void)
{
std::vector<cv::Mat> mats(mats_);
mats_.clear();
for (size_t i = 0; i < mats.size(); ++i)
{
if (mats[i].empty())
continue;
int bpp = param_.black_white ? 8 : param_.bits * param_.channels;
MatEx out(mats[i], bpp);
if (out.mat.channels() == 3)
swap_rgb(out.mat);
mats_.push_back(out.mat);
//cv::imwrite(std::to_string(i++)+"_final.jpg",out.mat);
}
return SCANNER_ERR_OK;
}
int get_final_data(LPIMGHEAD pimh, void** buf, int index)
{
if ((index < 0 || index >= mats_.size()))
return SCANNER_ERR_NO_DATA;
pimh->width = mats_[index].cols;
pimh->height = mats_[index].rows;
pimh->bits = 8; //mats_[index].depth
pimh->channels = mats_[index].channels();
pimh->total_bytes = mats_[index].total() * pimh->channels;
pimh->line_bytes = pimh->height ? pimh->total_bytes / pimh->height : pimh->width * pimh->channels;
*buf = mats_[index].data;
//printf("pimh->channels = %d \r\n",pimh->channels);
return SCANNER_ERR_OK;
}
int get_final_data(LPIMGHEAD pimh, std::vector<unsigned char>* buf, int index)
{
if ((index < 0 || index >= mats_.size()))
return SCANNER_ERR_NO_DATA;
pimh->width = mats_[index].cols;
pimh->height = mats_[index].rows;
pimh->bits = 8; //mats_[index].depth
pimh->channels = mats_[index].channels();
if((pimh->width * pimh->channels) % 4)
{
int len = pimh->width * pimh->channels;
pimh->line_bytes = (len + 3) / 4 * 4;
pimh->total_bytes = pimh->line_bytes * pimh->height;
buf->resize(pimh->total_bytes);
//printf("pimh->total_bytes=%d pimh->line_bytes=%d\r\n",pimh->total_bytes,pimh->line_bytes);
unsigned char* src = mats_[index].data, *dst = buf->data();
for(int i = 0; i < pimh->height; ++i)
{
memcpy(dst, src, len);
dst += pimh->line_bytes;
src += len;
}
}
else
{
pimh->total_bytes = mats_[index].total() * pimh->channels;
pimh->line_bytes = pimh->height ? pimh->total_bytes / pimh->height : pimh->width * pimh->channels;
buf->resize(pimh->total_bytes);
memcpy(buf->data(), mats_[index].data, pimh->total_bytes);
//cv::imwrite(to_string(index)+"_final.jpg",mats_[index]);
}
//printf("pimh->channels_01 = %d \r\n",pimh->channels);
return SCANNER_ERR_OK;
}
int imgtypechange(std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata)
{
int ret = SCANNER_ERR_OK;
if(!buf)
{
return SCANNER_ERR_NO_DATA;
}
cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
return ret;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// api ...
HIMGPRC init(LPSCANCONF parameter,LPIMGPRCPARAM param,int pid)
{
imgproc* obj = new imgproc(parameter,param,pid);
return (HIMGPRC)obj;
}
int load_buffer(HIMGPRC himg, std::shared_ptr<std::vector<char>> buff)
{
return ((imgproc*)himg)->load_raw_data(buff);
}
int load_file(HIMGPRC himg, const char* path_file)
{
return ((imgproc*)himg)->load_file(path_file);
}
int decode(HIMGPRC himg,int pid)
{
return ((imgproc*)himg)->decode(pid);
}
int correct_text(HIMGPRC himg)
{
return ((imgproc*)himg)->correct_text();
}
int split(HIMGPRC himg,int multioutputtype,bool is_msplit,bool is_multiout_red,int colortype,bool is_duplex)
{
return ((imgproc*)himg)->split( multioutputtype, is_msplit, is_multiout_red, colortype,is_duplex);
}
int fadeback(HIMGPRC himg,int range,bool is_duplex)
{
return ((imgproc*)himg)->fadeback(range,is_duplex);
}
int multi_out(HIMGPRC himg)
{
return ((imgproc*)himg)->multi_out();
}
int multi_out(HIMGPRC himg,int out_type)
{
return ((imgproc*)himg)->multi_out(out_type);
}
int multi_out_red(HIMGPRC himg)
{
return ((imgproc*)himg)->multi_out_red();
}
int auto_matic_color(HIMGPRC himg,int color_type)
{
return ((imgproc*)himg)->auto_matic_color(color_type);
}
int auto_crop(HIMGPRC himg)
{
return ((imgproc*)himg)->auto_crop();
}
int fillhole(HIMGPRC himg)
{
return ((imgproc*)himg)->fillhole();
}
int resolution_change(HIMGPRC himg)
{
return ((imgproc*)himg)->resolution_change();
}
int croprect(HIMGPRC himg)
{
return ((imgproc*)himg)->croprect();
}
int channel(HIMGPRC himg)
{
return ((imgproc*)himg)->channel();
}
int customgamma(HIMGPRC himg,bool is_custogamma,unsigned char* table,int tableLength)
{
return ((imgproc*)himg)->customgamma(is_custogamma,table,tableLength);
}
int antiInflow(HIMGPRC himg,int permeate_lv)
{
return ((imgproc*)himg)->antiInflow(permeate_lv);
}
int colorCorrection(HIMGPRC himg)
{
return ((imgproc*)himg)->colorCorrection();
}
int orentation(HIMGPRC himg)
{
return ((imgproc*)himg)->orentation();
}
int textureRemove(HIMGPRC himg)
{
return ((imgproc*)himg)->textureRemove();
}
int sharpenType(HIMGPRC himg)
{
return ((imgproc*)himg)->sharpenType();
}
int nosieDetach(HIMGPRC himg)
{
return ((imgproc*)himg)->nosieDetach();
}
int errorextention(HIMGPRC himg)
{
return ((imgproc*)himg)->errorextention();
}
int discardBlank(HIMGPRC himg)
{
return ((imgproc*)himg)->discardBlank();
}
int answerSheetFilterRed(HIMGPRC himg)
{
return ((imgproc*)himg)->answerSheetFilterRed();
}
//img_type_ = jpg png bmp
int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata)
{
return ((imgproc*)himg)->imgtypechange(img_type_,buf,bmpdata);
}
int fold(HIMGPRC himg)
{
return ((imgproc*)himg)->fold();
}
int quality(HIMGPRC himg,int dpi)
{
return ((imgproc*)himg)->quality(dpi);
}
int ocr_auto_txtdirect(HIMGPRC himg)
{
return ((imgproc*)himg)->ocr_auto_txtdirect();
}
int size_detection(HIMGPRC himg)
{
return ((imgproc*)himg)->size_detection();
}
int final(HIMGPRC himg)
{
return ((imgproc*)himg)->final();
}
int get_final_data(HIMGPRC himg, LPIMGHEAD pimh, void** buf, int index)
{
return ((imgproc*)himg)->get_final_data(pimh, buf, index);
}
int get_final_data(HIMGPRC himg, LPIMGHEAD pimh, std::vector<unsigned char>* buf, int index)
{
return ((imgproc*)himg)->get_final_data(pimh, buf, index);
}
void release(HIMGPRC himg)
{
imgproc* obj = (imgproc*)himg;
delete obj;
}
}