Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android + OpenCV - Finding extreme points in contours

Good Evening,

I have a trouble with finding extreme points in frames. I am detecting all contours, but I want find there one extreme point, which is lowest from others (southernmost contour). Here is a preview of screen, what I have.

image description

And here is a preview of screen, what I want ! For example, lowest point will bounded by red rectangle.

image description.

And here is my code, what I have now.

   contours = new ArrayList<MatOfPoint>();
   Rect rect;
   Point c1 = new Point(); Point c2 = new Point();

   Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY);
   subtractorMOG2.apply(mGray, mFGMask, 0.005);

   Imgproc.threshold(mFGMask, mFGMask, 45, 255, Imgproc.THRESH_BINARY);
   Imgproc.erode(mFGMask, mFGMask, new Mat());
   Imgproc.dilate(mFGMask, mFGMask, new Mat());

   Imgproc.findContours(mFGMask, contours, new Mat(), Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_NONE);
   Imgproc.drawContours(mRgba, contours, -1, new Scalar(255, 255, 0), 3);

        /*for (int idx = 0; idx < contours.size(); idx++) {

            double contourarea = Imgproc.contourArea(contours.get(idx));
            rect = boundingRect(contours.get(idx));

            c1.x = rect.x; c1.y = rect.y;
            c2.x = rect.x + rect.width; c2.y = rect.y + rect.height;
            if (contourarea > 1024 && contourarea < 30000) {
                Imgproc.rectangle(mRgba, c1, c2, new Scalar(255, 0, 0), 3);
            }
        }*/

  return mRgba;

Thanks everybody for help and comments !

Android + OpenCV - Finding extreme points in contours

Good Evening,

I have a trouble with finding extreme points in frames. I am detecting all contours, but I want find there one extreme point, which is lowest from others (southernmost contour). Here is a preview of screen, what I have.

image description

And here is a preview of screen, what I want ! For example, lowest point will bounded by red rectangle.

image description.

And here is my code, what I have now.

   contours = new ArrayList<MatOfPoint>();
   Rect rect;
   Point c1 = new Point(); Point c2 = new Point();

   Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY);
   subtractorMOG2.apply(mGray, mFGMask, 0.005);

   Imgproc.threshold(mFGMask, mFGMask, 45, 255, Imgproc.THRESH_BINARY);
   Imgproc.erode(mFGMask, mFGMask, new Mat());
   Imgproc.dilate(mFGMask, mFGMask, new Mat());

   Imgproc.findContours(mFGMask, contours, new Mat(), Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_NONE);
   Imgproc.drawContours(mRgba, contours, -1, new Scalar(255, 255, 0), 3);

        /*for (int idx = 0; idx < contours.size(); idx++) {

            double contourarea = Imgproc.contourArea(contours.get(idx));
            rect = boundingRect(contours.get(idx));

            c1.x = rect.x; c1.y = rect.y;
            c2.x = rect.x + rect.width; c2.y = rect.y + rect.height;
            if (contourarea > 1024 && contourarea < 30000) {
                Imgproc.rectangle(mRgba, c1, c2, new Scalar(255, 0, 0), 3);
            }
        }*/

  return mRgba;

Thanks everybody for help and comments !