Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

remap android

hi, New here. I'm following your documentation in android platform with opencv4android. One line of the code there is:

map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;

and my question is: 1 there's no method of map_x.at<float>(j,i) and map_x.get(j,i) will return double[]. 2 map_x.get(j,i) is an array, then why map_x.at<float>(j,i) is one value not an array? 3 how can I translate it to java version?

I've google a lot of related answers, please help. Thank you.

remap android

hi, New here. I'm following your documentation in android platform with opencv4android. One line of the code there is:

map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;

and my question is: 1 there's no method of map_x.at<float>(j,i) and map_x.get(j,i) will return double[]. 2 map_x.get(j,i) is an array, then why map_x.at<float>(j,i) is one value not an array? 3 how can I translate it to java version?

I've google a lot of related answers, please help. Thank you.

edit:

My code is like this ,just translate the code from documentation to android:

Utils.bitmapToMat(originalBitmap, inMat);

int rows = inMat.rows();
int cols = inMat.cols();
Mat mapX = new Mat(rows, cols, CvType.CV_32FC1);
Mat mapY = new Mat(rows, cols, CvType.CV_32FC1);

for (int j = 0; j < rows; j++) {
  for (int i = 0; i < cols; i++) {
        if (i > cols * 0.25 && i < cols * 0.75 && j > rows * 0.25 && j < rows * 0.75) {
          float[] pixelsX = new float[rows * cols];
          float[] pixelsY = Arrays.copyOf(pixelsX, pixelsX.length);
          pixelsX[j * cols + i] = (float) (2 * (i - cols * 0.25) + 0.5);
          pixelsY[j * cols + i] = (float) (2 * (i - rows * 0.25) + 0.5);
          mapX.put(j, i, pixelsX);
          mapY.put(j, i, pixelsY);
        }
  }
}

Imgproc.remap(inMat, outMat, mapX, mapY, CV_INTER_LINEAR, BORDER_CONSTANT, new Scalar(0, 0, 0));
Utils.matToBitmap(outMat, bitmap);

It didn't show the image well, where go wrong?

remap android

hi, New here. I'm following your documentation in android platform with opencv4android. One line of the code there is:

map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;

and my question is: 1 there's no method of map_x.at<float>(j,i) and map_x.get(j,i) will return double[]. 2 map_x.get(j,i) is an array, then why map_x.at<float>(j,i) is one value not an array? 3 how can I translate it to java version?

I've google a lot of related answers, please help. Thank you.

edit:

My code is like this ,just translate the code from documentation to android:

Utils.bitmapToMat(originalBitmap, inMat);

int rows = inMat.rows();
int cols = inMat.cols();
Mat mapX = new Mat(rows, cols, CvType.CV_32FC1);
Mat mapY = new Mat(rows, cols, CvType.CV_32FC1);

for (int j = 0; j < rows; j++) {
  for (int i = 0; i < cols; i++) {
        if (i > cols * 0.25 && i < cols * 0.75 && j > rows * 0.25 && j < rows * 0.75) {
          float[] pixelsX = new float[rows * cols];
          float[] pixelsY = Arrays.copyOf(pixelsX, pixelsX.length);
          pixelsX[j * cols + i] = (float) (2 * (i - cols * 0.25) + 0.5);
          pixelsY[j * cols + i] = (float) (2 * (i - rows * 0.25) + 0.5);
          mapX.put(j, i, pixelsX);
          mapY.put(j, i, pixelsY);
        }
  }
}

Imgproc.remap(inMat, outMat, mapX, mapY, CV_INTER_LINEAR, BORDER_CONSTANT, new Scalar(0, 0, 0));
Utils.matToBitmap(outMat, bitmap);

It didn't show the image well, where go wrong?

edit 2:

still not good:

int rows = inMat.rows();
int cols = inMat.cols();
float[] pixelsX = new float[rows * cols];
float[] pixelsY = new float[rows * cols];

for (int j = 0; j < rows; j++) {
  for (int i = 0; i < cols; i++) {
        if (i > cols * 0.25 && i < cols * 0.75 && j > rows * 0.25 && j < rows * 0.75) {
          pixelsX[j * cols + i] = (float) (2 * (i - cols * 0.25) + 0.5);
          pixelsY[j * cols + i] = (float) (2 * (i - rows * 0.25) + 0.5);
        }else {
        //default float value should be 0, but no harm.
          pixelsX[j * cols + i] = 0;
          pixelsY[j * cols + i] = 0;
        }
  }
}

Mat mapX = new Mat(rows, cols, CvType.CV_32FC1);
Mat mapY = new Mat(rows, cols, CvType.CV_32FC1);
mapX.put(0, 0, pixelsX); //why 0 row 0 col?
mapY.put(0, 0, pixelsY);

Imgproc.remap(inMat, outMat, mapX, mapY, CV_INTER_LINEAR, BORDER_CONSTANT, new Scalar(0, 0, 0));

original pic: image description

after zooming pic: image description