For Input String: "Mat [ 0*0*CV_32FC1, IsCont=true, IsSubmat=false, NativeObj=0x78a0dff700, DataAddr=0x0 ]" - Error Filling Matrix
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 s
Solution 1:
So I finally understood the problem. The line
Mat.zeros(srcOriginal.rows(), srcOriginal.cols(), CvType.CV_32F)
says to create a Mat of srcOriginal.rows()
by srcOriginal.cols()
pixels.
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.
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))
}
Solution 2:
I don't think you can use markers.toInt() in the for loop. Markers is a multidimensional array and can not be converted to an Integer.
Post a Comment for "For Input String: "Mat [ 0*0*CV_32FC1, IsCont=true, IsSubmat=false, NativeObj=0x78a0dff700, DataAddr=0x0 ]" - Error Filling Matrix"