How to get 4 image points(extreme points along diagonal) from circular contour?

asked 2019-03-14 10:13:46 -0500

opencvr gravatar image

updated 2019-03-15 05:14:52 -0500

Hello,

I am detecting contour of circular object like this. code snippet,

`vector<vector<Point> > contours;

        vector<Vec4i> hierarchy;

    findContours(src_gray, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0, 0));          

    //Draw contours

    Mat drawing = Mat::zeros(src_gray.size(), CV_8UC3);
    vector<Point> approx;
    for (int i = 0; i < contours.size(); i++) 
    {

        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        //drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());//draw all contours

        cv::approxPolyDP(cv::Mat(contours[i]), approx, cv::arcLength(cv::Mat(contours[i]), true) *0.02, true);
        if (approx.size() >= 8) //More than 6-8 vertices means its likely a circle
        {

               drawContours(drawing, contours, i, Scalar(0, 255, 0), 1, 8);
        }   
    }
    imshow("OUTPUT1", drawing);`

I am extracting only circular contour from all contour.

But how can I use this circular contour to define 4 extreme points (along 2 diagonals//4 end points) ?

so, I can use this points as image points as vector in SolvePnp algorithm.

Thanks.

edit retag flag offensive close merge delete

Comments

Can you post an image for better understanding?

Grillteller gravatar imageGrillteller ( 2019-03-19 07:33:41 -0500 )edit