178 lines
7.1 KiB
C
178 lines
7.1 KiB
C
|
#include "./ocrcommon.h"
|
|||
|
|
|||
|
//使用动态库的时候需要将 hwusbdev.key 放到应用程序相同路径
|
|||
|
//文件类型
|
|||
|
#define FILE_PDF 0 //输出精确版面复原的简体PDF文件
|
|||
|
#define FILE_RTF 2 //输出精确版面复原的简体RTF文件
|
|||
|
#define FILE_XLS 5 //输出简体XLS文件
|
|||
|
#define FILE_TXT 100 //输出为文本格式
|
|||
|
#define FILE_PDF_TXT 101 //输出文本加pdf
|
|||
|
#define FILE_JSON 200 //输出为json格式
|
|||
|
#define FILE_OFD 300 //输出双层ofd格式
|
|||
|
|
|||
|
#define STATUS_OK 0
|
|||
|
#define STATUS_NO_MEMORY -1
|
|||
|
#define STATUS_INVALID_PARAMETER -2
|
|||
|
#define STATUS_FAILED -3
|
|||
|
|
|||
|
//顺时针角度
|
|||
|
enum ROTATETYPEOUT
|
|||
|
{
|
|||
|
ROT0, //未旋转
|
|||
|
ROT90, //顺时针旋转90度
|
|||
|
ROT180, //顺时针旋转180度
|
|||
|
ROT270, //顺时针旋转270度
|
|||
|
};
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能: 初始化
|
|||
|
参数: ppstOcrHandle [I/O] 初始化识别句柄
|
|||
|
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_SDKInitialize(void **ppstOcrHandle);
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别jpg/bmp/tiff/png/gif图像文件,输出txt/json/rtf/xls/pdf格式
|
|||
|
参数: ImgFile [I] 输入图像路径及文件名
|
|||
|
OutFile [I] 输出文件名
|
|||
|
nFileType [I] 输出文件类型
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pLibDir [I] db文件所在目录
|
|||
|
pTmpDir [I] 保存临时文件的目录,需要有写权限,有时需要生成tmp.jpg文件。没有传此参数或者传NULL时,必要时会在pLibDir下生成tmp.jpg图像。
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_RecognizeFile(unsigned char*ImgFile, unsigned char *OutFile, int nFileType, void *pstHandle, char *pLibDir, char *pTmpDir=NULL);
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别jpg/bmp/tiff/png/gif批量图像文件,输出txt/json/rtf/xls/pdf格式
|
|||
|
参数: ppImageFiles [I] 输入图像路径及文件名
|
|||
|
OutFile [I] 输出文件名
|
|||
|
nFileType [I] 输出文件类型
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pLibDir [I] db文件所在目录
|
|||
|
pTmpDir [I] 保存临时文件的目录,需要有写权限,有时需要生成tmp.jpg文件。没有传此参数或者传NULL时,必要时会在pLibDir下生成jpg图像。
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
|
|||
|
int HWOCR_RecognizeFileBatch(char ** ppImageFiles, BYTE *OutFile, int nFileType, void *pstHandle, char *pLibDir, char *pTmpDir = NULL);
|
|||
|
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别内存图像的指定块,输出txt/json/rtf格式
|
|||
|
参数: pbImage [I] 图像数据
|
|||
|
nWidth [I] 图像宽度
|
|||
|
nHeight [I] 图像高度
|
|||
|
aLayoutInfo [I] 块属性
|
|||
|
nColorType [I] 颜色属性
|
|||
|
OutFile [I] 输出文件名
|
|||
|
nFileType [I] 输出文件类型
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pLibDir [I] db文件所在目录
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_RecognizeImgBlock(unsigned char*pbImage, int nWidth, int nHeight, TOCRLayoutBlockInfo aLayoutInfo,
|
|||
|
TColorType nColorType, BYTE *OutFile, int nFileType, void *pstHandle, char *pLibDir);
|
|||
|
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别jpg/bmp/tiff/png/gif图像文件,输出识别结果字符串
|
|||
|
参数: ImgFile [I] 输入图像路径及文件名
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
ppRst [O] 识别结果字符串
|
|||
|
pnLen [O] 字符串长度
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_RecognizeFile2Str(BYTE*ImgFile, void *pstHandle,char **ppRst,int* pnLen);
|
|||
|
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能: 释放识别结果
|
|||
|
参数: ppRst [I] 识别结果字符串
|
|||
|
|
|||
|
返回值: 无
|
|||
|
****************************************/
|
|||
|
void HWOCR_FreeStrRst(char **ppRst);
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能: 判断识别方向
|
|||
|
参数: ImgFile [I] 输入图像路径及文件名
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pDirect [O] 图像方向
|
|||
|
//顺时针角度
|
|||
|
enum ROTATETYPEOUT
|
|||
|
{
|
|||
|
ROT0, //未旋转
|
|||
|
ROT90, //顺时针旋转90度
|
|||
|
ROT180, //顺时针旋转180度
|
|||
|
ROT270, //顺时针旋转270度
|
|||
|
};
|
|||
|
|
|||
|
返回值: 正常为0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_GetFileDirect(BYTE*ImgFile, void *pstHandle, int *pDirect);
|
|||
|
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能: 判断识别方向,支持24bit 8bit 1bit内存图像。
|
|||
|
参数: pbImage [I] 输入内存图像
|
|||
|
nWidth [I] 图像宽度
|
|||
|
nHeight [I] 图像高度
|
|||
|
nColorType [I] 颜色属性
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pDirect [O] 图像方向
|
|||
|
//顺时针角度
|
|||
|
enum ROTATETYPEOUT
|
|||
|
{
|
|||
|
ROT0, //未旋转
|
|||
|
ROT90, //顺时针旋转90度
|
|||
|
ROT180, //顺时针旋转180度
|
|||
|
ROT270, //顺时针旋转270度
|
|||
|
};
|
|||
|
|
|||
|
返回值: 正常为0,否则<0
|
|||
|
****************************************/
|
|||
|
|
|||
|
int HWOCR_GetFileDirectImage(BYTE*pbImage, int nWidth, int nHeight, TColorType nColorType, void *pstHandle, int *pDirect);
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别ofd图像文件,输出txt/json/rtf/xls/pdf/ofd格式
|
|||
|
参数: OfdFile [I] 输入文件路径及文件名
|
|||
|
OutFile [I] 输出文件名
|
|||
|
nFileType [I] 输出文件类型
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pLibDir [I] 传NULL
|
|||
|
pTmpDir [I] 保存临时文件的目录,需要有写权限,有时需要生成tmp.jpg文件。
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_RecognizeOFD(BYTE*OfdFile, BYTE *OutFile, int nFileType, void *pstHandle, char *pLibDir, char *pTmpDir);
|
|||
|
|
|||
|
/**************************************
|
|||
|
功能:识别pdf图像文件,输出txt/json/rtf/xls/pdf/ofd格式
|
|||
|
参数: PdfFile [I] 输入文件路径及文件名
|
|||
|
OutFile [I] 输出文件名
|
|||
|
nFileType [I] 输出文件类型
|
|||
|
pstHandle [I] 输入句柄,初始化返回的结果
|
|||
|
pLibDir [I] 传NULL
|
|||
|
pTmpDir [I] 保存临时文件的目录,需要有写权限。
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
int HWOCR_RecognizePDF(BYTE*PdfFile, BYTE *OutFile, int nFileType, void *pstHandle, char *pLibDir, char *pTmpDir);
|
|||
|
|
|||
|
/*********************************
|
|||
|
功能:调用识别pdf函数前,调用此初始化函数
|
|||
|
**********************************/
|
|||
|
void HWOCR_InitPdf();
|
|||
|
|
|||
|
/*********************************
|
|||
|
功能:调用识别pdf函数后,调用此退出函数
|
|||
|
**********************************/
|
|||
|
void HWOCR_ExitPdf();
|
|||
|
/**************************************
|
|||
|
功能: 释放识别句柄
|
|||
|
参数: pstOcrHandle [I] 初始化时的句柄
|
|||
|
|
|||
|
返回值:正常返回0,否则<0
|
|||
|
****************************************/
|
|||
|
void HWOCR_SDKExit(void *pstOcrHandle);
|