I am trying to connect some straight lines to form a curved line.
for example if I had three lines like these
and I wanted to draw a curved line like this:
I have tried to use OpenCV line and polylines functions.
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));
}
}
}
but it doesn't work, because it connects lines that are far from each other. Also, is there a faster version of this I could try?