解决websocket增加上传功能后在linux上编译不过的问题

This commit is contained in:
luoliangyi 2022-05-11 18:30:33 +08:00
parent 3dba99c968
commit 62146c7dbe
39 changed files with 1033 additions and 44 deletions

View File

@ -29,6 +29,7 @@
#include <arpa/inet.h>
#include <dlfcn.h>
#include <iconv.h>
#include <sys/ioctl.h>
#endif
#endif /* __HGINC_H__ */

View File

@ -16,6 +16,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/opencv/uos/amd64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/amd64/include" />
</Compiler>
<Linker>
<Add option="-L../../../third_party/opencv/uos/amd64/lib" />
@ -26,6 +27,7 @@
<Add option="-littnotify" />
<Add option="-lzlib" />
<Add option="-L../HGBase/bin/uos_x86_64_Debug -lHGBase" />
<Add option="-L../HGImgFmt/bin/uos_x86_64_Debug -lHGImgFmt" />
</Linker>
</Target>
<Target title="uos_x86_64_Release">
@ -38,6 +40,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/opencv/uos/amd64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/amd64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -48,7 +51,7 @@
<Add option="-lopencv_core" />
<Add option="-littnotify" />
<Add option="-lzlib" />
<Add option="-L../../../../release/uos/x86_64 -lHGBase" />
<Add option="-L../../../../release/uos/x86_64 -lHGBase -lHGImgFmt" />
</Linker>
</Target>
<Target title="uos_aarch64_Debug">
@ -61,6 +64,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/opencv/uos/aarch64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/aarch64/include" />
</Compiler>
<Linker>
<Add option="-L../../../third_party/opencv/uos/aarch64/lib" />
@ -71,6 +75,7 @@
<Add option="-littnotify" />
<Add option="-lzlib" />
<Add option="-L../HGBase/bin/uos_aarch64_Debug -lHGBase" />
<Add option="-L../HGImgFmt/bin/uos_aarch64_Debug -lHGImgFmt" />
</Linker>
</Target>
<Target title="uos_aarch64_Release">
@ -83,6 +88,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/opencv/uos/aarch64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/aarch64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -93,7 +99,7 @@
<Add option="-lopencv_core" />
<Add option="-littnotify" />
<Add option="-lzlib" />
<Add option="-L../../../../release/uos/aarch64 -lHGBase" />
<Add option="-L../../../../release/uos/aarch64 -lHGBase -lHGImgFmt" />
</Linker>
</Target>
<Target title="uos_mips64_Debug">
@ -106,6 +112,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/opencv/uos/mips64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/mips64/include" />
</Compiler>
<Linker>
<Add option="-L../../../third_party/opencv/uos/mips64/lib" />
@ -115,6 +122,7 @@
<Add option="-lopencv_core" />
<Add option="-lzlib" />
<Add option="-L../HGBase/bin/uos_mips64_Debug -lHGBase" />
<Add option="-L../HGImgFmt/bin/uos_mips64_Debug -lHGImgFmt" />
</Linker>
</Target>
<Target title="uos_mips64_Release">
@ -127,6 +135,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/opencv/uos/mips64/include" />
<Add directory="../../../third_party/ocr/hanvon/uos/mips64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -136,7 +145,7 @@
<Add option="-lopencv_imgproc" />
<Add option="-lopencv_core" />
<Add option="-lzlib" />
<Add option="-L../../../../release/uos/mips64 -lHGBase" />
<Add option="-L../../../../release/uos/mips64 -lHGBase -lHGImgGmt" />
</Linker>
</Target>
</Build>
@ -155,6 +164,14 @@
<Unit filename="../../../imgproc/HGImgProc.cpp" />
<Unit filename="../../../imgproc/HGImgProc.h" />
<Unit filename="../../../imgproc/HGImgProcErr.h" />
<Unit filename="../../../imgproc/HGOCR.cpp" />
<Unit filename="../../../imgproc/HGOCR.h" />
<Unit filename="../../../imgproc/HGOCRBase.cpp" />
<Unit filename="../../../imgproc/HGOCRBase.hpp" />
<Unit filename="../../../imgproc/HGOCRHanvon.cpp" />
<Unit filename="../../../imgproc/HGOCRHanvon.hpp" />
<Unit filename="../../../imgproc/HGOCRRetImpl.cpp" />
<Unit filename="../../../imgproc/HGOCRRetImpl.hpp" />
<Unit filename="../../../imgproc/hg_imageprocess.cpp" />
<Unit filename="../../../imgproc/hg_imageprocess.hpp" />
<Extensions>

