cv图像识别

安卓opencv全分辨率找图


connectedComponentsWithStats 连通域检测

<p>[TOC]</p> <h5>简要描述</h5> <ul> <li>connectedComponentsWithStats 检查轮廓、边缘连通域。获得连通域位置、宽高、中心。在物体形状、特征检测领域有很大作用 <strong>V 2.1.2 以及以上版本可用</strong></li> </ul> <h5>参数</h5> <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;">mat</td> <td style="text-align: left;">是</td> <td style="text-align: left;">mat</td> <td>欲检测的mat对象, 必须8uc1 格式,</td> </tr> <tr> <td style="text-align: left;">connectivity</td> <td style="text-align: left;">(可选)</td> <td style="text-align: left;">int</td> <td>标记连通域时使用的邻域种类,默认=8. 4:四邻域,8:八邻域。</td> </tr> <tr> <td style="text-align: left;">ltype</td> <td style="text-align: left;">(可选)</td> <td style="text-align: left;">int</td> <td>输出图像的数据类型,默认=4。目前支持CV_32S=4和CV_16U=2两种数据类型。</td> </tr> <tr> <td style="text-align: left;">ccltype</td> <td style="text-align: left;">(可选)</td> <td style="text-align: left;">int</td> <td>算法类型。 默认=0。可选值: 0、-1、1</td> </tr> </tbody> </table> <h5>返回参数说明</h5> <p>返回JSON数组 或 NULL</p> <p>返回样例: [ {&quot;zx&quot;:337,&quot;zy&quot;:181,&quot;left&quot;:51,&quot;top&quot;:24,&quot;width&quot;:570,&quot;height&quot;:306,&quot;area&quot;:20956,&quot;max&quot;:0},{&quot;zx&quot;:345,&quot;zy&quot;:190,&quot;left&quot;:0,&quot;top&quot;:0,&quot;width&quot;:690,&quot;height&quot;:380,&quot;area&quot;:240293,&quot;max&quot;:0},{&quot;zx&quot;:83,&quot;zy&quot;:38,&quot;left&quot;:80,&quot;top&quot;:36,&quot;width&quot;:7,&quot;height&quot;:5,&quot;area&quot;:23,&quot;max&quot;:0},{&quot;zx&quot;:155,&quot;zy&quot;:43,&quot;left&quot;:154,&quot;top&quot;:40,&quot;width&quot;:3,&quot;height&quot;:7,&quot;area&quot;:10,&quot;max&quot;:0},{&quot;zx&quot;:607,&quot;zy&quot;:42,&quot;left&quot;:605,&quot;top&quot;:40,&quot;width&quot;:5,&quot;height&quot;:5,&quot;area&quot;:11,&quot;max&quot;:0},{&quot;zx&quot;:522,&quot;zy&quot;:48,&quot;left&quot;:519,&quot;top&quot;:47,&quot;width&quot;:7,&quot;height&quot;:3,&quot;area&quot;:13,&quot;max&quot;:0},{&quot;zx&quot;:597,&quot;zy&quot;:56,&quot;left&quot;:597,&quot;top&quot;:56,&quot;width&quot;:1,&quot;height&quot;:1,&quot;area&quot;:1,&quot;max&quot;:0},{&quot;zx&quot;:447,&quot;zy&quot;:64,&quot;left&quot;:445,&quot;top&quot;:57,&quot;width&quot;:5,&quot;height&quot;:15,&quot;area&quot;:45,&quot;max&quot;:0},{&quot;zx&quot;:83,&quot;zy&quot;:95,&quot;left&quot;:83,&quot;top&quot;:94,&quot;width&quot;:3,&quot;height&quot;:3,&quot;area&quot;:6,&quot;max&quot;:0} ]</p> <h5>连通域检测样例</h5> <pre><code class="language-java">//载入图 var mat_1=cvImg.loadFromFile('/sdcard/Pictures/t1.png',1); //转到灰度 var mat_gray=cvImg.toGray(mat_1); //二值化 var mat_two=cvImg.threshold(mat_gray,0,100,255); //连通域检测 var list=cvImg.connectedComponentsWithStats(mat_two); //在原图上画出连通域位置 for(var i=0;i&lt;list.length;i++){ var key=list[i]; cvImg.rectangle( mat_1, key.left, key.top, key.left+key.width, key.top+key.height, [random(100,255),random(100,255),random(100,255),255], 1) } //保存到文件,查看效果 cvImg.toFile(mat_1,"连通域效果输出.png") logd(JSON.stringify(list))</code></pre> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3efd42891c06d27d5801ceca0b315d50&amp;file=file.png" alt="" /></p>

页面列表

ITEM_HTML