Android + OpenCV - Finding extreme points in contours

时间:2023-11-22 10:38:44

原文链接http://answers.opencv.org/question/134783/android-opencv-finding-extreme-points-in-contours/

导    读本例子使用轮廓分析,寻找到轮廓的极点;使用了STD的SORT特性。

提出问题

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.

Android + OpenCV - Finding extreme points in contours

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

Android + OpenCV - Finding extreme points in contours.

And here is my code, what I have now.

   contours .);

Imgproc.threshold(mFGMask, mFGMask, , , Imgproc.THRESH_BINARY);
   Imgproc.erode(mFGMask, mFGMask, , , , ), );

/*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 !

 优质解答:  
bool);
    ;
    }
    cvtColor(mSrc,mDst,COLOR_GRAY2BGR);
    , ) );
    vector; i,,), );
        ptsContour],,Scalar(,,),);
    }
    imshow( source_window, mDst );
    waitKey();
    ;
}

Android + OpenCV - Finding extreme points in contours

Android + OpenCV - Finding extreme points in contours

 程序解读本程序的基本思路是很简答的,就是遍历轮廓,找到轮廓中x和y最大的点,这个点就是极值点。但是有两个地方需要注意:
1、是使用了std的sort特性,应该说简化了程序设计;
2、是findcontours的第二个参数,使用的是“只寻找第一层轮廓”。那么对于本例来说,这样做是合理的。