c++ - 如何使用opencv框架将点[4]添加到轮廓

标签 c++ opencv

我目前正在使用 opencv framework(3.4.1) 进行对象测量,但我无法将 points[4] 添加到轮廓中。请告诉我如何将 points[4] 添加到下面代码中的 boxContours

我可以将 boxContours 传递给 drawContours 只有当我向前者添加点时。

cv::findContours( gray, contours, hierarchy, CV_RETR_EXTERNAL, 
CV_CHAIN_APPROX_SIMPLE);
NSLog(@"contour size %lu",contours.size());
for (int i = 0; i< contours.size(); i++)
{
    cv::RotatedRect rect = cv::minAreaRect(contours[i]);
    cv::Point2f points[4];
    rect.points(points);

    std::vector<std::vector<cv::Point2f>> boxContours;

    cv::drawContours(image, boxContours, i,cvScalar(0,255,0),2);   
}

最佳答案

请参阅此代码以绘制旋转矩形!您可以轻松地绘制线条!

Mat image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);
Point2f vertices[4];
rRect.points(vertices);

for (int i = 0; i < 4; i++)
    line(image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0));

imshow("rectangles", image);
waitKey(0);

enter image description here

关于c++ - 如何使用opencv框架将点[4]添加到轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49421505/

相关文章:

opencv - 针对 ARM 优化的 FAST 计算

c++ - VSCode 中的 Cpp - 如何编译到其他文件夹

c++ - 条件内的指针语法

c++ - 将 int 的单个数字存储在数组中

c++ - OpenCV 和 RTMP 流

python - 如何锐化opencv python中的边缘

numpy - 重建基于numpy数组的图像

android - OpenCV-Android highgui链接错误

c++ - 为用户定义的类正确调用复制构造函数/赋值运算符

c++ - 将 boost::asio::ip::address_v4 隐藏为字符串