I am new to OpenCv and trying to learn by implementing. I need to draw the contours i have detected in new Mat so I can work with them.
This is my Original image
After doing some work I achieved this by finding and drawing contours
Here's my code
m = Utils.loadResource(MainActivity.this, R.drawable.sheet1, Highgui.CV_LOAD_IMAGE_COLOR);
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Imgproc.cvtColor(m, m, Imgproc.COLOR_BGR2GRAY);
Imgproc.medianBlur(m, m, 3);
Imgproc.threshold(m, m, 0, 255, Imgproc.THRESH_OTSU);
Core.bitwise_not(m, m);
Imgproc.dilate(m, m, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,118)));
//Contours detection
java.util.List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(m, contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
Imgproc.cvtColor(m, m, Imgproc.COLOR_GRAY2BGR);
//Contour drawing
Mat matArray = new Mat();
Imgproc.drawContours(m, contours, -1, new Scalar(153,255,204), 3);
Utils.matToBitmap(m, bm);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
Now, I want to save every MCQ in new Mat.How can this be implemented in android Java?
0 comments:
Post a Comment