Find rectangle from image in android?
hello,
i want to find four black cornered rectangle from below image
how to find those four border rectangle from this image?
i have tried with this code
Mat rgbMat=ImageUtils.bitmapToMat(resultBitmap);
Mat grayMat = new Mat(resultBitmap.getHeight(), resultBitmap.getWidth(),CvType.CV_8U, new Scalar(1));
Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 2);
Imgproc.threshold(grayMat, grayMat, 100, 255, Imgproc.THRESH_BINARY);
Core.bitwise_not(grayMat, grayMat);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(grayMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
List<Point> pointList=new ArrayList<Point>();
for(int i=0; i<contours.size(); i++)
{
Rect rect = Imgproc.boundingRect(contours.get(i));
double k = (rect.height+0.0)/rect.width;
if (0.9<k && k<1.1 && rect.area() > 100)
{
Imgproc.drawContours(rgbMat, contours, i, new Scalar(255, 0, 0), 3);
}
}
resultBitmap = ImageUtils.matToBitmap(rgbMat);
Please help me ..
Thanks in advance
can you try again with the image ?
hello berak i tried with above code but can't find all rectangle.please help me