# string.ocrLite 库模块帮助文档

## string 成员列表 <a id="string" href="#string">&#x23;</a>

### string.ocrLite <a id="string.ocrLite" href="#string.ocrLite">&#x23;</a>
识别屏幕或图像上文字的本地组件,开源免费。  
使用此组件时 **必须首先在主线程中导入此扩展库** 以避免 DLL 提前卸载。  
[此扩展库开源许可证（ GPL ）](https://github.com/aardio/chineseocr_lite_dll/blob/main/LICENSE)

创建OCR对象,所有参数可选,  
在屏幕上找到文字以后可使用 winex.mouse, mouse 等库函数自动点击,  
使用 aardio 工具里的「探测器->窗口探测器」可生成窗口检测或点击的示例代码

### string.ocrLite() <a id="string.ocrLite" href="#string.ocrLite">&#x23;</a>
[返回对象:stringOcrLiteObject](#stringOcrLiteObject)

### string.ocrLite(models,outputBitmap,outputConsole,numThreads) <a id="string.ocrLite" href="#string.ocrLite">&#x23;</a>
创建OCR对象,所有参数可选,注意截图范围越小结果越准确,  
@models 参数指定模型目录,或包含模型路径配置的参数表,  
导入 string.ocrLite.defaultModels 可嵌入默认模型,  
指定@outputBitmap为true时OCR结果对象会包含resultBitmap字段,  
@outputConsole 为true会向控制台输出调试信息,  
@outputConsole设为true时会自动以UTF8编码打开控制台,  
@numThreads指定线程数,一般不需要指定

## stringOcrLiteObject 成员列表 <a id="stringOcrLiteObject" href="#stringOcrLiteObject">&#x23;</a>

### stringOcrLiteObject.clickClient(hwnd,text,miniSimilar) <a id="stringOcrLiteObject.clickClient" href="#stringOcrLiteObject.clickClient">&#x23;</a>
在@hwnd参数指定的窗口上查找并点击@text指定的文本,  
@miniSimilar指定最小相似度,可选参数,默认为 0.5,  
成功返回true

### stringOcrLiteObject.close() <a id="stringOcrLiteObject.close" href="#stringOcrLiteObject.close">&#x23;</a>
关闭对象,  
关闭以后不应再使用此对象,  
默认在对象被回收时会自动关闭

### stringOcrLiteObject.config(OCR参数表) <a id="stringOcrLiteObject.config" href="#stringOcrLiteObject.config">&#x23;</a>

```aardio
stringOcrLiteObject.config({ 
	padding = 50; 
	maxSideLen = 1024; 
	boxScoreThresh = 0.6; 
	boxThresh = 0.3;
	unClipRatio = 2.0; 
	doAngle = 1;
	mostAngle= 1;/*配置OCR参数,细节请参考 chineseocr_lite 项目文档和源码*/
})
```

### stringOcrLiteObject.detectBitmap() <a id="stringOcrLiteObject.detectBitmap" href="#stringOcrLiteObject.detectBitmap">&#x23;</a>
传入 gdip.bimap 对象并识别文字,注意截图范围越小结果越准确,  
返回识别结果对象

[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectBuffer() <a id="stringOcrLiteObject.detectBuffer" href="#stringOcrLiteObject.detectBuffer">&#x23;</a>
[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectBuffer(buffer) <a id="stringOcrLiteObject.detectBuffer" href="#stringOcrLiteObject.detectBuffer">&#x23;</a>
识别文字并返回识别结果对象,  
buffer指定图像文件的内存数据,  
支持jpg,png,bmp等常见格式

### stringOcrLiteObject.detectClient() <a id="stringOcrLiteObject.detectClient" href="#stringOcrLiteObject.detectClient">&#x23;</a>
[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectClient(hwnd,x,y,cx,cy) <a id="stringOcrLiteObject.detectClient" href="#stringOcrLiteObject.detectClient">&#x23;</a>
自窗口客户区后台截图并识别文字,注意截图范围越小结果越准确,  
必须用 @hwnd 参数指定窗口句柄,  
可选用 @x,y@ 参数指定坐标  
可选用 @cx,@cy 指定宽度和高度,  
返回识别结果对象

### stringOcrLiteObject.detectImage() <a id="stringOcrLiteObject.detectImage" href="#stringOcrLiteObject.detectImage">&#x23;</a>
[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectImage(...) <a id="stringOcrLiteObject.detectImage" href="#stringOcrLiteObject.detectImage">&#x23;</a>
使用传入参数创建 gdip.bimap 对象并识别文字,  
参数与 gdip.bimap 相同,返回识别结果对象  
,注意截图范围越小结果越准确,

### stringOcrLiteObject.detectScreen() <a id="stringOcrLiteObject.detectScreen" href="#stringOcrLiteObject.detectScreen">&#x23;</a>
[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectScreen(hwnd,x,y,cx,cy) <a id="stringOcrLiteObject.detectScreen" href="#stringOcrLiteObject.detectScreen">&#x23;</a>
自屏幕截图并识别文字,注意截图范围越小结果越准确,  
所有参数可选,可选用 @hwnd 参数指定窗口句柄,  
可选用 @x,y@ 参数指定坐标  
可选用 @cx,@cy 指定宽度和高度,  
返回识别结果对象

### stringOcrLiteObject.detectWindow() <a id="stringOcrLiteObject.detectWindow" href="#stringOcrLiteObject.detectWindow">&#x23;</a>
[返回对象:stringOcrLiteResultObject](#stringOcrLiteResultObject)

### stringOcrLiteObject.detectWindow(hwnd,x,y,cx,cy) <a id="stringOcrLiteObject.detectWindow" href="#stringOcrLiteObject.detectWindow">&#x23;</a>
自窗口后台截图并识别文字,注意截图范围越小结果越准确,  
必须用 @hwnd 参数指定窗口句柄,  
可选用 @x,y@ 参数指定坐标  
可选用 @cx,@cy 指定宽度和高度,  
返回识别结果对象

### stringOcrLiteObject.findClient(hwnd,text,miniSimilar) <a id="stringOcrLiteObject.findClient" href="#stringOcrLiteObject.findClient">&#x23;</a>
在@hwnd参数指定的窗口上查找@text指定的文本,  
@miniSimilar指定最小相似度,可选参数,默认为 0.5,  
成功返回true

### stringOcrLiteObject.waitClickClient(hwnd,text,miniSimilar,timeout,hwndWait) <a id="stringOcrLiteObject.waitClickClient" href="#stringOcrLiteObject.waitClickClient">&#x23;</a>
等待@hwnd参数指定的窗口,查找并点击@text指定的文本,  
@miniSimilar指定最小相似度,可选参数,默认为 0.6,  
@timeout 为可选的超时参数,单位毫秒,  
可选用 @hwndWait 指定等待窗口句柄,不指定则默认值为 @hwnd,  
成功返回true

### stringOcrLiteObject.waitClient(hwnd,text,miniSimilar,timeout,hwndWait) <a id="stringOcrLiteObject.waitClient" href="#stringOcrLiteObject.waitClient">&#x23;</a>
等待@hwnd参数指定的窗口上出现@text指定的文本,  
@miniSimilar指定最小相似度,可选参数,默认为 0.6,  
@timeout 为可选的超时参数,单位毫秒,  
可选用 @hwndWait 指定等待窗口句柄,不指定则默认值为 @hwnd,  
成功返回true

## stringOcrLiteResultBlockObject 成员列表 <a id="stringOcrLiteResultBlockObject" href="#stringOcrLiteResultBlockObject">&#x23;</a>

### stringOcrLiteResultBlockObject.boxScore <a id="stringOcrLiteResultBlockObject.boxScore" href="#stringOcrLiteResultBlockObject.boxScore">&#x23;</a>
文本块置信度,数值

### stringOcrLiteResultBlockObject.charScores <a id="stringOcrLiteResultBlockObject.charScores" href="#stringOcrLiteResultBlockObject.charScores">&#x23;</a>
字符置信度数组

### stringOcrLiteResultBlockObject.points <a id="stringOcrLiteResultBlockObject.points" href="#stringOcrLiteResultBlockObject.points">&#x23;</a>
文本框四角坐标,长度为4的坐标数组,  
每个坐都是包含x,y坐标属性的对象,  

[返回对象:pointsObject](#pointsObject)

### stringOcrLiteResultBlockObject.text <a id="stringOcrLiteResultBlockObject.text" href="#stringOcrLiteResultBlockObject.text">&#x23;</a>
识别出的全部文本

## stringOcrLiteResultObject 成员列表 <a id="stringOcrLiteResultObject" href="#stringOcrLiteResultObject">&#x23;</a>

### stringOcrLiteResultObject.blocks <a id="stringOcrLiteResultObject.blocks" href="#stringOcrLiteResultObject.blocks">&#x23;</a>
识别结果文本块数组

### stringOcrLiteResultObject.find <a id="stringOcrLiteResultObject.find" href="#stringOcrLiteResultObject.find">&#x23;</a>
查找文本,支持模糊匹配

### stringOcrLiteResultObject.find() <a id="stringOcrLiteResultObject.find" href="#stringOcrLiteResultObject.find">&#x23;</a>
[返回对象:stringOcrLiteResultBlockObject](#stringOcrLiteResultBlockObject)

### stringOcrLiteResultObject.find(txt,miniSimilar,startIndex) <a id="stringOcrLiteResultObject.find" href="#stringOcrLiteResultObject.find">&#x23;</a>
查找文本,支持模糊匹配,  
参数 @txt 指定要查找的文本,可传入包含多个查询文本的数组,  
@miniSimilar 指定最小相似度,可选参数,  
完全相似为1,完全不相似为0,默认最小相似度为0.5,  
可以降低相似度没有问题,此函数会自动获取相似度最高的结果,  
可选指定起始索引,  
成功返回值@1为匹配的文本块信息,返回值@2为找到的索引

### stringOcrLiteResultObject.findPoint <a id="stringOcrLiteResultObject.findPoint" href="#stringOcrLiteResultObject.findPoint">&#x23;</a>
查找文本所在的区块正中点坐标,支持模糊匹配

### stringOcrLiteResultObject.findPoint(txt,miniSimilar,startIndex) <a id="stringOcrLiteResultObject.findPoint" href="#stringOcrLiteResultObject.findPoint">&#x23;</a>
查找文本所在的区块正中点坐标,支持模糊匹配,  
参数 @txt 指定要查找的文本,可传入包含多个查询文本的数组,  
@miniSimilar 指定最小相似度,可选参数,  
完全相似为1,完全不相似为0,默认最小相似度为0.5,  
可以降低相似度没有问题,此函数会自动获取相似度最高的结果,  
可选指定起始索引,  
成功返回坐标值 x,y

### stringOcrLiteResultObject.findRect <a id="stringOcrLiteResultObject.findRect" href="#stringOcrLiteResultObject.findRect">&#x23;</a>
查找文本所在的区块,支持模糊匹配

### stringOcrLiteResultObject.findRect() <a id="stringOcrLiteResultObject.findRect" href="#stringOcrLiteResultObject.findRect">&#x23;</a>
[返回对象:rectObject](https://www.aardio.com/zh-cn/docs/library-reference/global/_.html#rectObject)

### stringOcrLiteResultObject.findRect(txt,miniSimilar,startIndex) <a id="stringOcrLiteResultObject.findRect" href="#stringOcrLiteResultObject.findRect">&#x23;</a>
查找文本所在的区块,支持模糊匹配,  
参数 @txt 指定要查找的文本,可传入包含多个查询文本的数组,  
@miniSimilar 指定最小相似度,可选参数,  
完全相似为1,完全不相似为0,默认最小相似度为0.5,  
可以降低相似度没有问题,此函数会自动获取相似度最高的结果,  
可选指定起始索引,  
成功返回值@1为匹配的::RECT对象,返回值@2为找到的索引

### stringOcrLiteResultObject.resultBitmap <a id="stringOcrLiteResultObject.resultBitmap" href="#stringOcrLiteResultObject.resultBitmap">&#x23;</a>
识别结果图像,图像上已经标记了文本框,  
创建 string.ocrLite 对象指定outputBitmap参数为true可启用此字段,  
gdip.bitmap对象  

[返回对象:gdipbitmapObject](https://www.aardio.com/zh-cn/docs/library-reference/gdip/bitmap.html#gdipbitmapObject)

### stringOcrLiteResultObject.search(subString,miniSimilar) <a id="stringOcrLiteResultObject.search" href="#stringOcrLiteResultObject.search">&#x23;</a>
查找识别结果是否包含@subString指定的子字符串,支持模糊匹配,  
@miniSimilar 指定最小相似度,可选参数,  
完全相似为1,完全不相似为0,默认最小相似度为0.8,  
字符串较短时建议降低相似度

### stringOcrLiteResultObject.text <a id="stringOcrLiteResultObject.text" href="#stringOcrLiteResultObject.text">&#x23;</a>
识别出的全部文本
