如何在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());
答案 0 :(得分:2)
我的回答是
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];
}
}
}