Get all points inside a rectangle using opencv findcontour method
I want to find all points in the rectangle. But when i use findContour method in opencv, it actually finds points in the lines drawn ( Not points inside the rectangle). I verified using drawcontour method ( even if we use thickness as -1, it draws lines ).
How can i find points inside the smaller rectangle using findContour method ?
//srcMatrix create
Mat srcMat = new Mat();
srcMat.create(100, 100, CvType.8UC3);
// create a canny matrix
Mat mCanny = new Mat();
// Make it to sizeof srcMatrix and
// make channel to 1
mCanny.create( srcMat.cols(), srcMat.rows, CvType.8UC1)
// clear it
mCanny.setTo(new Scalar(0));
// draw a border rectangle on the mcanny
Core.rectangle(mCanny,
new Point(0,0),
new Point(100, 100),
new Scalar(255));
// draw a rectangle
Core.rectangle(mCanny,
new Point(25,25),
new Point(50, 50),
new Scalar(255));
// make it binary image
Imgproc.cvtColor(mCanny , mCanny , Imgproc.COLOR_RGB2GRAY);
// make it blur
Imgproc.blur( mCanny, mCanny, new Size(3,3));
//find canny
Imgproc.Canny(mCanny ,mCanny, 2,4);
/// find Contour
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(mCanny,
contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
I have a bitmap of whitecolor. I have drawn many criss cross lines. All lines are straight and will touch boundaries. These line caused whole plane to split into many regions. I want to detect in which mouse clicked ?
I was amazed to see findcountour method is not able to find some contours. Why is it so ? is there any good way ?