opencv在图像上根据顶点绘制直线

知道图像中的四个顶点,绘制四个顶点构成的四边形。如果想绘制图像上原有的点,添加drawContours()函数。

        Mat imageContoursnew = Mat::zeros(edge.size(), CV_8UC1);
        //drawContours(imageContoursnew, aglcontours, 0, Scalar(255), 1, 8);//aglcontours中存放实际的点的坐标,定义为                                                                                                                                                           vector<vector<Point>> aglcontours;
        Point2f aglPnew[4];//四个顶点的坐标
        aglPnew[0] = Point2f(minmaxnew[0], minmaxnew[3]);
        aglPnew[1] = Point2f(minmaxnew[0], minmaxnew[2]);
        aglPnew[2] = Point2f(minmaxnew[1], minmaxnew[2]);
        aglPnew[3] = Point2f(minmaxnew[1], minmaxnew[3]);

        for (int j = 0; j <= 3; j++)
        {
            line(imageContoursnew, aglPnew[j], aglPnew[(j + 1) % 4], Scalar(255), 2);
        }
        imshow("imageContoursnew", imageContoursnew);
        waitKey(0);

猜你喜欢

转载自blog.csdn.net/u013925378/article/details/83856308