Android : draw a boundary box using opencv android

on Saturday, September 13, 2014


I develop an algorithm for extract the object from image with android java and opencv.


this is i have image


this is i need image and hope to extract the object.


here with my android code, and please help me to continue



ImageView imgView = (ImageView) findViewById(R.id.imageView1);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),myimage);


//First convert Bitmap to Mat
Mat ImageMat = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));
Bitmap myBitmap32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(myBitmap32, ImageMat);
//Converting RGB to Gray.
Imgproc.cvtColor(ImageMat, ImageMat, Imgproc.COLOR_RGB2GRAY,8);
//Reduce the lightness
Imgproc.threshold(ImageMat, ImageMat, 0, 255, Imgproc.THRESH_OTSU);
//Converting GaussianBlur
Imgproc.GaussianBlur(ImageMat, ImageMat, new Size(3,3),2);
//Edge Detction
Imgproc.Canny(ImageMat, ImageMat, 1200, 1600, 5, true);
//Dialation(morphology operation) increase the size of edge
//Imgproc.dilate(ImageMat, ImageMat, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3)));
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5,5));
Imgproc.morphologyEx(ImageMat, ImageMat, Imgproc.MORPH_CLOSE, kernel);

//Then convert the processed Mat to Bitmap
Bitmap resultBitmap = Bitmap.createBitmap(ImageMat.cols(), ImageMat.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(ImageMat, resultBitmap);
imgView.setImageBitmap(resultBitmap);

0 comments:

Post a Comment