Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply the OpenCV-function polylines() to lists in C++

I have a result like this std::list<std::list<cv::Point2i>> and I would like to visualize the result using polylines() and imshow(). Is there a way to realize this without having to copy the list elements to vectors?

like image 609
jkl Avatar asked Nov 18 '25 21:11

jkl


1 Answers

Unfortunately, the answer is no. cv::polylines accepts only continuously stored data. So it can't process points stored in std::list.

If you don't want to store your points in std::vector you may implement polylines for std::list.

For example:

void polylines(cv::Mat& img, const std::list<std::list<cv::Point2i>>& polylines)
{
    for (auto& polyline : polylines)
    {
        auto current = polyline.begin();
        auto next = std::next(current, 1);
        for (; next != polyline.end(); current++, next++)
        {
            cv::line(img, *current, *next, cv::Scalar(255));
        }
    }
}

Then you can call cv::imshow for drawing.

like image 188
akarsakov Avatar answered Nov 21 '25 15:11

akarsakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!