Skip to content

指定bmp图片识字 - OcrFromBmpData

函数简介

对指定bmp格式图片进行文字识别。

接口名称

OcrFromBmpData

DLL调用

long OcrFromBmpData(long ola, long imgPtr, int size);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
imgPtr长整数型bmp图片数据流地址。
size整数型图片大小。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpData(bmpPtr, bmpSize);
// text 为识别到的文字
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpData(bmpPtr, bmpSize);
// text 为识别到的文字
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpData(bmpPtr, bmpSize)
# text 为识别到的文字
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
String text = ola.OcrFromBmpData(bmpPtr, bmpSize);
// text 为识别到的文字
cpp
var ola = com("OlaPlug.OlaSoft")
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
var bmpPtr = bmpData
var bmpSize = 102400
var text = ola.OcrFromBmpData(bmpPtr, bmpSize)
// text 为识别到的文字
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpData(bmpPtr, bmpSize)
' text 为识别到的文字
text
.局部变量 ola, OLAPlug
ola.创建 ()
' bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
text = ola.OcrFromBmpData(bmpPtr, bmpSize)
' text 为识别到的文字
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
var bmpPtr = bmpData;
var bmpSize = 102400;
var text = ola.OcrFromBmpData(bmpPtr, bmpSize);
// text 为识别到的文字
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
长整数 bmpPtr = bmpData
整数 bmpSize = 102400
文本型 text = ola.OcrFromBmpData(bmpPtr, bmpSize)
// text 为识别到的文字
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
string text = ola.OcrFromBmpData(bmpPtr, bmpSize);
// text 为识别到的文字

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
long textPtr = OcrFromBmpData(instance, bmpPtr, bmpSize);
if (textPtr != 0) {
    char text[512] = {0};
    GetStringFromPtr(textPtr, text, sizeof(text));
    FreeStringPtr(textPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
// bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
long bmpPtr = bmpData;
int bmpSize = 102400;
long textPtr = OcrFromBmpData(instance, bmpPtr, bmpSize);
if (textPtr != 0) {
    StringBuilder text = new StringBuilder(GetStringSize(textPtr) + 1);
    GetStringFromPtr(textPtr, text, text.Capacity);
    FreeStringPtr(textPtr);
    string textStr = text.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
# bmpPtr/bmpSize 为 BMP 字节流地址与长度(可由文件读入内存获得)
bmpPtr = bmpData
bmpSize = 102400
textPtr = OcrFromBmpData(instance, bmpPtr, bmpSize)
if textPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(textPtr, buf, 512)
    ola.FreeStringPtr(textPtr)
    text = buf.value.decode("utf-8")

返回值

返回值说明
(返回值)字符串指针地址,返回识别到的字符串。返回的字符串指针需调用 FreeStringPtr 释放内存。

注意事项

项目说明
字体比较特殊或者背景复杂识别不准确的字体比较特殊或者背景复杂识别不准确的,建议用图像识别来处理。