View File

@ -2,31 +2,9 @@
#include "../../../base/HGBase.h"
#include "../../../imgfmt/HGImgFmt.h"
#include "../../../imgproc/HGImgProc.h"
#include "../../../imgproc/HGOCR.h"
int main()
{
HGImage img = NULL;
HGImgFmt_LoadImage("1.pdf", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
HGImgFmt_SaveImage(img, 0, NULL, 0, "pdf2pdf.pdf");
HGBase_DestroyImage(img);
HGImgFmt_LoadImage("1.jpg", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
HGImgFmt_SaveImage(img, 0, NULL, 0, "jpg2pdf.pdf");
HGBase_DestroyImage(img);
HGImgFmt_LoadImage("1.pdf", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
HGImgFmt_SaveImage(img, 0, NULL, 0, "pdf2jpg.jpg");
HGBase_DestroyImage(img);
HGImgFmt_LoadImage("1.bmp", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_BOTTOM, &img);
HGImage imgCrop = NULL;
HGImgProc_ImageDeskew(img, HGFALSE, HGFALSE, NULL, 800, 1200, HGBASE_IMGTYPE_BGRA, HGBASE_IMGORIGIN_TOP, &imgCrop);
HGImgFmt_SaveImage(imgCrop, 0, NULL, 0, "deskew.bmp");
HGBase_DestroyImage(imgCrop);
HGBase_DestroyImage(img);
HGBase_WriteInfo(HGBASE_INFOTYPE_DEBUG, "%d", 123456);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%d", 12345);
return 0;
}

View File

@ -14,6 +14,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/libzip/uos/amd64/include" />
<Add directory="../../../third_party/libcurl/uos/amd64/include" />
</Compiler>
<Linker>
<Add option="-L../HGBase/bin/uos_x86_64_Debug -lHGBase" />
@ -25,6 +26,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/amd64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/amd64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/amd64/lib -lcurl" />
</Linker>
</Target>
<Target title="uos_x86_64_Release">
@ -35,6 +37,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/libzip/uos/amd64/include" />
<Add directory="../../../third_party/libcurl/uos/amd64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -47,6 +50,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/amd64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/amd64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/amd64/lib -lcurl" />
</Linker>
</Target>
<Target title="uos_aarch64_Debug">
@ -57,6 +61,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/libzip/uos/aarch64/include" />
<Add directory="../../../third_party/libcurl/uos/aarch64/include" />
</Compiler>
<Linker>
<Add option="-L../HGBase/bin/uos_aarch64_Debug -lHGBase" />
@ -68,6 +73,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/aarch64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/aarch64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/aarch64/lib -lcurl" />
</Linker>
</Target>
<Target title="uos_aarch64_Release">
@ -78,6 +84,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/libzip/uos/aarch64/include" />
<Add directory="../../../third_party/libcurl/uos/aarch64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -90,6 +97,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/aarch64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/aarch64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/aarch64/lib -lcurl" />
</Linker>
</Target>
<Target title="uos_mips64_Debug">
@ -100,6 +108,7 @@
<Compiler>
<Add option="-g" />
<Add directory="../../../third_party/libzip/uos/mips64/include" />
<Add directory="../../../third_party/libcurl/uos/mips64/include" />
</Compiler>
<Linker>
<Add option="-L../HGBase/bin/uos_mips64_Debug -lHGBase" />
@ -111,6 +120,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/mips64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/mips64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/mips64/lib -lcurl" />
</Linker>
</Target>
<Target title="uos_mips64_Release">
@ -121,6 +131,7 @@
<Compiler>
<Add option="-O2" />
<Add directory="../../../third_party/libzip/uos/mips64/include" />
<Add directory="../../../third_party/libcurl/uos/mips64/include" />
</Compiler>
<Linker>
<Add option="-s" />
@ -133,6 +144,7 @@
<Add option="-lhgdriver" />
<Add option="-L../../../third_party/libzip/uos/mips64/lib -lzip" />
<Add option="-L../../../third_party/zlib/uos/mips64/lib -lz" />
<Add option="-L../../../third_party/libcurl/uos/mips64/lib -lcurl" />
</Linker>
</Target>
</Build>
@ -144,6 +156,9 @@
<Add directory="../../../third_party/json" />
<Add directory="../../../../sdk/include" />
</Compiler>
<Linker>
<Add option="-lpthread" />
</Linker>
<Unit filename="../../../sdk/webservice/HttpHead.cpp" />
<Unit filename="../../../sdk/webservice/HttpHead.h" />
<Unit filename="../../../sdk/webservice/HttpUser.cpp" />

View File

@ -7,6 +7,7 @@
</Project>
<Project filename="HGImgProc/HGImgProc.cbp">
<Depends filename="HGBase/HGBase.cbp" />
<Depends filename="HGImgFmt/HGImgFmt.cbp" />
</Project>
<Project filename="HGSaneUser/HGSaneUser.cbp">
<Depends filename="HGBase/HGBase.cbp" />

View File

@ -752,7 +752,7 @@ bool HGOfdImageWriterImpl::AddContentXmlFile(HGUInt index, HGFloat physicalWidth
imgObject->SetAttribute("CTM", ctmText);
layer->InsertEndChild(imgObject);
HGChar name[128];
HGChar name[256];
sprintf(name, "%s/Content.xml", dir);
return AddXmlFile(xmlDoc, name);
}

View File

@ -38,7 +38,7 @@ HGResult HGOCRHanvon::Init()
#if defined(HG_CMP_MSC)
HGResult ret = HGBase_CreateDll("hanwangOCRdetect.dll", &m_dll);
#else
HGResult ret = HGBase_CreateDll("hanwangOCRdetect.so", &m_dll);
HGResult ret = HGBase_CreateDll("libhwocrdetect.so", &m_dll);
#endif
HGBase_SetCurrentDir(oldDir);
if (HGBASE_ERR_OK != ret)

View File

@ -1355,8 +1355,8 @@ bool Manager::GetImageBase64(const std::string& devId, const std::string& imgNam
std::string Manager::GetFilePath(const std::string& devId)
{
HGChar docsPath[512];
HGBase_GetDocumentsPath(docsPath, 512);
HGChar docsPath[256];
HGBase_GetDocumentsPath(docsPath, 256);
HGChar imgPath[512];
sprintf(imgPath, "%sHuago/WebService/%s/", docsPath, Utf8ToStdString(devId.c_str()).c_str());
HGChar stdImgPath[512];
@ -1547,7 +1547,7 @@ bool Manager::SaveBase64(const std::string& fileName, const char* base64)
HGBase_Base64Decode((const HGByte*)base64, (HGSize)base64Size, data, &size);
size_t writeLen = fwrite(data, 1, size, file);
if (writeLen == size)
if (writeLen == (size_t)size)
ret = true;
delete[] data;
@ -1663,8 +1663,12 @@ bool Manager::HTTPUpload(const std::string& localFileName, const std::string& ht
assert(-1 != sockClient);
#endif
#if defined(HG_CMP_MSC)
u_long ul = 1; // 设为非阻塞
ioctlsocket(sockClient, FIONBIO, &ul);
#else
ioctl(sockClient, FIONBIO, 1);
#endif
#if defined(HG_CMP_MSC)
SOCKADDR_IN addrServer = { 0 };
@ -1674,7 +1678,7 @@ bool Manager::HTTPUpload(const std::string& localFileName, const std::string& ht
if (0 != connect(sockClient, (SOCKADDR*)&addrServer, sizeof(SOCKADDR_IN)))
#else
struct sockaddr_in addrServer = { 0 };
addrServer.sin_addr.S_un.S_addr = inet_addr(addr.c_str());
addrServer.sin_addr.s_addr = inet_addr(addr.c_str());
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(port);
if (0 != connect(sockClient, (struct sockaddr*)&addrServer, sizeof(addrServer)))
@ -1710,8 +1714,12 @@ bool Manager::HTTPUpload(const std::string& localFileName, const std::string& ht
}
}
#if defined(HG_CMP_MSC)
ul = 0; // 设为阻塞
ioctlsocket(sockClient, FIONBIO, &ul);
#else
ioctl(sockClient, FIONBIO, 0);
#endif
char remoteName[256];
HGBase_GetFileName(localFileName.c_str(), remoteName, 256);
@ -1805,9 +1813,9 @@ bool Manager::FTPUpload(const std::string& localFileName, const std::string& ftp
char remoteName[256];
HGBase_GetFileName(localFileName.c_str(), remoteName, 256);
char ftp_rnfr[256];
char ftp_rnfr[512];
sprintf(ftp_rnfr, "RNFR %s", tmpName);
char ftp_rnto[256];
char ftp_rnto[512];
sprintf(ftp_rnto, "RNTO %s", remoteName);
struct curl_slist* headerlist = NULL;

Binary file not shown.

4
third_party/libcurl/uos/amd64/lib/libcurl.la vendored Normal file → Executable file
View File

@ -17,7 +17,7 @@ old_library='libcurl.a'
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' -lidn2 -lzstd -lz'
dependency_libs=' -lz'
# Names of additional weak libraries provided by this library
weak_library_names=''
@ -38,4 +38,4 @@ dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/data/home/luoliangyi/hgproject/third_party/libcurl/uos/amd64/curl-7.82.0/release/lib'
libdir='/data/home/luoliangyi/code_app/third_party/libcurl/uos/amd64/curl-7.82.0/release/lib'

View File

@ -23,17 +23,17 @@
# This should most probably benefit from getting a "Requires:" field added
# dynamically by configure.
#
prefix=/data/home/luoliangyi/hgproject/third_party/libcurl/uos/amd64/curl-7.82.0/release
prefix=/data/home/luoliangyi/code_app/third_party/libcurl/uos/amd64/curl-7.82.0/release
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
supported_protocols="DICT FILE FTP GOPHER HTTP IMAP MQTT POP3 RTSP SMTP TELNET TFTP"
supported_features="AsynchDNS IDN IPv6 Largefile UnixSockets alt-svc libz zstd"
supported_features="AsynchDNS IPv6 Largefile UnixSockets alt-svc libz"
Name: libcurl
URL: https://curl.se/
Description: Library to transfer files with ftp, http, etc.
Version: 7.82.0
Libs: -L${libdir} -lcurl -lidn2 -lzstd -lz -pthread
Libs.private: -lidn2 -lzstd -lz -pthread
Libs: -L${libdir} -lcurl -lz -pthread
Libs.private: -lz -pthread
Cflags: -I${includedir} -DCURL_STATICLIB

View File

@ -0,0 +1,177 @@
#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);

View File

@ -0,0 +1,146 @@
/*--------------------------------------------------------------------------
Embedded OCR Engine for embedded platform v1.0
Copyright (c) 2006£¬HanWang Technology Co., Ltd. All Rights Reserved.
File: ocrcommon.h
Description:
common file for embedded OCR module.
Author: Hanwang Embedded OCR Group
History:
Nov.7, 2006 Created
---------------------------------------------------------------------------*/
#ifndef OCRCOMMON_H
#define OCRCOMMON_H
/*--------------------------------------------------------------------------*/
/* Typedef's */
/*--------------------------------------------------------------------------*/
typedef unsigned char BYTE;
typedef int BOOL;
typedef unsigned short WORD;
//Data type define
///////////////////////////////////////////////////////////////////////////////
typedef void (*RecogProgress)( int nPercent);
typedef int (*IsCanceled)();
typedef void* (*BCRHeapAlloc)( unsigned int lSize );
typedef void (*BCRHeapFree)( void *memblock );
#define MAX_PATH 260
typedef struct _OCRRect //rectangle
{
int left;
int top;
int right;
int bottom;
} TOCRRECT;
enum TLayoutType //layout text type
{
ETypeHorizontal, // TYPE_HORIZONTAL,
ETypeVertical // TYPE_VERTICAL
};
enum TTextType
{
ETextMultiLine, //multi-text line
ETextSingleLine //sigle text line
};
enum TImageBackground //brightness for text background
{
EBackgroundLight, // dark character with light background
EBackgroundDark, //light character with dark background
EBackgroundUnknown // unknown
};
enum TColorType //color type
{
EGray2 = 0, //black and white image, 1 bit per pixel
EGray256, // gray image, 8 bit per pixel
EColor16M, // color image, 24 bit per pixel
};
struct TOCRTextLineInfo // data structure of text line
{
char *iText; // during layout analyze, this is null
short *psDistance;
TOCRRECT iRect; //
TOCRRECT *iCharRect; // This is an array which returns the regions of every single character in this line
int iCharCount; // How many characters in this line
};
struct TOCRBlockInfo // data structure of layout infomation
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
};
struct TOCRTextRgnInfo // data structure of recognition result
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
TOCRTextLineInfo *iLines;
int iLineCount; // Lines' count in each block
};
struct TOCRLayoutSetting // data structure of layout settings
{
enum TBrightness // brightness
{
ENormal, // Normal
ELight, // Light
EDark // Dark
};
int iSkew; // switch of skew adjustment 1: do skew adjustment; 0: dont do it
TBrightness iBrightness; // switch of brightness adjustment
};
struct TOCRRecognizeSetting // data structure of Recognition settings
{
int iRotate;
void* iCandidate; // for later usage
};
struct TOCRLayoutBlockInfo // COCRLayoutBlockInfo
{
TOCRRECT iRect; //block coordinates
TLayoutType iLayout; //vertical or horzontal text
TTextType iText; //mulitline or single line
TImageBackground iBackgroundColor;//brightness for text background
};
struct TRegionInfo
{
TOCRRECT iRect;
TImageBackground iBackgroundColor;
enum TRegionType
{
EEmailAddress,
ETelephoneNumber,
EWWWAddress
};
TRegionType iType;
};
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,177 @@
#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);

View File

@ -0,0 +1,146 @@
/*--------------------------------------------------------------------------
Embedded OCR Engine for embedded platform v1.0
Copyright (c) 2006£¬HanWang Technology Co., Ltd. All Rights Reserved.
File: ocrcommon.h
Description:
common file for embedded OCR module.
Author: Hanwang Embedded OCR Group
History:
Nov.7, 2006 Created
---------------------------------------------------------------------------*/
#ifndef OCRCOMMON_H
#define OCRCOMMON_H
/*--------------------------------------------------------------------------*/
/* Typedef's */
/*--------------------------------------------------------------------------*/
typedef unsigned char BYTE;
typedef int BOOL;
typedef unsigned short WORD;
//Data type define
///////////////////////////////////////////////////////////////////////////////
typedef void (*RecogProgress)( int nPercent);
typedef int (*IsCanceled)();
typedef void* (*BCRHeapAlloc)( unsigned int lSize );
typedef void (*BCRHeapFree)( void *memblock );
#define MAX_PATH 260
typedef struct _OCRRect //rectangle
{
int left;
int top;
int right;
int bottom;
} TOCRRECT;
enum TLayoutType //layout text type
{
ETypeHorizontal, // TYPE_HORIZONTAL,
ETypeVertical // TYPE_VERTICAL
};
enum TTextType
{
ETextMultiLine, //multi-text line
ETextSingleLine //sigle text line
};
enum TImageBackground //brightness for text background
{
EBackgroundLight, // dark character with light background
EBackgroundDark, //light character with dark background
EBackgroundUnknown // unknown
};
enum TColorType //color type
{
EGray2 = 0, //black and white image, 1 bit per pixel
EGray256, // gray image, 8 bit per pixel
EColor16M, // color image, 24 bit per pixel
};
struct TOCRTextLineInfo // data structure of text line
{
char *iText; // during layout analyze, this is null
short *psDistance;
TOCRRECT iRect; //
TOCRRECT *iCharRect; // This is an array which returns the regions of every single character in this line
int iCharCount; // How many characters in this line
};
struct TOCRBlockInfo // data structure of layout infomation
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
};
struct TOCRTextRgnInfo // data structure of recognition result
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
TOCRTextLineInfo *iLines;
int iLineCount; // Lines' count in each block
};
struct TOCRLayoutSetting // data structure of layout settings
{
enum TBrightness // brightness
{
ENormal, // Normal
ELight, // Light
EDark // Dark
};
int iSkew; // switch of skew adjustment 1: do skew adjustment; 0: dont do it
TBrightness iBrightness; // switch of brightness adjustment
};
struct TOCRRecognizeSetting // data structure of Recognition settings
{
int iRotate;
void* iCandidate; // for later usage
};
struct TOCRLayoutBlockInfo // COCRLayoutBlockInfo
{
TOCRRECT iRect; //block coordinates
TLayoutType iLayout; //vertical or horzontal text
TTextType iText; //mulitline or single line
TImageBackground iBackgroundColor;//brightness for text background
};
struct TRegionInfo
{
TOCRRECT iRect;
TImageBackground iBackgroundColor;
enum TRegionType
{
EEmailAddress,
ETelephoneNumber,
EWWWAddress
};
TRegionType iType;
};
#endif

View File

@ -0,0 +1,177 @@
#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);

View File

@ -0,0 +1,146 @@
/*--------------------------------------------------------------------------
Embedded OCR Engine for embedded platform v1.0
Copyright (c) 2006£¬HanWang Technology Co., Ltd. All Rights Reserved.
File: ocrcommon.h
Description:
common file for embedded OCR module.
Author: Hanwang Embedded OCR Group
History:
Nov.7, 2006 Created
---------------------------------------------------------------------------*/
#ifndef OCRCOMMON_H
#define OCRCOMMON_H
/*--------------------------------------------------------------------------*/
/* Typedef's */
/*--------------------------------------------------------------------------*/
typedef unsigned char BYTE;
typedef int BOOL;
typedef unsigned short WORD;
//Data type define
///////////////////////////////////////////////////////////////////////////////
typedef void (*RecogProgress)( int nPercent);
typedef int (*IsCanceled)();
typedef void* (*BCRHeapAlloc)( unsigned int lSize );
typedef void (*BCRHeapFree)( void *memblock );
#define MAX_PATH 260
typedef struct _OCRRect //rectangle
{
int left;
int top;
int right;
int bottom;
} TOCRRECT;
enum TLayoutType //layout text type
{
ETypeHorizontal, // TYPE_HORIZONTAL,
ETypeVertical // TYPE_VERTICAL
};
enum TTextType
{
ETextMultiLine, //multi-text line
ETextSingleLine //sigle text line
};
enum TImageBackground //brightness for text background
{
EBackgroundLight, // dark character with light background
EBackgroundDark, //light character with dark background
EBackgroundUnknown // unknown
};
enum TColorType //color type
{
EGray2 = 0, //black and white image, 1 bit per pixel
EGray256, // gray image, 8 bit per pixel
EColor16M, // color image, 24 bit per pixel
};
struct TOCRTextLineInfo // data structure of text line
{
char *iText; // during layout analyze, this is null
short *psDistance;
TOCRRECT iRect; //
TOCRRECT *iCharRect; // This is an array which returns the regions of every single character in this line
int iCharCount; // How many characters in this line
};
struct TOCRBlockInfo // data structure of layout infomation
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
};
struct TOCRTextRgnInfo // data structure of recognition result
{
TOCRRECT iRect; // block coordinates
TLayoutType iType; //vertical or horizontal
int iBlockId; // block's ID
TOCRTextLineInfo *iLines;
int iLineCount; // Lines' count in each block
};
struct TOCRLayoutSetting // data structure of layout settings
{
enum TBrightness // brightness
{
ENormal, // Normal
ELight, // Light
EDark // Dark
};
int iSkew; // switch of skew adjustment 1: do skew adjustment; 0: dont do it
TBrightness iBrightness; // switch of brightness adjustment
};
struct TOCRRecognizeSetting // data structure of Recognition settings
{
int iRotate;
void* iCandidate; // for later usage
};
struct TOCRLayoutBlockInfo // COCRLayoutBlockInfo
{
TOCRRECT iRect; //block coordinates
TLayoutType iLayout; //vertical or horzontal text
TTextType iText; //mulitline or single line
TImageBackground iBackgroundColor;//brightness for text background
};
struct TRegionInfo
{
TOCRRECT iRect;
TImageBackground iBackgroundColor;
enum TRegionType
{
EEmailAddress,
ETelephoneNumber,
EWWWAddress
};
TRegionType iType;
};
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.