Home > front end >  Is there a flood fill outlining algorithm for constructing a polygon?
Is there a flood fill outlining algorithm for constructing a polygon?

Time:08-01

Is there a flood fill like method of generating an outline around the object? I'm trying to detect an object in an image and outline it. I'm currently successful with highlighting it but don't know how to outline. I'm using QT C and would like to construct a QPolygon of the points at the edges. My code so far:

 while(!stack.empty())
{
    auto curr = stack.pop();
    const auto x = curr.first.x(), y= curr.first.y();
    if(x>=maxX || y>=maxY || x<minX || y<minY || memo[x y*img.width()])
    {
        continue;
    }
    auto currColor = orig[x y*img.width()];
    auto diff = colorDifference(currColor, curr.second);
    if(diff < 40)
    {
        memo[x y*img.width()] = true;
        stack.push(make_pair(QPoint(x-1,y),currColor));
        stack.push(make_pair(QPoint(x 1,y),currColor));
        stack.push(make_pair(QPoint(x,y-1),currColor));
        stack.push(make_pair(QPoint(x,y 1),currColor));
        changed[x y*img.width()] = filler; //highlight pixel, need to be replaced with outlining
    }
}

CodePudding user response:

You can use OpenCV API, cv::findContours().(It's based on Satoshi et al., 1985)

Call cv::findContours() on the image you labeled. It returns points of all contours(outlines).(Be careful to filter out trivial contours in the tree of contours such as a root node.)

See the official tutorial, Contours Hierarchy.

  • Related