mirror of http://192.168.1.51:8099/lmh188/uv-twain
86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
/*
|
||
* ====================================================
|
||
|
||
* 功能:本地图片进行OCR,并生成多页PDF功能
|
||
* 作者:刘丁维
|
||
* 生成时间:2020/3/5
|
||
* 最近修改时间:2020/3/5
|
||
* 版本号:v1.0
|
||
|
||
* ====================================================
|
||
*/
|
||
|
||
#ifndef HG_GPDF_H
|
||
#define HG_GPDF_H
|
||
|
||
#if defined (_WIN32)
|
||
#if !defined (HG_GPDF_API_BUILD)
|
||
#define HG_GPDF_API __declspec(dllexport)
|
||
#else
|
||
#define HG_GPDF_API __declspec(dllimport)
|
||
#endif
|
||
#else
|
||
#define HG_GPDF_API
|
||
#endif
|
||
|
||
class HG_GPDF_API HG_OCR
|
||
{
|
||
public:
|
||
|
||
//识别模式
|
||
enum RECOGNITION_MODE
|
||
{
|
||
RECOGNITION_OSD, //文稿方向识别模式
|
||
RECOGNITION_OCR //字符识别模式
|
||
};
|
||
|
||
//字符识别保存模式
|
||
enum SAVE_MODE
|
||
{
|
||
SAVE_PDF = 0x01, //PDF保存字符识别结果
|
||
SAVE_TXT = 0x02, //TXT保存字符识别结果
|
||
SAVE_PDF_TXT = 0x03 //同时采用PDF和TXT保存字符识别结果
|
||
};
|
||
public:
|
||
|
||
HG_OCR();
|
||
|
||
~HG_OCR();
|
||
|
||
/*
|
||
* 函数功能:初始化PDF生成器
|
||
* trainFile:[in] 训练库文件路径,不含文件名,末尾无需'/'结尾
|
||
* mode:[in] 具体选项参照 enum RECOGNITION_MODE,默认值为RECOGNITION_OCR
|
||
* 返回值:0为成功,否则为异常。异常查看打印输出
|
||
*/
|
||
int init(const char* trainFile, RECOGNITION_MODE mode = RECOGNITION_OCR);
|
||
|
||
/*
|
||
* 函数功能:字符识别,并生成文本
|
||
* inputFileNames:[in] 本地待识别图片完整路径,可同时输入多个图片路径
|
||
* numOfFiles:[in] inputFileNames长度
|
||
* numOfFiles:[in] inputFileNames长度
|
||
* outputFileName:[in] 识别结果保存路径,包含文件基础名字,不含文件后缀名
|
||
* flag:[in] 字符识别保存模式,参照 enum SAVE_MODE
|
||
* 返回值:true为成功,否则为异常。异常查看打印输出
|
||
*/
|
||
bool ocr(const char** inputFileNames, int numOfFiles, const char* outputFileName, SAVE_MODE flag = SAVE_PDF);
|
||
|
||
/*
|
||
* 函数功能:文本方向识别
|
||
* data:[in] 图像数据指针
|
||
* width:[in] 图像宽度
|
||
* height:[in] 图像高度
|
||
* channels:[in] 图像通道
|
||
* dpi:[in] 图片DPI
|
||
* 返回值:以顺时针进行计数,输出0,90,180,270四种结果
|
||
*/
|
||
int orientation(const unsigned char* data, int width, int height, int channels, int dpi);
|
||
|
||
private:
|
||
void* m_ptr;
|
||
};
|
||
|
||
|
||
#endif //HG_GPDF_H
|