这个目录下移除oce

This commit is contained in:
luoliangyi 2022-05-11 11:42:18 +08:00
parent 17f45de108
commit 861736c192
54 changed files with 0 additions and 1274 deletions

View File

@ -1,176 +0,0 @@
#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 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

@ -1,146 +0,0 @@
/*--------------------------------------------------------------------------
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

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="OcrSdkDemo/jni"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OcrSdkDemo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//src/com/hanvon/ocrsdk/SDKInterface.java=UTF-8
encoding//src/com/hanvon/ocrsdk/test.java=UTF-8

View File

@ -1,29 +0,0 @@
package com.hanvon.ocrsdk;
public class OCRLayoutBlockInfo {
OCRLayoutBlockInfo()
{
iRect = new TOCRRECT();
}
// LayoutType
public final static int ETypeHorizontal= 0; // TYPE_HORIZONTAL,
public final static int ETypeVertical = 1; // TYPE_VERTICAL
// TextType
public final static int ETextMultiLine = 0; //multi-text line
public final static int ETextSingleLine = 1;//sigle text line
// ImageBackground
public final static int EBackgroundLight = 0; // dark character with light background
public final static int EBackgroundDark = 1; //light character with dark background
public final static int EBackgroundUnknown= 2; // unknown
public TOCRRECT iRect; //block coordinates
public int nLayoutType; //vertical or horzontal text
public int nTextType; //mulitline or single line
public int nImageBackground;//brightness for text background
}

View File

@ -1,92 +0,0 @@
package com.hanvon.ocrsdk;
public class SDKInterface {
//文件类型
public final static int FILE_PDF = 0; //输出精确版面复原的简体PDF文件
public final static int FILE_RTF = 2;
public final static int FILE_XLS = 5;
public final static int FILE_PDF_TXT = 101; //输出文本加pdf
public final static int FILE_TXT = 100; //输出为文本格式
public final static int FILE_JSON = 200; //输出为json格式
public final static int FILE_OFD = 300;
// 返回结果
public final static int STATUS_OK = 0;
public final static int STATUS_NO_MEMORY = -1;
public final static int STATUS_INVALID_PARAMETER = -2;
public final static int STATUS_FAILED = -3;
public final static int EGray2 = 0; //black and white image, 1 bit per pixel
public final static int EGray256 = 1; // gray image, 8 bit per pixel
public final static int EColor16M = 2; // color image, 24 bit per pixel
/**
* 初始化sdk运行环境
* @return 返回状态值
*/
public static native long HWOCR_SDKInitialize();
/**
* 结束用完以后调用释放内存
*/
public static native void HWOCR_SDKExit(long hDll);
public static native void HWOCR_OCRExit(long ocrhandle,long hDll);
public static native long HWOCR_OCRInitialize(long hDll);
/**
* 从图像文件识别到指定文件
* @param imgFile 原始图像文件
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在位置
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeFile(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native int HWOCR_RecognizePDF(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native void HWOCR_InitPDF(long hDll);
public static native void HWOCR_ExitPDF(long hDll);
public static native int HWOCR_RecognizeOFD(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native String HWOCR_RecognizeFile2Str(String imgFile,long ocrhandle, long hDll);
/**
* 从PDF文件识别到指定文件
* @param pdfFile PDF文件
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在位置
* @param pTmpDir 临时文件路径
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeFileBatch(String[] inFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
/**
* 从图像块识别到文件
* @param pbImage 图像数据
* @param nWidth 图像宽度
* @param nHeight 图像高度
* @param aLayoutInfo 版面信息
* @param nColorType 颜色类型
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在文件夹位置
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeImgBlock(byte[] pbImage, int nWidth, int nHeight, OCRLayoutBlockInfo aLayoutInfo,
int nColorType, String OutFile, int nFileType, String pLibDir,long ocrhandle, long hDll);
static {
System.load("/home/user/workspace/2021/ocr-sdk-ofd/linux_mt20210608_x64/test.lock/libhwocrjni.so");
//System.load("E:\\2019-smallOCRSDK\\branch\\hwocr2019_mt\\release\\中英文sdk_Windows_设备绑定版本2.1.0.6\\bin\\x64\\HwOcrSdk.dll");
}
}

View File

@ -1,8 +0,0 @@
package com.hanvon.ocrsdk;
public class TOCRRECT {
public int left;
public int top;
public int right;
public int bottom;
}

View File

@ -1,279 +0,0 @@
package com.hanvon.ocrsdk;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.*;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import javax.imageio.ImageIO;
class RunnableDemo implements Runnable {
private Thread t;
private String threadName;
private long hdll11;
RunnableDemo( String name,long hDll) {
threadName = name;
hdll11 = hDll;
System.out.println("Creating " + threadName );
System.out.print(hdll11);
}
public void run() {
// while(true)
{
System.out.println("Running " + threadName );
System.out.print(hdll11);
//try {
/*for(int i = 4; i > 0; i--) {
System.out.println("Thread: " + threadName + ", " + i);
// 让线程睡眠一会
Thread.sleep(50);
}*/
// long hdll11 = SDKInterface.HWOCR_SDKInitialize();
// 先初始化
long handle = SDKInterface.HWOCR_OCRInitialize(hdll11);
System.out.println("HWOCR_SDKInitialize result:"+handle);
// 识别图像文件
int a = SDKInterface.HWOCR_RecognizeFile(threadName+"3.jpg",
threadName+"1工工.pdf", SDKInterface.FILE_PDF_TXT, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeFile result:" + a);
String files[] = new String[2];
files[0] = threadName+"1.bmp";
files[1] = threadName+"3.jpg";
//files[2] = threadName+"111.jpg";
//sdk.RecognizeImageToFile("D:\\OCRTest\\image\\A0002.tif", files);
a = SDKInterface.HWOCR_RecognizeFileBatch(files,
threadName+"asd.pdf", SDKInterface.FILE_PDF_TXT, threadName,
threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeFileBatch result:" + a);
String rst = SDKInterface.HWOCR_RecognizeFile2Str(threadName+"111.jpg",handle, hdll11);
System.out.println("HWOCR_RecognizeFile2Str result:"+rst);
// 识别图像块
String basepath = threadName+"2.jpg";
try {
basepath=URLDecoder.decode(basepath,"utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File file = new File(basepath);
BufferedImage image = null;
int colorType = SDKInterface.EColor16M;
byte[] pbImage = null;
try {
image = ImageIO.read(file);
Raster raster = image.getData( );
pbImage = new byte[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
int[] ptmp = new int[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
if (raster.getNumBands() == 1) {
colorType = SDKInterface.EGray256;
}else if (raster.getNumBands() == 3) {
colorType = SDKInterface.EColor16M;
}else {
// 需要转换才能使用建议直接使用24位真彩色图像或灰度图像
}
int [] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), ptmp);
for(int i = 0 ;i < pixels.length; i++)
{
pbImage[i]=(byte)pixels[i];
}
file = null;
raster=null;
pixels=null;
ptmp=null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OCRLayoutBlockInfo aLayoutInfo = new OCRLayoutBlockInfo();
aLayoutInfo.iRect.left = 0;
aLayoutInfo.iRect.top = 0;
aLayoutInfo.iRect.right = image.getWidth() - 1;
aLayoutInfo.iRect.bottom = image.getHeight() - 1;
aLayoutInfo.nTextType = OCRLayoutBlockInfo.ETextMultiLine;
aLayoutInfo.nImageBackground = OCRLayoutBlockInfo.EBackgroundUnknown;
aLayoutInfo.nLayoutType = OCRLayoutBlockInfo.ETypeHorizontal;
//a = SDKInterface.HWOCR_RecognizeImgBlock(pbImage, image.getWidth(), image.getHeight(), aLayoutInfo, colorType,
// threadName+"cc.txt", SDKInterface.FILE_TXT, threadName,
// handle, hdll11);
image = null;
pbImage=null;
System.out.println("HWOCR_RecognizeImgBlock:" + a);
a = SDKInterface.HWOCR_RecognizePDF(threadName+"prefix-0005.pdf",
threadName+"1.ofd", SDKInterface.FILE_OFD, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizePDF result:" + a);
a = SDKInterface.HWOCR_RecognizeOFD(threadName+"prefix-0005.pdf.ofd",
threadName+"ofd.pdf", SDKInterface.FILE_PDF_TXT, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeOFD result:" + a);
SDKInterface.HWOCR_OCRExit(handle,hdll11);
System.out.println("result:" + a);
//}
System.out.println("Thread " + threadName + " exiting.");
}
}
public void start () {
System.out.println("Starting " + threadName );
if (t == null) {
t = new Thread (this, threadName);
t.start ();
}
}
public void join () {
try {
t.join();//注意这里
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class test {
public static void main(String[] args){
System.out.println("test");
long hdll = SDKInterface.HWOCR_SDKInitialize();
SDKInterface.HWOCR_InitPDF(hdll);
//long hdll = 0;
RunnableDemo R1 = new RunnableDemo( "/home/user/workspace/2021/ocr-sdk-ofd/linux_mt20210608_x64/test.lock/",hdll);
R1.start();
// RunnableDemo R2 = new RunnableDemo( "G:\\workspace\\2021\\sdk\\test\\out2\\",hdll);
// R2.start();
R1.join();//注意这里
// R2.join();//注意这里
SDKInterface.HWOCR_ExitPDF(hdll);
SDKInterface.HWOCR_SDKExit(hdll);
System.out.println("over");
// 先初始化
/*long[] handle = SDKInterface.HWOCR_SDKInitialize();
System.out.println("HWOCR_SDKInitialize result:"+handle[0]);
// 识别图像文件
int a = SDKInterface.HWOCR_RecognizeFile("E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\61.bmp",
"E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\1工工.pdf", SDKInterface.FILE_PDF_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\","E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
handle[0], handle[1]);
System.out.println("HWOCR_RecognizeFile result:" + a);
String files[] = new String[3];
files[0] = "G:\\workspace\\2021\\sdk\\大商\\111.jpg";
files[1] = "G:\\workspace\\2021\\sdk\\大商\\222.jpg";
files[2] = "G:\\workspace\\2021\\sdk\\大商\\111.jpg";
//sdk.RecognizeImageToFile("D:\\OCRTest\\image\\A0002.tif", files);
// 识别PDF文件
//a = SDKInterface.HWOCR_RecognizeFileBatch(files,
// "G:\\workspace\\2020\\sdk\\1234567890123456789012345678901234567890\\asd.pdf", SDKInterface.FILE_PDF_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
// "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
// handle[0], handle[1]);
//System.out.println("HWOCR_RecognizeFileBatch result:" + a);
String rst = SDKInterface.HWOCR_RecognizeFile2Str("G:\\workspace\\2021\\sdk\\大商\\222.jpg",handle[0],handle[1]);
// rst = SDKInterface.HWOCR_RecognizeFile2Str("G:\\workspace\\2021\\sdk\\大商\\222.jpg",handle[0],handle[1]);
//}
//System.out.println("HWOCR_RecognizeFile2Str result:" + rst);
// 识别图像块
String basepath = "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\61.bmp";
try {
basepath=URLDecoder.decode(basepath,"utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File file = new File(basepath);
BufferedImage image = null;
int colorType = SDKInterface.EColor16M;
byte[] pbImage = null;
try {
image = ImageIO.read(file);
Raster raster = image.getData( );
pbImage = new byte[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
int[] ptmp = new int[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
if (raster.getNumBands() == 1) {
colorType = SDKInterface.EGray256;
}else if (raster.getNumBands() == 3) {
colorType = SDKInterface.EColor16M;
}else {
// 需要转换才能使用建议直接使用24位真彩色图像或灰度图像
}
int [] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), ptmp);
for(int i = 0 ;i < pixels.length; i++)
{
pbImage[i]=(byte)pixels[i];
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OCRLayoutBlockInfo aLayoutInfo = new OCRLayoutBlockInfo();
aLayoutInfo.iRect.left = 0;
aLayoutInfo.iRect.top = 0;
aLayoutInfo.iRect.right = image.getWidth() - 1;
aLayoutInfo.iRect.bottom = image.getHeight() - 1;
aLayoutInfo.nTextType = OCRLayoutBlockInfo.ETextMultiLine;
aLayoutInfo.nImageBackground = OCRLayoutBlockInfo.EBackgroundUnknown;
aLayoutInfo.nLayoutType = OCRLayoutBlockInfo.ETypeHorizontal;
a = SDKInterface.HWOCR_RecognizeImgBlock(pbImage, image.getWidth(), image.getHeight(), aLayoutInfo, colorType,
"E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\cc.txt", SDKInterface.FILE_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
handle[0], handle[1]);
System.out.println("HWOCR_RecognizeImgBlock:" + a);
SDKInterface.HWOCR_SDKExit(handle);
System.out.println("result:" + a);*/
}
}

View File

@ -1 +0,0 @@
2.1.0.20Linux_aarch64设备绑定版本

View File

@ -1,37 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include "hanwangOCRdetect.h"
int main()
{
unsigned char pbIn[] = ".\\1.bmp";
unsigned char pbOut[] = ".\\1.pdf";
char pbDir[] = ".\\";
void *pHandel = NULL;
TOCRLayoutBlockInfo aLayoutInfo;
TColorType nColorType;
HWOCR_SDKInitialize(&pHandel);
HWOCR_RecognizeFile((unsigned char*)pbIn, (unsigned char* )pbOut, 0, pHandel, NULL, pbDir);
char *pRst = NULL;
int nLen = 0;
HWOCR_RecognizeFile2Str((unsigned char*) pbIn, pHandel,&pRst, &nLen);
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);
fp = fopen("rst.txt", "wb");
fprintf(fp,"%d\r\n",nDirect);
fclose(fp);
HWOCR_SDKExit(pHandel);
return 0;
}

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="OcrSdkDemo/jni"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OcrSdkDemo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//src/com/hanvon/ocrsdk/SDKInterface.java=UTF-8
encoding//src/com/hanvon/ocrsdk/test.java=UTF-8

View File

@ -1,29 +0,0 @@
package com.hanvon.ocrsdk;
public class OCRLayoutBlockInfo {
OCRLayoutBlockInfo()
{
iRect = new TOCRRECT();
}
// LayoutType
public final static int ETypeHorizontal= 0; // TYPE_HORIZONTAL,
public final static int ETypeVertical = 1; // TYPE_VERTICAL
// TextType
public final static int ETextMultiLine = 0; //multi-text line
public final static int ETextSingleLine = 1;//sigle text line
// ImageBackground
public final static int EBackgroundLight = 0; // dark character with light background
public final static int EBackgroundDark = 1; //light character with dark background
public final static int EBackgroundUnknown= 2; // unknown
public TOCRRECT iRect; //block coordinates
public int nLayoutType; //vertical or horzontal text
public int nTextType; //mulitline or single line
public int nImageBackground;//brightness for text background
}

View File

@ -1,92 +0,0 @@
package com.hanvon.ocrsdk;
public class SDKInterface {
//文件类型
public final static int FILE_PDF = 0; //输出精确版面复原的简体PDF文件
public final static int FILE_RTF = 2;
public final static int FILE_XLS = 5;
public final static int FILE_PDF_TXT = 101; //输出文本加pdf
public final static int FILE_TXT = 100; //输出为文本格式
public final static int FILE_JSON = 200; //输出为json格式
public final static int FILE_OFD = 300;
// 返回结果
public final static int STATUS_OK = 0;
public final static int STATUS_NO_MEMORY = -1;
public final static int STATUS_INVALID_PARAMETER = -2;
public final static int STATUS_FAILED = -3;
public final static int EGray2 = 0; //black and white image, 1 bit per pixel
public final static int EGray256 = 1; // gray image, 8 bit per pixel
public final static int EColor16M = 2; // color image, 24 bit per pixel
/**
* 初始化sdk运行环境
* @return 返回状态值
*/
public static native long HWOCR_SDKInitialize();
/**
* 结束用完以后调用释放内存
*/
public static native void HWOCR_SDKExit(long hDll);
public static native void HWOCR_OCRExit(long ocrhandle,long hDll);
public static native long HWOCR_OCRInitialize(long hDll);
/**
* 从图像文件识别到指定文件
* @param imgFile 原始图像文件
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在位置
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeFile(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native int HWOCR_RecognizePDF(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native void HWOCR_InitPDF(long hDll);
public static native void HWOCR_ExitPDF(long hDll);
public static native int HWOCR_RecognizeOFD(String imgFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
public static native String HWOCR_RecognizeFile2Str(String imgFile,long ocrhandle, long hDll);
/**
* 从PDF文件识别到指定文件
* @param pdfFile PDF文件
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在位置
* @param pTmpDir 临时文件路径
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeFileBatch(String[] inFile, String OutFile,
int nFileType, String pLibDir, String pTmpDir,long ocrhandle, long hDll);
/**
* 从图像块识别到文件
* @param pbImage 图像数据
* @param nWidth 图像宽度
* @param nHeight 图像高度
* @param aLayoutInfo 版面信息
* @param nColorType 颜色类型
* @param OutFile 输出文件
* @param nFileType 输出文件类型
* @param pLibDir db文件所在文件夹位置
* @return 返回结果成功与否
*/
public static native int HWOCR_RecognizeImgBlock(byte[] pbImage, int nWidth, int nHeight, OCRLayoutBlockInfo aLayoutInfo,
int nColorType, String OutFile, int nFileType, String pLibDir,long ocrhandle, long hDll);
static {
System.load("/home/user/workspace/2021/ocr-sdk-ofd/linux_mt20210608_x64/test.lock/libhwocrjni.so");
//System.load("E:\\2019-smallOCRSDK\\branch\\hwocr2019_mt\\release\\中英文sdk_Windows_设备绑定版本2.1.0.6\\bin\\x64\\HwOcrSdk.dll");
}
}

View File

@ -1,8 +0,0 @@
package com.hanvon.ocrsdk;
public class TOCRRECT {
public int left;
public int top;
public int right;
public int bottom;
}

View File

@ -1,279 +0,0 @@
package com.hanvon.ocrsdk;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.*;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import javax.imageio.ImageIO;
class RunnableDemo implements Runnable {
private Thread t;
private String threadName;
private long hdll11;
RunnableDemo( String name,long hDll) {
threadName = name;
hdll11 = hDll;
System.out.println("Creating " + threadName );
System.out.print(hdll11);
}
public void run() {
// while(true)
{
System.out.println("Running " + threadName );
System.out.print(hdll11);
//try {
/*for(int i = 4; i > 0; i--) {
System.out.println("Thread: " + threadName + ", " + i);
// 让线程睡眠一会
Thread.sleep(50);
}*/
// long hdll11 = SDKInterface.HWOCR_SDKInitialize();
// 先初始化
long handle = SDKInterface.HWOCR_OCRInitialize(hdll11);
System.out.println("HWOCR_SDKInitialize result:"+handle);
// 识别图像文件
int a = SDKInterface.HWOCR_RecognizeFile(threadName+"3.jpg",
threadName+"1工工.pdf", SDKInterface.FILE_PDF_TXT, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeFile result:" + a);
String files[] = new String[2];
files[0] = threadName+"1.bmp";
files[1] = threadName+"3.jpg";
//files[2] = threadName+"111.jpg";
//sdk.RecognizeImageToFile("D:\\OCRTest\\image\\A0002.tif", files);
a = SDKInterface.HWOCR_RecognizeFileBatch(files,
threadName+"asd.pdf", SDKInterface.FILE_PDF_TXT, threadName,
threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeFileBatch result:" + a);
String rst = SDKInterface.HWOCR_RecognizeFile2Str(threadName+"111.jpg",handle, hdll11);
System.out.println("HWOCR_RecognizeFile2Str result:"+rst);
// 识别图像块
String basepath = threadName+"2.jpg";
try {
basepath=URLDecoder.decode(basepath,"utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File file = new File(basepath);
BufferedImage image = null;
int colorType = SDKInterface.EColor16M;
byte[] pbImage = null;
try {
image = ImageIO.read(file);
Raster raster = image.getData( );
pbImage = new byte[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
int[] ptmp = new int[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
if (raster.getNumBands() == 1) {
colorType = SDKInterface.EGray256;
}else if (raster.getNumBands() == 3) {
colorType = SDKInterface.EColor16M;
}else {
// 需要转换才能使用建议直接使用24位真彩色图像或灰度图像
}
int [] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), ptmp);
for(int i = 0 ;i < pixels.length; i++)
{
pbImage[i]=(byte)pixels[i];
}
file = null;
raster=null;
pixels=null;
ptmp=null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OCRLayoutBlockInfo aLayoutInfo = new OCRLayoutBlockInfo();
aLayoutInfo.iRect.left = 0;
aLayoutInfo.iRect.top = 0;
aLayoutInfo.iRect.right = image.getWidth() - 1;
aLayoutInfo.iRect.bottom = image.getHeight() - 1;
aLayoutInfo.nTextType = OCRLayoutBlockInfo.ETextMultiLine;
aLayoutInfo.nImageBackground = OCRLayoutBlockInfo.EBackgroundUnknown;
aLayoutInfo.nLayoutType = OCRLayoutBlockInfo.ETypeHorizontal;
//a = SDKInterface.HWOCR_RecognizeImgBlock(pbImage, image.getWidth(), image.getHeight(), aLayoutInfo, colorType,
// threadName+"cc.txt", SDKInterface.FILE_TXT, threadName,
// handle, hdll11);
image = null;
pbImage=null;
System.out.println("HWOCR_RecognizeImgBlock:" + a);
a = SDKInterface.HWOCR_RecognizePDF(threadName+"prefix-0005.pdf",
threadName+"1.ofd", SDKInterface.FILE_OFD, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizePDF result:" + a);
a = SDKInterface.HWOCR_RecognizeOFD(threadName+"prefix-0005.pdf.ofd",
threadName+"ofd.pdf", SDKInterface.FILE_PDF_TXT, threadName,threadName,
handle, hdll11);
System.out.println("HWOCR_RecognizeOFD result:" + a);
SDKInterface.HWOCR_OCRExit(handle,hdll11);
System.out.println("result:" + a);
//}
System.out.println("Thread " + threadName + " exiting.");
}
}
public void start () {
System.out.println("Starting " + threadName );
if (t == null) {
t = new Thread (this, threadName);
t.start ();
}
}
public void join () {
try {
t.join();//注意这里
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class test {
public static void main(String[] args){
System.out.println("test");
long hdll = SDKInterface.HWOCR_SDKInitialize();
SDKInterface.HWOCR_InitPDF(hdll);
//long hdll = 0;
RunnableDemo R1 = new RunnableDemo( "/home/user/workspace/2021/ocr-sdk-ofd/linux_mt20210608_x64/test.lock/",hdll);
R1.start();
// RunnableDemo R2 = new RunnableDemo( "G:\\workspace\\2021\\sdk\\test\\out2\\",hdll);
// R2.start();
R1.join();//注意这里
// R2.join();//注意这里
SDKInterface.HWOCR_ExitPDF(hdll);
SDKInterface.HWOCR_SDKExit(hdll);
System.out.println("over");
// 先初始化
/*long[] handle = SDKInterface.HWOCR_SDKInitialize();
System.out.println("HWOCR_SDKInitialize result:"+handle[0]);
// 识别图像文件
int a = SDKInterface.HWOCR_RecognizeFile("E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\61.bmp",
"E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\1工工.pdf", SDKInterface.FILE_PDF_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\","E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
handle[0], handle[1]);
System.out.println("HWOCR_RecognizeFile result:" + a);
String files[] = new String[3];
files[0] = "G:\\workspace\\2021\\sdk\\大商\\111.jpg";
files[1] = "G:\\workspace\\2021\\sdk\\大商\\222.jpg";
files[2] = "G:\\workspace\\2021\\sdk\\大商\\111.jpg";
//sdk.RecognizeImageToFile("D:\\OCRTest\\image\\A0002.tif", files);
// 识别PDF文件
//a = SDKInterface.HWOCR_RecognizeFileBatch(files,
// "G:\\workspace\\2020\\sdk\\1234567890123456789012345678901234567890\\asd.pdf", SDKInterface.FILE_PDF_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
// "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
// handle[0], handle[1]);
//System.out.println("HWOCR_RecognizeFileBatch result:" + a);
String rst = SDKInterface.HWOCR_RecognizeFile2Str("G:\\workspace\\2021\\sdk\\大商\\222.jpg",handle[0],handle[1]);
// rst = SDKInterface.HWOCR_RecognizeFile2Str("G:\\workspace\\2021\\sdk\\大商\\222.jpg",handle[0],handle[1]);
//}
//System.out.println("HWOCR_RecognizeFile2Str result:" + rst);
// 识别图像块
String basepath = "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\61.bmp";
try {
basepath=URLDecoder.decode(basepath,"utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File file = new File(basepath);
BufferedImage image = null;
int colorType = SDKInterface.EColor16M;
byte[] pbImage = null;
try {
image = ImageIO.read(file);
Raster raster = image.getData( );
pbImage = new byte[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
int[] ptmp = new int[raster.getWidth()*raster.getHeight()*raster.getNumBands()];
if (raster.getNumBands() == 1) {
colorType = SDKInterface.EGray256;
}else if (raster.getNumBands() == 3) {
colorType = SDKInterface.EColor16M;
}else {
// 需要转换才能使用建议直接使用24位真彩色图像或灰度图像
}
int [] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), ptmp);
for(int i = 0 ;i < pixels.length; i++)
{
pbImage[i]=(byte)pixels[i];
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OCRLayoutBlockInfo aLayoutInfo = new OCRLayoutBlockInfo();
aLayoutInfo.iRect.left = 0;
aLayoutInfo.iRect.top = 0;
aLayoutInfo.iRect.right = image.getWidth() - 1;
aLayoutInfo.iRect.bottom = image.getHeight() - 1;
aLayoutInfo.nTextType = OCRLayoutBlockInfo.ETextMultiLine;
aLayoutInfo.nImageBackground = OCRLayoutBlockInfo.EBackgroundUnknown;
aLayoutInfo.nLayoutType = OCRLayoutBlockInfo.ETypeHorizontal;
a = SDKInterface.HWOCR_RecognizeImgBlock(pbImage, image.getWidth(), image.getHeight(), aLayoutInfo, colorType,
"E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\cc.txt", SDKInterface.FILE_TXT, "E:\\2019-smallOCRSDK\\branch\\18030code_version\\code\\Release\\",
handle[0], handle[1]);
System.out.println("HWOCR_RecognizeImgBlock:" + a);
SDKInterface.HWOCR_SDKExit(handle);
System.out.println("result:" + a);*/
}
}

View File

@ -1 +0,0 @@
2.1.0.20Linux_aarch64设备绑定版本

View File

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