Java 如何从OpenCV中的Mat对象m中读取每个像素的值作为RGB值

Java 如何从OpenCV中的Mat对象m中读取每个像素的值作为RGB值,java,android,opencv,Java,Android,Opencv,这是我的代码,我正在读取/sdcard中的imagerectangle.jpg。我想知道像素值(正常,以及RGB格式)。我应该使用什么代码来处理它 package com.idag.edge; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.util.Log; import android.widget.TextView; import o

这是我的代码,我正在读取
/sdcard
中的image
rectangle.jpg
。我想知道像素值(正常,以及RGB格式)。我应该使用什么代码来处理它

package com.idag.edge;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;

import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

public class MainActivity extends Activity {  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try
        {
            String path=Environment.getExternalStorageDirectory().getAbsolutePath() +"/rectangle.jpg";
            Mat m=Highgui.imread(path,1); 
            Log.i("Paramenres on matrix", "height "+ m.height()+" width "+ m.width()+" total = "+m.total()+" channels " +m.channels());

            System.out.println("element at 0 0 = "+ m.row(0).col(0).nativeObj+" element at 150 150 = "+ m.row(150).col(150).nativeObj);
        }

        catch(Exception e){
            System.err.print("Error in the code");
            Log.i("Error in imread", "Error in imread");
        } 
    }

}
Mat.get(x,y)
-返回(x,y)处所有通道值的数组,每个通道位于不同的位置。如果你的图像是RGB,那么你会得到一个[r,g,b]的数组

Mat.put(x,y,value)
-将(x,y)处的通道值设置为
value

double[] rgb = image.get(0, 0);
Log.i("", "red:"+rgb[0]+"green:"+rgb[1]+"blue:"+rgb[2]);
image.put(0, 0, new double[]{255, 255, 0});//sets the pixel to yellow

OpenCV中使用的函数是
double[]Mat::get(int row,int col)

我已经编写了“我正在从/sdcard读取image rectangle.jpg”,它现在存储在m中,Mat变量为图像尺寸的大小宽度x高度。我想在每个像素中存储m…的值。。。。你什么都没试过?你来这里是希望我们给你完整的代码,我已经试过了问题中提到的所有东西,它就在你面前,除了从m中提取值。我不知道像素值和我得到的navtiveObj值是相同还是不同。