c++ - 如何从多条直线画一条曲线?

标签 c++ opencv line

我正在尝试连接一些直线以形成一条曲线。

例如,如果我有这样的三行

enter image description here :

我想画一条这样的曲线:

enter image description here

我已经尝试使用 OpenCV linepolylines 函数。

    for (size_t i = 0;i < lines.size();i++)
    {
        for (size_t j = 0;j < lines.size();j++)
        {
            //first line
            Vec4i l1 = lines[i];
            Point p1 = Point(l1[0], l1[1]);
            Point p2 = Point(l1[2], l1[3]);

            //second line
            Vec4i l2 = lines[j];
            Point p3 = Point(l2[0], l2[1]);
            Point p4 = Point(l2[2], l2[3]);

            if ((cv::norm(p1 - p3) < 20) || (cv::norm(p1 - p4) < 20) || (cv::norm(p2 - p3) < 20) || (cv::norm(p2 - p4) < 20))
            {
                vector<Point> pointList;
                pointList.push_back(p1);
                pointList.push_back(p2);
                pointList.push_back(p3);
                pointList.push_back(p4);

                const Point *pts = (const cv::Point*) Mat(pointList).data;
                int npts = Mat(pointList).rows;

                polylines(img, &pts, &npts, 1, true, Scalar(255, 0, 0));

            }
        }
    }

但它不起作用,因为它连接了彼此相距很远的线。 另外,有没有我可以尝试的更快版本?

最佳答案

贝塞尔曲线可能会有所帮助 ( https://en.wikipedia.org/wiki/B%C3%A9zier_curve )。

关于c++ - 如何从多条直线画一条曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57329005/

相关文章:

Bash:在文件中弹出行

c++ - 在类定义中使用结构的细节和好处

c++ - 在复制构造函数中使用 memcpy 复制 QThread 指针

c++ - 使用STL从字符串中删除重复字符

c++ - opencv tesseract undefined reference错误

c++ - 在 C++ 编译器上安装 OpenCV

opencv - 模拟各向同性线性扩散平滑

c++ - 使用opencv4将鱼眼图像转换为等距柱状图像

flutter - 改变 X 轴折线图 flutter

html - 防止div中的换行