saeedmpt
saeedmpt

Reputation: 154

How to get the RGB matrix from an image?

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());

Upvotes: 1

Views: 280

Answers (1)

saeedmpt
saeedmpt

Reputation: 154

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];
                }
            }
        }

Upvotes: 2

Related Questions