Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is an excellent explanation: How to get and modify the pixel of Mat in Java?.

Here is an excellent explanation: How to get and modify the pixel of Mat in Java? In your case code can be like:


// assume, that Mats with one channel
byte[] sourceBuffer = new byte[srcMat.total()];
byte[] destinationBuffer = new byte[dstMat.total()];
int cols = srcMat.cols();
int rows = srcMat.rows();
for (int y = 0; y < rows; y++){
  for (int x = 0; x < cols; x++){
    for (int i = 0; i <= 2; i++){
          destinationBuffer[y * cols + 3 * x + i] = sourceBuffer(vy * cols + 3 * vx + i) 
    }
  }
}

Here is an excellent explanation: How to get and modify the pixel of Mat in Java? In your case code can be like:


// assume, that Mats with one channel
byte[] sourceBuffer = new byte[srcMat.total()];
byte[] destinationBuffer = new byte[dstMat.total()];
srcMat.get(0, 0, sourceBuffer);
int cols = srcMat.cols();
int rows = srcMat.rows();
for (int y = 0; y < rows; y++){
  for (int x = 0; x < cols; x++){
    for (int i = 0; i <= 2; i++){
          destinationBuffer[y * cols + 3 * x + i] = sourceBuffer(vy * cols + 3 * vx + i) 
    }
  }
}
dstMat.put(0, 0, destinationBuffer);