新增文稿自动方向识别

This commit is contained in:
luoliangyi 2022-05-11 11:27:11 +08:00
parent 9ef1efab77
commit afa11b6d16
11 changed files with 237 additions and 146 deletions

View File

@ -1,176 +1,176 @@
#include "./ocrcommon.h"
#include "./ocrcommon.h"
//文件类型
#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 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度
ROT0, //未旋转
ROT90, //顺时针旋转90度
ROT180, //顺时针旋转180度
ROT270, //顺时针旋转270度
};
/**************************************
ppstOcrHandle [I/O]
ppstOcrHandle [I/O]
0<0
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
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
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
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
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]
ppRst [I]
****************************************/
void HWOCR_FreeStrRst(char **ppRst);
/**************************************
ImgFile [I]
pstHandle [I]
pDirect [O]
//顺时针角度
ImgFile [I]
pstHandle [I]
pDirect [O]
//顺时针角度
enum ROTATETYPEOUT
{
ROT0, //未旋转
ROT90, //顺时针旋转90度
ROT180, //顺时针旋转180度
ROT270, //顺时针旋转270度
ROT0, //未旋转
ROT90, //顺时针旋转90度
ROT180, //顺时针旋转180度
ROT270, //顺时针旋转270度
};
0<0
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]
//顺时针角度
,24bit 8bit 1bit内存图像
pbImage [I]
nWidth [I]
nHeight [I]
nColorType [I]
pstHandle [I]
pDirect [O]
//顺时针角度
enum ROTATETYPEOUT
{
ROT0, //未旋转
ROT90, //顺时针旋转90度
ROT180, //顺时针旋转180度
ROT270, //顺时针旋转270度
ROT0, //未旋转
ROT90, //顺时针旋转90度
ROT180, //顺时针旋转180度
ROT270, //顺时针旋转270度
};
0<0
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
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
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函数前
pdf函数前
**********************************/
void HWOCR_InitPdf();
/*********************************
pdf函数后退
pdf函数后退
**********************************/
void HWOCR_ExitPdf();
/**************************************
pstOcrHandle [I]
pstOcrHandle [I]
0<0
0<0
****************************************/
void HWOCR_SDKExit(void *pstOcrHandle);

View File

@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include "ocrcommon.h"
#include "hanwangOCRdetect.h"
@ -8,7 +8,7 @@
int main()
{
unsigned char pbIn[] = ".\\1.bmp";
unsigned char pbIn[] = "1.jpg";
unsigned char pbOut[] = ".\\1.pdf";
char pbDir[] = ".\\";
@ -17,17 +17,17 @@ int main()
TOCRLayoutBlockInfo aLayoutInfo;
TColorType nColorType;
HWOCR_SDKInitialize(&pHandel);
HWOCR_RecognizeFile((unsigned char*)pbIn, (unsigned char* )pbOut, 0, pHandel, NULL, pbDir);
HWOCR_RecognizeFile((unsigned char*)pbIn, (unsigned char* )pbOut, 0, pHandel, NULL, pbDir);
char *pRst = NULL;
char *pRst = NULL;
int nLen = 0;
HWOCR_RecognizeFile2Str((unsigned char*) pbIn, pHandel,&pRst, &nLen);
FILE *fp = fopen(rst.txt, wb);
FILE *fp = fopen("rst.txt", "wb");
fwrite(pRst, 1, nLen, fp);
fclose(fp);
HWOCR_FreeStrRst(&pRst);
int nDirect = 0;
HWOCR_GetFileDirect((unsigned char*)pImgPath, pHandel, &nDirect);
int nDirect = 0;
HWOCR_GetFileDirect((unsigned char*)pbOut, pHandel, &nDirect);
fp = fopen("rst.txt", "wb");
fprintf(fp,"%d\r\n",nDirect);
fclose(fp);

View File

@ -42,9 +42,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE usb-1.0)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../3rdparty/nick
${PROJECT_SOURCE_DIR}/../ImageProcess
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/include/hanwangOCRdetect.h
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/include/ocrcommon.h
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/include
${PROJECT_SOURCE_DIR}/../../../sdk/include
${PROJECT_SOURCE_DIR}/../3rdparty/hanwangOCRdetect.h
${PROJECT_SOURCE_DIR}/../3rdparty/ocrcommon.h
)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../build/)

