Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Merge contour from vector<points>

I would like to form an external contour from different vector points. The individual contours are continuous and contain curved lines (1 pixel wide). The merged contour should connect the lines like as marked in red in the image below

image description => image description

I would transfer the single points into a total vector. How can i determine the order I have to follow? I suppose every single contour must be ordered clockwise?

std::vector<cv::point> contourMerged; for (int cn = 0; cn < cntContours; cn++) { vector<double> xTmp = xPts[cn]; vector<double> yTmp = yPts[cn];

    for (int pn = 0; pn < xTmp.size(); pn++)
    {
        cv::Point tmp;
        int xt = (int)xTmp[pn];
        int yt = (int)yTmp[pn];
        tmp.x = xt;
        tmp.y = yt;

        contourMerged.push_back(tmp);
    }

}
// close contour
contourMerged.push_back(contourMerged[0]);

Thank you!

click to hide/show revision 2
None

updated 2020-06-26 09:55:09 -0500

berak gravatar image

Merge contour from vector<points>

I would like to form an external contour from different vector points. The individual contours are continuous and contain curved lines (1 pixel wide). The merged contour should connect the lines like as marked in red in the image below

image description => image description

I would transfer the single points into a total vector. How can i determine the order I have to follow? I suppose every single contour must be ordered clockwise?

std::vector<cv::point>

std::vector<cv::Point> contourMerged;
 for (int cn = 0; cn < cntContours; cn++)
 {
     vector<double> xTmp =  xPts[cn];
     vector<double> yTmp =  yPts[cn];

yPts[cn];

    for (int pn = 0; pn < xTmp.size(); pn++)
    {
        cv::Point tmp;
        int xt = (int)xTmp[pn];
        int yt = (int)yTmp[pn];
        tmp.x = xt;
        tmp.y = yt;

        contourMerged.push_back(tmp);
    }

}
// close contour
contourMerged.push_back(contourMerged[0]);

Thank you!

Merge contour from vector<points>

I would like to form an external contour from different vector points. The individual contours are continuous and contain curved lines (1 pixel wide). The merged contour should connect the lines like as marked in red in the image below

image description => image description

I would transfer the single points into a total vector. How can i determine the order I have to follow? I suppose every single contour must be ordered clockwise?

//xPts = vector<vector<int>> containing all x-Values of contour

int cntContours = xPts.size();
std::vector<cv::Point> contourMerged;
for (int cn = 0; cn < cntContours; cn++)
{
    vector<double> xTmp =  xPts[cn];
    vector<double> yTmp =  yPts[cn];

    for (int pn = 0; pn < xTmp.size(); pn++)
    {
        cv::Point tmp;
        int xt = (int)xTmp[pn];
        int yt = (int)yTmp[pn];
        tmp.x = xt;
        tmp.y = yt;

        contourMerged.push_back(tmp);
    }

}
// close contour
contourMerged.push_back(contourMerged[0]);

Thank you!