4

rectangle.jpgこれは、から画像を読み取っている私のコードです/sdcard。ピクセル値(通常、および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");
        } 
    }

}
4

2 に答える 2

10

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
于 2013-01-15T13:38:37.740 に答える
0

OpenCVで使用される関数はですdouble[] Mat::get(int row, int col)

于 2016-02-26T09:53:25.547 に答える