gpt4 book ai didi

image-processing - 如何使用 JavaCV 识别另一个轮廓内的轮廓?

转载 作者:太空宇宙 更新时间:2023-11-03 20:49:35 25 4
gpt4 key购买 nike

如何识别另一个轮廓内的轮廓?我试图通过许多 OpenCV 教程,但我无法识别它。请高人能给出简单的代码解释一下吗?

这是我的输入文件

enter image description here

这个深色部分就是我需要识别的轮廓。

enter image description here

请与我分享您的经验。

最佳答案

对 JavaCV 不是很满意,下面是我如何在 OpenCV 和 C(古老的东西)中解决这个问题:

  1. 使用 cvFindContours()
  2. 查找图像中的所有轮廓
  3. 在这些轮廓上运行两个循环(迭代指针 h_next 或 JavaCV 中的任何内容)。对于外环中的每个轮廓,将其与基于 检测到的所有其他轮廓相匹配。 . .
  4. 计算每个轮廓的边界框。这将是一个 CvRect 结构。
  5. 将两个 CvRects 传递给计算两个矩形之间相交(重叠)面积的函数。
  6. 如果该面积等于两个矩形中较小矩形的面积,则较小矩形对应的轮廓完全被较大矩形包围。

    下面是查找相交区域的代码。它一定是在网络上的某个地方漂浮着。

    CvRect 相交(CvRect r1,CvRect r2)
    {
    CvRect 交集;

    // find overlapping region
    intersection.x = (r1.x < r2.x) ? r2.x : r1.x;
    intersection.y = (r1.y < r2.y) ? r2.y : r1.y;
    intersection.width = (r1.x + r1.width < r2.x + r2.width) ?
    r1.x + r1.width : r2.x + r2.width;
    intersection.width -= intersection.x;
    intersection.height = (r1.y + r1.height < r2.y + r2.height) ?
    r1.y + r1.height : r2.y + r2.height;
    intersection.height -= intersection.y;

    // check for non-overlapping regions
    if ((intersection.width <= 0) || (intersection.height <= 0)) {
    intersection = cvRect(0, 0, 0, 0);
    }

    return intersection;

关于image-processing - 如何使用 JavaCV 识别另一个轮廓内的轮廓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11454160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com