opencv c ++查找轮廓的内切圆

编程入门 行业动态 更新时间:2024-10-24 12:33:28
本文介绍了opencv c ++查找轮廓的内切圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想找到轮廓的最大内切圆.

我用cv::findContours检测到轮廓,并以vector<Point>的形式存在.

I have detected the contour with cv::findContours and it is there as a vector<Point>.

我知道如何检测最小封闭圆(cv::minEnclosingCircle),但不知道如何获取最大封闭圆.该怎么做?

I know how to detect the minimum enclosing circle (cv::minEnclosingCircle), but not how to get the maximum inclosing circle. How to do this?

问题2:如何使刻划和外接圆以质心为中心?

Question2: How do i get the inscribing and circumscribing circles centered on the center of mass?

为澄清起见,我尝试描述这些圆圈的含义:

For clarification, i try to describe, what i mean with these circels:

  • 最小包围圈:从外部触摸物体,中心位置无所谓,最小面积.
  • 外接圆:从外部触摸对象,中心位置位于对象的质心上,最小面积.
  • 最大闭合圆:从内部触摸物体,中心位置无所谓,最大面积.
  • 内切圆:从内部触摸对象,对象的质心的中心位置,最大面积.
  • min enclosing circle: touching object from outside, center position doesn't matter, minimum area.
  • circumscribing circle: touching object from outside, center position on the center of mass of the object, minimum area.
  • max inclosing circle: touching object from inside, center position doesn't matter, maximum area.
  • inscribing circle: touching object from inside, center position on the center of mass of the object, maximum area.
  • 推荐答案

    您可以:

    1)从轮廓创建蒙版

    2)计算蒙版上的distanceTransform

    3)最大值是半径,位置是中心

    3) The highest value is the radius, its position is the center

    代码:

    #include <opencv2\opencv.hpp> int main() { // Load image cv::Mat1b img = cv::imread("path_to_img", cv::IMREAD_GRAYSCALE); // Correct image cv::Mat1b bin = img < 127; // Find contour std::vector<std::vector<cv::Point>> contours; cv::findContours(bin, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); // Draw on mask cv::Mat1b mask(bin.rows, bin.cols, uchar(0)); cv::drawContours(mask, contours, 0, cv::Scalar(255), cv::FILLED); // Distance Trasnsform cv::Mat1f dt; cv::distanceTransform(mask, dt, cv::DIST_L2, 5, cv::DIST_LABEL_PIXEL); // Find max value double max_val; cv::Point max_loc; cv::minMaxLoc(dt, nullptr, &max_val, nullptr, &max_loc); // Output image cv::Mat3b out; cv::cvtColor(img, out, cv::COLOR_GRAY2BGR); cv::circle(out, max_loc, max_val, cv::Scalar(0, 255, 0)); return 0; }

    更多推荐

    opencv c ++查找轮廓的内切圆

    本文发布于:2023-05-26 20:21:04,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/265243.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:内切圆   轮廓   opencv

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!