cv图像识别

安卓opencv全分辨率找图


matchTemplateEx 模板匹配返回多目标

<p>[TOC]</p> <h5>简要描述</h5> <ul> <li> <p>模板匹配返回多个匹配良好的目标。它内部是对matchTemplate函数的封装。 透明图匹配:当图片的4个角,颜色一样时,将把该颜色视作透明色。 透明色边缘:尽量使要寻找的图片位于正中间,透明色边缘最好留个2-3个像素。</p> </li> <li> <p>插件内部对返回的结果的相似度,已经从大到小排列,如通常使用第1个成员目标就行了</p> </li> <li>此模板找图不能全分,但速度最快。能同时寻找多个同样目标。 <h5>参数</h5></li> </ul> <table> <thead> <tr> <th style="text-align: left;">参数名</th> <th style="text-align: left;">必选</th> <th style="text-align: left;">类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">mat1</td> <td style="text-align: left;">是</td> <td style="text-align: left;">mat</td> <td>输入图像。</td> </tr> <tr> <td style="text-align: left;">mat2</td> <td style="text-align: left;">是</td> <td style="text-align: left;">mat</td> <td>模板图像。</td> </tr> <tr> <td style="text-align: left;">sim</td> <td style="text-align: left;">是</td> <td style="text-align: left;">double</td> <td>相似度</td> </tr> </tbody> </table> <h5>返回参数说明</h5> <p><code>JSON | null</code></p> <p>x1, y1, x2, y2, 相似度</p> <p>以下是输出样例。</p> <p>[ {&quot;x1&quot;:226,&quot;y1&quot;:233,&quot;x2&quot;:299,&quot;y2&quot;:310,&quot;sim&quot;:0.9921951495764245}, {&quot;x1&quot;:45,&quot;y1&quot;:174,&quot;x2&quot;:118,&quot;y2&quot;:251,&quot;sim&quot;:0.6605219142754991}, {&quot;x1&quot;:334,&quot;y1&quot;:7,&quot;x2&quot;:407,&quot;y2&quot;:84,&quot;sim&quot;:0.6543360084863401} ]</p> <h5>示例(返回多目标)</h5> <pre><code class="language-java"> //载入图像 var mat=cvImg.loadFromFile("/sdcard/Pictures/c1.png",1); //载入模板图 var mat2=cvImg.loadFromFile("/sdcard/Pictures/b1.png",1); //模板匹配Ex。 var info=cvImg.matchTemplateEx(mat,mat2,0.5); for(let i=0;i&lt;info.length;i++){ cvImg.rectangle(mat,info[i].x1,info[i].y1,info[i].x2,info[i].y2,[255,0,0,0],2); } //输出图像文件,看结果用 cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg"); //释放资源 cvImg.release(mat); cvImg.release(mat2); </code></pre> <p>原图 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=48220fe303adef339cb3402b0dec5958" alt="" /> 模板图 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=59f229c0967bd57a7364bded73cab482" alt="" /> 结果图 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=d237b045fc99f7a1781c51a939ef3982" alt="" /></p> <h5>示例(透明找图)</h5> <pre><code class="language-java"> //载入图像 var mat=cvImg.loadFromFile("/sdcard/Pictures/c1.png",1); //载入模板图 var mat2=cvImg.loadFromFile("/sdcard/Pictures/b1.png",1); //模板匹配Ex。 var info=cvImg.matchTemplateEx(mat,mat2,0.5); for(let i=0;i&lt;info.length;i++){ cvImg.rectangle(mat,info[i].x1,info[i].y1,info[i].x2,info[i].y2,[255,0,0,0],2); } //输出图像文件,看结果用 cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg"); //释放资源 cvImg.release(mat); cvImg.release(mat2); </code></pre> <p>原图 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=48220fe303adef339cb3402b0dec5958" alt="" /></p> <p><strong>【模板图】(透明图制作:【当图片的4个角,颜色一样时】,将把该颜色视作透明色。)</strong> <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=5c3f268738bc467f53c5f571674fe4a4" alt="" /></p> <p>结果图 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=d61694df414a141903d8af84b4188cb9" alt="" /></p>

页面列表

ITEM_HTML