如何从图像中获取 RGB 矩阵?
How to get the RGB matrix from an image?
如何在 openCv 中从图像创建矩阵 R,G,B。
matSrcBRG 是 Mat 变量。我的图片是 img_about
try {
matSrcBGR = Utils.loadResource(context, R.raw.img_about);
} catch (IOException e) {
e.printStackTrace();
}
int rows = matSrcBGR.rows(); //Calculates number of rows
int cols = matSrcBGR.cols(); //Calculates number of columns
int ch = matSrcBGR.channels(); //Calculates number of channels (Grayscale: 1, RGB: 3, etc.)
double[] bgrColor = matSrcBGR.get(matSrcBGR.rows(), matSrcBGR.cols());
我的答案是
int rows = matSrcBGR.rows(); //Calculates number of rows
int cols = matSrcBGR.cols(); //Calculates number of columns
int channels = matSrcBGR.channels(); //Calculates number of channels
//channel2=red , channel1=green ,channel0=blue
int[][][] matrix = new int[cols][rows][channels];
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
for (int channel = 0; channel < channels; channel++) {
matrix[col][row][channel] = (int) matSrcBGR.get(row, col)[channel];
}
}
}
如何在 openCv 中从图像创建矩阵 R,G,B。 matSrcBRG 是 Mat 变量。我的图片是 img_about
try {
matSrcBGR = Utils.loadResource(context, R.raw.img_about);
} catch (IOException e) {
e.printStackTrace();
}
int rows = matSrcBGR.rows(); //Calculates number of rows
int cols = matSrcBGR.cols(); //Calculates number of columns
int ch = matSrcBGR.channels(); //Calculates number of channels (Grayscale: 1, RGB: 3, etc.)
double[] bgrColor = matSrcBGR.get(matSrcBGR.rows(), matSrcBGR.cols());
我的答案是
int rows = matSrcBGR.rows(); //Calculates number of rows
int cols = matSrcBGR.cols(); //Calculates number of columns
int channels = matSrcBGR.channels(); //Calculates number of channels
//channel2=red , channel1=green ,channel0=blue
int[][][] matrix = new int[cols][rows][channels];
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
for (int channel = 0; channel < channels; channel++) {
matrix[col][row][channel] = (int) matSrcBGR.get(row, col)[channel];
}
}
}