对于输入字符串:"Mat [0 * 0 * CV_32FC1,isCont = true,isSubmat = false,nativeObj = 0x78a0dff700,dataAddr = 0x0]" -错误填充矩阵 [英] For input string: "Mat [ 0*0*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x78a0dff700, dataAddr=0x0 ]" - Error filling matrix

查看:122
本文介绍了对于输入字符串:"Mat [0 * 0 * CV_32FC1,isCont = true,isSubmat = false,nativeObj = 0x78a0dff700,dataAddr = 0x0]" -错误填充矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Android上的opencv一起开发图像分割应用程序,但使用了分水岭算法.我正在打开一个图像并创建一个具有相同图像尺寸的蒙版,并为该蒙版的所有行和列传递0.但是,在下一步中,即遍历一个0数组并在该数组中添加为坐标,我得到了错误:

I am working with opencv on android for the development of an image segmentation application, but with the watershed algorithm. I am opening an image and creating a mask with the same image size and passing 0 for all the rows and columns of that mask. However, in the next step, which is to go through an array of 0 and add as coordinates in that array, I have the error:

java.lang.NumberFormatException: For input string: "Mat [0 * 0 * CV_32FC1, isCont = true, isSubmat = false, nativeObj = 0x78a0dff700, dataAddr = 0x0] "

那样,不可能将新值传递给数组,有人可以帮我吗?

With that, it is not possible to pass the new values ​​to an array, can someone help me with this?

代码:

// Load the image
val srcOriginal = Imgcodecs.imread(currentPhotoPath)

// Create a blank image of zeros (same dimension as img)
val markers = Mat.zeros(srcOriginal.rows(), srcOriginal.cols(), CvType.CV_32F)

// Example assigning a new value to a matrix index
for (i in 0 until markers.toInt()) {
   markers.put(my_canvas.pointsToDrawY.get(i).toInt(), my_canvas.pointsToDrawY.get(i).toInt(), intArrayOf(0,0,255))
}

错误:

推荐答案

所以我终于理解了这个问题.线

So I finally understood the problem. The line

Mat.zeros(srcOriginal.rows(), srcOriginal.cols(), CvType.CV_32F)

表示要创建一个srcOriginal.rows() x srcOriginal.cols()像素的Mat.

says to create a Mat of srcOriginal.rows() by srcOriginal.cols() pixels.

现在,您必须遍历其中的行和列,以RGB设置其颜色值.换句话说,您必须设置第0行的所有列值,然后设置第1行的所有列值,依此类推.

Now you have to loop through it rows and columns to set their color values in RGB. In other words you have to set all the column values for 0th row, then all the column values for 1st row, and so on.

因此,您必须循环两次,一次循环用于行,一次循环用于列.您可以使用两个for循环.我将它们提取到一个内联函数中,以便以后进行管理.

So you have to loop twice, one for row and one for column. You can either use two for loops. I'll extract them into an inline function so that they will be easier to manage afterwards.

// function declaration toplevel / or in class
inline fun loopThrough(rows: Int, cols: Int, block: (Int, Int) -> Unit) {
    for(r in 0 until rows) {
        for (c in 0 until cols) block(r, c)
    }
}

// code here
val rows = srcOriginal.rows()
val cols = srcOriginal.cols()
val markers = Mat.zeros(rows, cols, CvType.CV_32F)

loopThrough(rows, cols) { row, col ->
   markers.put(row, col, intArrayOf(0,0,255))
}

这篇关于对于输入字符串:"Mat [0 * 0 * CV_32FC1,isCont = true,isSubmat = false,nativeObj = 0x78a0dff700,dataAddr = 0x0]" -错误填充矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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