1

how to create matrix R,G,B from image in openCv . matSrcBRG is Mat variable . and my image is 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());
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
saeedmpt
  • 144
  • 1
  • 7

1 Answers1

2

my answer is

        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];
                }
            }
        }
saeedmpt
  • 144
  • 1
  • 7