YYPOST群发软件 发表于 2025-3-12 06:03:25

AIWORK 软件全功能 OCR 查找区域功能代码示例

<table cellspacing="0" cellpadding="0" style="table-layout: fixed; width: 979px; font-size: 12px;"><tbody><tr><td class="t_f" id="postmessage_346" style="font-size: 14px; line-height: 24px;"><ignore_js_op>&nbsp;</ignore_js_op><ignore_js_op>&nbsp;</ignore_js_op><ignore_js_op>&nbsp;</ignore_js_op><ignore_js_op>&nbsp;</ignore_js_op><ignore_js_op></ignore_js_op><br><br><div class="blockcode" style="overflow: hidden; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; background-image: linear-gradient(90deg, rgb(237, 237, 237), rgb(237, 237, 237)); background-size: 43px; color: rgb(102, 102, 102); zoom: 1;"><div id="code_Hoo"><ol style="margin-left: 10px !important;"><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第一个示例:获取屏幕截图并进行 OCR 文字识别(简体中文)<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img1 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocr1 = img1.MLKitOcr('zhs');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var text1 = ocr1.getAllString();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">printl(text1);<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img1.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 这是一个最基本的 OCR 示例。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 使用 MLKitOcr 方法通过简体中文词库识别截图中的文字。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 最终输出识别到的全文本信息。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第二个示例:指定区域内的 OCR 文字识别(中文)<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img2 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrRegion2 = ;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult2 = img2.MLKitOcrRect('zh', ocrRegion2);<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var recognizedText2 = ocrResult2.getAllString();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">printl("OCR识别结果: " + recognizedText2);<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img2.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 此示例中,OCR 定义了一个特定的屏幕区域来识别文本,避免了全屏识别的开销。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 使用 MLKitOcrRect 方法优化了识别区域。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第三个示例:使用 PaddleOCR 识别并查找特定文本<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img3 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult3 = img3.paddleOCR(640, );<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var target3 = ocrResult3.findIncludeText("雷电");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (target3) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; target3.hidClick();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("成功点击目标区域: 雷电");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("目标区域未找到: 雷电");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img3.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 示例使用 PaddleOCR 技术识别文本。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 识别完成后,查找特定文本,并对找到目标进行点击操作。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第四个示例:全屏 OCR 查找文本内容并点击<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img4 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult4 = img4.paddleOCR(640, );<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var target4 = ocrResult4.findIncludeText("雷电");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (target4) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; target4.click();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未找到指定文本");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img4.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 该示例与第三个类似,但更高效地处理了查找和目标动作操作。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第五个示例:查找包含目标文字的多个区域<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img5 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult5 = img5.MLKitOcr('zh');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var targets5 = ocrResult5.findIncludeTexts("雷电");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (targets5.length &gt; 0) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; targets5.forEach(target =&gt; {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;target.click();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; });<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未找到指定文本");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img5.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 查找包含目标文字的多个区域,返回所有目标的列表。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 遍历所有目标,逐一对其执行点击操作。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第六个示例:获取 OCR 识别到的所有文本并打印<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img6 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult6 = img6.paddleOCR(640, );<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var allText6 = ocrResult6.getAllString();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (!allText6) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未检测到任何文本");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("检测到的文本内容: " + allText6);<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img6.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 示例展示如何提取 OCR 识别结果中的所有字符信息。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第七个示例:通过 MLKitOcr 完全读出屏幕文字<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img7 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult7 = img7.MLKitOcr('zh');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">printl(ocrResult7.getAllString());<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img7.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 示例使用 MLKitOcr 在全屏范围内提取所有文本信息。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第八个示例:获取 JSON 格式的 OCR 识别结果<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img8 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult8 = img8.MLKitOcr('zh');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var jsonResult8 = ocrResult8.getJson();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">printl(JSON.stringify(jsonResult8, null, 2));<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img8.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 此示例展示了如何将 OCR 结果以 JSON 格式获取。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第九个示例:获取 OCR 的 JSON 表示<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img9 = screen.screenShotFull();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrResult9 = img9.MLKitOcr('zh');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var ocrJson9 = ocrResult9.getJson();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">printl("OCR 结果 JSON: " + JSON.stringify(ocrJson9));<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img9.recycle();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 将 OCR 输出结果以 JSON 格式显示,便于程序进一步处理。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第十个示例:OpenCV OCR 使用<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var mat10 = screen.screenShot(720, 1280, 100).getMat();<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var seek10 = opencv.OCR(mat10, '自己的库.ocr', 0.95, 0);<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (seek10) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl(seek10.findIncludeText('蜂'));<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未找到了");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 使用 OpenCV 库执行 OCR,匹配的置信度为 0.95。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 根据内容查找包含特定文本的区域。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 第十一个示例:OpenCV OCR 扩展功能使用<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var seek11 = opencv.OCREx('多点比色.cv');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (seek11) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl(seek11.findIncludeText('雷电模拟器'));<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未找到了");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var seek11Alt = opencv.OCREx('多点比色.cv');<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (opencv.checkColorsEx('多点比色.cv')) {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl(seek11Alt.getAllString());<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; printl("未找到了");<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">/*<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">说明:<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 使用 opencv.OCREx 对指定的 cv 文件进行 OCR 识别。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">- 扩展功能 checkColorsEx 用于进一步处理颜色匹配和文本识别结果。<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">*/<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"></li></ol></div><span style="color: rgb(255, 255, 255); margin-left: 43px; font-size: 12px; cursor: pointer; user-select: none; display: inline-block; margin-top: 8px; padding: 2px 8px; background: rgb(153, 153, 169); border-radius: 4px;">复制代码</span></div><div align="left">将说明单独列在代码块下面。</div><div align="left"><br></div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第一个var img = screen.screenShotFull();var ocr = img.MLKitOcr('zhs');var text = ocr.getAllString();printl(text);img.recycle();<br><div align="left">说明:截取全屏截图,使用 MLKitOcr(简体中文)进行 OCR 识别,获取识别到的所有文字,并打印结果。最后释放图片资源。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第二个var img = screen.screenShotFull();var ocrRegion = ;var ocrResult = img.MLKitOcrRect('zh', ocrRegion);var recognizedText = ocrResult.getAllString();printl("OCR识别结果: " + recognizedText);img.recycle();<br><div align="left">说明:定义屏幕中特定区域作为 OCR 识别的范围,使用 MLKitOcrRect 进行区域内的文字识别,并打印结果。释放图片资源。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第三个var img = screen.screenShotFull();let ocrResult = img.paddleOCR(640, );var target = ocrResult.findIncludeText("雷电");if (target) {&nbsp; &nbsp; target.hidClick();&nbsp; &nbsp; printl("成功点击目标区域: 雷电");} else {&nbsp; &nbsp; printl("目标区域未找到: 雷电");}img.recycle();<br><div align="left">说明:全屏截图,使用 paddleOCR 进行 OCR 识别,全屏范围包含的输出结果中查找包含“雷电”的目标,并点击目标区域。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第四个let img = screen.screenShotFull();let ocrResult = img.paddleOCR(640, );let target = ocrResult.findIncludeText("雷电");if (target) {&nbsp; &nbsp; target.click();} else {&nbsp; &nbsp; printl("未找到指定文本");}img.recycle();<br><div align="left">说明:与第三个类似,全屏 OCR 识别,寻找包含“雷电”的文本目标并执行点击操作。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第五个let img = screen.screenShotFull();let ocrResult = img.MLKitOcr('zh');let targets = ocrResult.findIncludeTexts("雷电");if (targets.length &gt; 0) {&nbsp; &nbsp; targets.forEach(target =&gt; {&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;target.click();&nbsp; &nbsp; });} else {&nbsp; &nbsp; printl("未找到指定文本");}img.recycle();<br><div align="left">说明:全屏使用 MLKitOcr 执行 OCR 识别,寻找多个包含特定文字(如“雷电”)的目标,并依次点击。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第六个let img = screen.screenShotFull();let ocrResult = img.paddleOCR(640, );let allText = ocrResult.getAllString();if (!allText) {&nbsp; &nbsp; printl("未检测到任何文本");} else {&nbsp; &nbsp; printl("检测到的文本内容: " + allText);}img.recycle();<br><div align="left">说明:全屏截图后,通过 paddleOCR 获取屏幕内所有的文字信息,并打印检测到的内容。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第七个let img = screen.screenShotFull();let ocrResult = img.MLKitOcr('zh');printl(ocrResult.getAllString());img.recycle();<br><div align="left">说明:截屏并调用 MLKitOcr,直接获取所有识别到的字符串并打印。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第八个let img = screen.screenShotFull();let ocrResult = img.MLKitOcr('zh');let jsonResult = ocrResult.getJson();printl(JSON.stringify(jsonResult, null, 2));img.recycle();<br><div align="left">说明:通过 MLKitOcr 执行 OCR 识别后,获取 JSON 格式的结果并以美化的形式输出。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第九个let img = screen.screenShotFull();let ocrResult = img.MLKitOcr('zh');let ocrJson = ocrResult.getJson();printl("OCR 结果 JSON: " + JSON.stringify(ocrJson));img.recycle();<br><div align="left">说明:OCR 识别后直接打印 JSON 格式的内容。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第十个var mat = screen.screenShot(720, 1280, 100).getMat();var seek = opencv.OCR(mat, '蜂群课堂.ocr', 0.95, 0);if (seek) {&nbsp; &nbsp; printl(seek.findIncludeText('蜂'))} else {&nbsp; &nbsp; printl("未找到了");}<br><div align="left">说明:使用 opencv 库对指定截图获取的矩阵内容通过训练的 .ocr 文件进行 OCR 并查找特定内容。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);">//第十一个var seek = opencv.OCREx('多点比色.cv');if (seek) {&nbsp; &nbsp; printl(seek.findIncludeText('雷电模拟器'));} else {&nbsp; &nbsp; printl("未找到了");}<br><div align="left">说明:使用 opencv.OCREx 根据配置文件查找目标文字内容。</div><hr class="l" style="clear: both; background-color: rgb(237, 237, 237); color: rgb(237, 237, 237);"><div align="left">这些代码块中展示了如何使用 OCR 工具进行从简单到复杂的文字识别操作,说明部分逐一概述了各代码段的主要功能和处理过程。</div></td></tr></tbody></table><p></p>
页: [1]
查看完整版本: AIWORK 软件全功能 OCR 查找区域功能代码示例