Skip to content

Instantly share code, notes, and snippets.

@munhra
Created Oct 29, 2018
Embed
What would you like to do?
private float[][][][] cropImage(String absolutePath) {
Mat imageRaw = Imgcodecs.imread(absolutePath);
float[][][][] imgData = new float [DIM_BATCH_SIZE] [DIM_IMG_SIZE_X] [DIM_IMG_SIZE_Y] [DIM_PIXEL_SIZE];
int square_qtd_x = 20;
int square_qtd_y = 20;
Log.d(TAG,"Squares in x "+square_qtd_x);
Log.d(TAG,"Squares in y "+square_qtd_y);
Log.d(TAG, "Total Crop Squares "+square_qtd_x * square_qtd_y);
int square_counter = 0;
for (int idx = 0 ; idx < square_qtd_x ; idx ++) {
for(int idy = 0 ; idy < square_qtd_y ; idy ++) {
for (int i = DIM_IMG_SIZE_X - 1 ; i >= 0 ; i --) {
for (int j = DIM_IMG_SIZE_Y - 1 ; j >= 0 ; j --) {
float[] bgrColorsNormalized = new float[3];
bgrColorsNormalized[0] = new Float(imageRaw.get(i + DIM_IMG_SIZE_X * idx, j + DIM_IMG_SIZE_Y * idy)[2]) / 255; // b
bgrColorsNormalized[1] = new Float(imageRaw.get(i + DIM_IMG_SIZE_X * idx, j + DIM_IMG_SIZE_Y * idy)[1]) / 255; // g
bgrColorsNormalized[2] = new Float(imageRaw.get(i + DIM_IMG_SIZE_X * idx, j + DIM_IMG_SIZE_Y * idy)[0]) / 255; // r
imgData[square_counter][i][j] = bgrColorsNormalized;
}
}
square_counter ++;
}
}
Log.d(TAG,"raw image size "+imageRaw.size());
return imgData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment