OpenCV Java:如何访问findNonZero()返回的坐标? [英] OpenCV Java: how to access coordinates returned by findNonZero()?

查看:728
本文介绍了OpenCV Java:如何访问findNonZero()返回的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的android应用中,我正在使用findNonZero()查找和访问二进制图像中的白点.

In my android app, I am using findNonZero() to find and access white points in a binary image.

我将图像(binMat,尺寸:595 * 800)作为方法的输入,然后得到:

I get the image (binMatwith size: 595*800) as the input to the method and then I have:

...
Mat wLocMat = Mat.zeros(binMat.size(), binMat.channels()); 
Core.findNonZero(binMat, wLocMat);

问题是:我不知道如何访问wLocMat中存储的白点坐标!当我登录wLocMat.toString()时,我得到了:

The problem is: I don't know how to access the white points' coordinates stored inside the wLocMat! when I log the wLocMat.toString(), I get this:

[ 476000*1*CV_32SC2, isCont=true, isSubmat=false, nativeObj=0x74abd920, dataAddr=0x75bac010 ]

那么,我究竟如何才能访问存储在wLocMat中的坐标?

So, how exactly can I access the coordinates stored in wLocMat?!

推荐答案

我的问题是将输出矩阵初始化为图像大小.我只需要创建一个空的Mat并将其传递给函数:

My problem was initializing the output matrix to the size of the image. I just had to create an empty Mat and pass it to the function:

...
Mat wLocMat = Mat.zeros(); 
Core.findNonZero(binMat, wLocMat);

然后,通过将wLocMat转换为MatOfPoint,可以轻松访问坐标:

Then, by converting wLocMat to MatOfPoint, the coordinates are easily accessible:

MatOfPoint mop = new MatOfPoint(wLocMat);

这篇关于OpenCV Java:如何访问findNonZero()返回的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