1

I am working with opencv on android for the development of an image segmentation application, but specifically with the watershed algorithm. I'm opening the image and creating a mask with the same size as the image and passing 0 for all the rows and columns of that mask. However, in the following step, which is to add new values ​​for certain rows and columns of this matrix, I have the error: No get method providing array access With that, I am not able to pass the new values ​​to the matrix, can someone help me with this?

COde:

   // 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
    markers.put(0,0,255)

Error:

enter image description here

Carlos Diego
  • 348
  • 5
  • 20

2 Answers2

1

try this:

markers.put(0,0,X);

where x is array containing pixel vales (because it may be RGB,GRAY SCALE,etc) In Java you can use Mat::get() and Mat::put() methods.

Read this for more details.

1

OpenCV library in java doesn't take input Int as a parameter. You can see in the method declaration https://docs.opencv.org/3.4/javadoc/org/opencv/core/Mat.html#get(int,int,int%5B%5D).

Pass an IntArray for RGB values along with row and col values:

// Replace row and col with your values
markers.put(row, col, intArrayOf(0,0,255))
Animesh Sahu
  • 7,445
  • 2
  • 21
  • 49