Reputation: 11
I am new in OpenCV so please to be patient. I am doing an Android application to measure the similarity of leaf color. I've tried using canny to detect only the leaf area but but I think it requires a longer process. Here is the code, only to the detection of leaf area.
public class editImage extends Activity {
//private static final int CV_64FC1 = 0;
protected ImageView im;
protected String msg_path;
private Mat mMatriximg;
private Mat mMatriximgBW;
private int CV_64FC1;
//private Mat mMatriximgBW;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_layout);
im = (ImageView) findViewById(R.id.imV_ed);
Intent iIdentify = getIntent();
msg_path = iIdentify.getStringExtra("path");
//to grayscale
int im_gray = Highgui.CV_LOAD_IMAGE_GRAYSCALE;
mMatriximg = Highgui.imread(msg_path, im_gray);
// call library OpenCV
//Imgproc.equalizeHist(mMatriximg, mMatriximg);
Imgproc.Canny(mMatriximg, mMatriximg, 50, 150);
mMatriximgBW = Mat.zeros(mMatriximg.height(), mMatriximg.width(), CV_64FC1);
double y;
double threshold=190;
for(int i=0; i<mMatriximg.height(); i++){
for(int j=0; j<mMatriximg.width(); j++){
if(mMatriximg.get(i, j) [0]>=threshold){
y=255;
}else{
y=0;
}
mMatriximgBW.put(i, j, new double[] {y});
}
}
//result mat to Grayscale
Imgproc.cvtColor(mMatriximgBW, mMatriximgBW, Imgproc.COLOR_GRAY2RGBA, 4);
Bitmap bmpOut = Bitmap.createBitmap(mMatriximgBW.cols(), mMatriximgBW.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mMatriximgBW, bmpOut);
im.setImageBitmap(bmpOut);
}
public void bckHome(View v){
Intent iIden = new Intent(this, MBWDActivity.class);
setResult(RESULT_OK, iIden);
startActivityForResult(iIden, 99);
}
}
So I thought it would be more efficient if i cut out the center of the leaf as the sample data (matrix).
is there who can share on how to implement cvSetImageROI or other methods?
Thank you for any help
Upvotes: 1
Views: 1330
Reputation: 93410
I've covered this topic on this answer.
You need to create a Rect
with the dimensions of the ROI. Then, create a new Mat
and pass to its constructor the original image as 1st parameter, and the rectangle with the ROI as 2nd.
Upvotes: 1