code_device/hgdriver/hgdev/image_process.h

238 lines
8.7 KiB
C
Raw Normal View History

2022-07-18 07:04:48 +00:00
#pragma once
2022-05-03 03:56:07 +00:00
// API for image process
//
// created on 2022-03-01
//
#include "huagao/hgscanner_error.h"
#include "common_setting.h"
#include <memory>
#include <vector>
#include <sane/sane_ex.h>
2022-12-28 01:56:54 +00:00
#include "../ImageProcess/ImageApplyHeaders.h"
//#include <vld.h>
class tiny_buffer;
2022-05-03 03:56:07 +00:00
namespace hg_imgproc
{
typedef struct _img_data
{
int img_fmt; // 图片格式BMP、PNG……暂时未用
int width; // 行宽度(像素数)
int height; // 高度(像素数)
int line_bytes; // 每行的字节数
int bits; // 每个像素的位深
bool is_bw; // 是否为黑白图片,由图像处理模块设置
unsigned bytes; // 图像数据字节数(buf中的字节数)
void* ip_data; // 图像处理模块的自定义数据,调用者不要随意更改此值!!!
void* buf; // 图像数据信息
}IMGDATA, *LPIMGDATA;
// 用于释放图像处理模块返回的各种动态内存, mem[i] == NULL 时终止,下列相同参数均照此规则
void imgproc_free_memory(LPIMGDATA* mem);
// 所有函数均返回“int”值代表错误代码 0为成功其它错误码由图像处理模块开发者定义
// Function: 用于将原始数据如图像文件内容解码为target_fmt指定的图像格式
//
// Parameters: raw - 原始的图像数据
//
// bytes - raw中数据字节数
//
// bits - 位深
//
// out - 用于接收解码后的图像数据。由图像处理模块分配内存调用者调用imgproc_free_memory释放
//
// Return: 错误码
//
// NOTE: 该函数返回的out结构体中buf为图像处理的中间数据类型如cv::mat*),要想获取最终的图片数据,
// 需要再调用 imgproc_final 函数进行转换
int imgproc_decode(void* buf, unsigned bytes, int bits, LPIMGDATA** out);
// Function: 将倾斜的文本校正
//
// Parameters: raw - [in]: 原始的图像数据,*raw == NULL时终止
//
// [out]: 最终的图像数据
//
// out - 用于接收解码后的图像数据。由图像处理模块分配内存调用者调用imgproc_free_memory释放
//
// dpi - 图片DPI
//
// double_face - 是否双面
//
// Return: 错误码
int imgproc_correct_text(LPIMGDATA** raw, int dpi, bool double_face); // 适用于raw从其它图像处理函数返回的情况
int imgproc_correct_text(LPIMGDATA* raw, LPIMGDATA** out, int dpi, bool double_face); // 适用于raw从文件或者内存中转换而来
// Function: 自动匹配颜色
//
// Parameters: raw - [in]: 原始的图像数据,*raw == NULL时终止
//
// [out]: 最终的图像数据
//
// out - 用于接收解码后的图像数据。由图像处理模块分配内存调用者调用imgproc_free_memory释放
//
// double_face - 是否双面
//
// Return: 错误码
int imgproc_auto_adjust_color(LPIMGDATA** raw, bool double_face); // 适用于raw从其它图像处理函数返回的情况
int imgproc_auto_adjust_color(LPIMGDATA* raw, LPIMGDATA** out, bool double_face); // 适用于raw从文件或者内存中转换而来
// Function: 图像拆分
//
// Parameters: raw - [in]: 原始的图像数据,*raw == NULL时终止
//
// [out]: 最终的图像数据
//
// out - 用于接收解码后的图像数据。由图像处理模块分配内存调用者调用imgproc_free_memory释放
//
// Return: 错误码
int imgproc_split(LPIMGDATA** raw); // 适用于raw从其它图像处理函数返回的情况
int imgproc_split(LPIMGDATA* raw, LPIMGDATA** out); // 适用于raw从文件或者内存中转换而来
// Function: 多流输出
//
// Parameters: raw - [in]: 原始的图像数据,*raw == NULL时终止
//
// out - 用于接收解码后的图像数据。由图像处理模块分配内存调用者调用imgproc_free_memory释放
//
// dpi - 图片DPI
//
// double_face - 是否双面
//
// Return: 错误码
int imgproc_multi_out(LPIMGDATA* raw, LPIMGDATA** out, int dpi, bool double_face);
enum
{
TARGET_FORMAT_GRAY = 1 << 0,
TARGET_FORMAT_BLACK_WHITE = 1 << 1,
TARGET_FORMAT_RGB = 1 << 2,
};
// Function: 用于将图像处理过程的中间态数据,转换为最终的图片数据
//
// Parameters: raw - [in]: 原始的图像数据,*raw == NULL时终止通常该变量是由其它图像处理函数返回的
//
// [out]: 最终的图像数据
//
// target_fmt - 预期解码到的格式TARGET_FORMAT_xxx
//
// Return: 错误码
int imgproc_final(LPIMGDATA** raw, int target_fmt, int dpi);
////////////////////////////////////////////////////////////////////////////////
// NEWflow ...
//
// 1 - call init to initialize an image processing object handle HIMGPRC
//
// 2 - call load_buffer or load_file to load raw data
//
// 3 - call image-processing methods
//
// 4 - repeat step-3
//
// 5 - call final to got outputing data
//
// 6 - call get_final_data to get outputing data, while return SCANNER_ERR_NO_DATA
2022-05-03 03:56:07 +00:00
//
// 7 - call release to free the HIMGPRC handle
//
////////////////////////////////////////////////////////////////////////////////
typedef void* HIMGPRC;
typedef struct _img_proc_param
{
int dpi;
int bits; // 单分量位深
int channels;
int color_mode;
bool double_side;
bool black_white;
2022-12-28 01:56:54 +00:00
bool cis_image; //设置原图
2023-09-22 06:17:06 +00:00
int width; // in pixel
int height; // in pixel
unsigned total_bytes;// total bytes
bool is_sup_real_300dpi_;
bool is_sup_real_600dpi_;
2023-09-22 06:17:06 +00:00
bool device_7010;
2022-05-03 03:56:07 +00:00
}IMGPRCPARAM, *LPIMGPRCPARAM;
typedef struct _img_header
{
int width; // in pixel
int height; // in pixel
int bits; // per channel
int channels; // RGB - 3; GRAY - 1; ...
int line_bytes; // bytes of ONE line
unsigned total_bytes;// total bytes
SANE_Image_Statu statu; // added on 2022-07-23
2022-05-03 03:56:07 +00:00
}IMGHEAD, *LPIMGHEAD;
HIMGPRC init(int pid, bool isx86Advan_);
int load_buffer(HIMGPRC himg,std::shared_ptr<tiny_buffer> buff);
2022-05-03 03:56:07 +00:00
int load_file(HIMGPRC himg, const char* path_file);
//图像数据转换
2023-09-22 06:17:06 +00:00
int decode(HIMGPRC himg,int pid, LPSCANCONF img_param, LPIMGPRCPARAM param, std::map<int, setting3288dsp::FLAT_INFO_IMAGE>& correction_image_map_);
2022-05-03 03:56:07 +00:00
int correct_text(HIMGPRC himg);
int init_auto_txt_hanld(HIMGPRC himg);
int free_auto_txt_hanld(HIMGPRC himg);
2022-05-03 03:56:07 +00:00
//拆分
2022-10-20 06:58:26 +00:00
int split(HIMGPRC himg,int split3399);
int fadeback(HIMGPRC himg);
int multi_out(HIMGPRC himg,int out_type, int bw_threshold);
2022-05-03 03:56:07 +00:00
int multi_out_red(HIMGPRC himg);
int auto_matic_color(HIMGPRC himg,int color_type);
int auto_crop(HIMGPRC himg, float dpi);
int dispersion(HIMGPRC himg);
2022-09-11 15:56:27 +00:00
int fillhole(HIMGPRC himg, float top, float low, float r, float l);
int resolution_change(HIMGPRC himg,float dpi3288);
2022-05-03 03:56:07 +00:00
int croprect(HIMGPRC himg);
int channel(HIMGPRC himg);
int adjust_color(HIMGPRC himg, unsigned char* table = nullptr, int tableLength = 0/*default value is to adjust color, or apply custom gamma*/);
2022-05-03 03:56:07 +00:00
int antiInflow(HIMGPRC himg,int permeate_lv);
int colorCorrection(HIMGPRC himg);
int orentation(HIMGPRC himg);
int textureRemove(HIMGPRC himg);
int remove_morr(HIMGPRC himg);
2022-05-03 03:56:07 +00:00
int sharpenType(HIMGPRC himg);
int nosieDetach(HIMGPRC himg);
int errorextention(HIMGPRC himg, int bw_threshold);
2022-05-03 03:56:07 +00:00
int discardBlank(HIMGPRC himg);
int answerSheetFilterRed(HIMGPRC himg);
int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata);
int fold(HIMGPRC himg);
2022-05-09 11:27:10 +00:00
int quality(HIMGPRC himg,int dpi);
2022-05-11 03:27:11 +00:00
int ocr_auto_txtdirect(HIMGPRC himg);
int tesseract_auto_txtdirect(HIMGPRC himg);
2022-05-19 06:35:38 +00:00
int size_detection(HIMGPRC himg);
2022-12-28 01:56:54 +00:00
int cis_test_image(HIMGPRC himg, CISTestImageProcess::CISTestResult& res);
int color_cast_correction(HIMGPRC himg);
2023-10-08 10:03:11 +00:00
int lost_frame_test(HIMGPRC himg);
2022-05-03 03:56:07 +00:00
int final(HIMGPRC himg);
2023-09-22 06:17:06 +00:00
int correction_image(HIMGPRC himg, cv::Mat& flat_lut, cv::Mat black_mat, cv::Mat white_mat);
2022-05-03 03:56:07 +00:00
// pimh must not to be NULL, and pimh->total_bytes indicates the length of 'buf'
//
// if 'buf' was NULL, then return SCANNER_ERR_INSUFFICIENT_MEMORY
2022-05-03 03:56:07 +00:00
//
// index is ZERO-base, if index is valid, fill the 'pimh' first, and copy data to buf if it was not NULL
// return SCANNER_ERR_NO_DATA if it was out of range
2022-05-03 03:56:07 +00:00
//
// return SCANNER_ERR_OK if index has valid image data and buf is large enough
2022-05-03 03:56:07 +00:00
int get_final_data(HIMGPRC himg, LPIMGHEAD pimh, void** buf, int index = 0);
int get_final_data(HIMGPRC himg, LPIMGHEAD pimh, std::vector<unsigned char>* buf, int index);
void dump_2_file(HIMGPRC himg, const char* local_file);
2022-05-03 03:56:07 +00:00
void release(HIMGPRC himg);
// seperate utilites ...
int convert_image_file(SANE_ImageFormatConvert* conv);
2022-07-14 06:21:53 +00:00
int save_2_bmp_file(const char* bmp_file, LPIMGHEAD head, void* buf, int resolution);
std::string bmp8_2_1bit(const unsigned char* data, int w, int h, int line_len, int threshold, bool reverse, bool align);
2022-05-03 03:56:07 +00:00
}