View File

@ -727,7 +727,7 @@ typedef struct _scan_conf
unsigned char papertype; /**< the current paper source ADF or Flatbed*/
unsigned char paperAlign;
unsigned char en_sizecheck; /**< 尺寸检测*/
float imageRotateDegree;
float imageRotateDegree; /**< 旋转 */
unsigned char is_duplex; /**< True to use duplex false for simplex, ignored if flatbed*/
unsigned char en_fold; /**<对折*/
int pixtype; /**< type of pixels to transfer image as */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,14 @@
#include "../ImageProcess/ImageApplyHeaders.h"
#include "ImageMultiOutput.h"
#include "PaperSize.h"
extern "C"
{
#include "ocr/hanwangOCRdetect.h"
#include "ocr/ocrcommon.h"
};
#include <dlfcn.h>
#ifdef WIN32
#include "scanner_manager.h"
#endif
@ -515,9 +522,11 @@ namespace hg_imgproc
int ret = HG_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_.is_autotext)
switch ((CImageApplyRotation::RotationType)img_conf_.imageRotateDegree)
{
case CImageApplyRotation::RotationType::Rotate_90_clockwise:
rotatetype = CImageApplyRotation::RotationType::Rotate_90_clockwise;
@ -532,7 +541,7 @@ namespace hg_imgproc
break;
}
if (img_conf_.is_autotext== TEXT_DIRECTION_AUTO)
if (img_conf_.is_autotext)
rotatetype = CImageApplyRotation::RotationType::AutoTextOrientation;
#ifdef WIN32
char szIniFile[MAX_PATH] = {0};
@ -684,8 +693,44 @@ namespace hg_imgproc
}
return HG_ERR_OK;
}
// final
//int ocr
int ocr_auto_txtdirect()
{
int pDirect = -1;
int ret = HG_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);
printf("ret = %d pDirect=%d\r\n",ret,pDirect);
if(ret != 0)
{
return HG_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;
}
// final
public:
int final(void)
{
@ -901,6 +946,10 @@ namespace hg_imgproc
{
return ((imgproc*)himg)->quality(dpi);
}
int ocr_auto_txtdirect(HIMGPRC himg)
{
return ((imgproc*)himg)->ocr_auto_txtdirect();
}
int final(HIMGPRC himg)
{
return ((imgproc*)himg)->final();

View File

@ -192,6 +192,8 @@ namespace hg_imgproc
int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata);
int fold(HIMGPRC himg);
int quality(HIMGPRC himg,int dpi);
int ocr_auto_txtdirect(HIMGPRC himg);
int final(HIMGPRC himg);
// pimh must not to be NULL, and pimh->total_bytes indicates the length of 'buf'

View File

@ -20,9 +20,9 @@ message(STATUS ${CMAKE_HOST_SYSTEM_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/../../../build/libgdev.a
${PROJECT_SOURCE_DIR}/../../../build/libgimgproc.a
${PROJECT_SOURCE_DIR}/../../../build/libgimgproc.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/libopencv_world.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/libIlmImf.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/libIlmImf.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/liblibjasper.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/liblibjpeg-turbo.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/liblibpng.a
@ -48,16 +48,18 @@ elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/libittnotify.a
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/libtegra_hal.a
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libexportfile.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libcnocr.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libconvert.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libdocseg.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libexportfile.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libhwocrdetect.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libhwocrjni.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libcrypto.so.1.0.0
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libdocseg.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libofd.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libpdfparse.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libtinyxml2.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libzip.so
${PROJECT_SOURCE_DIR}/../3rdparty/ocr/lib/uos/${CMAKE_SYSTEM_PROCESSOR}/lib/libhwocrdetect.so
#message("静态库预留03")
#message("静态库预留04")
)