OpenCV groupRectangles - 获取分组和未分组的矩形

OpenCV groupRectangles - getting grouped and ungrouped rectangles(OpenCV groupRectangles - 获取分组和未分组的矩形)
本文介绍了OpenCV groupRectangles - 获取分组和未分组的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 OpenCV 并希望将具有显着重叠的矩形组合在一起.为此,我尝试使用 groupRectangles,它采用组阈值参数.阈值为 0 时它根本不进行任何分组,阈值为 1 时仅返回由至少 2 个矩形组成的矩形.例如,给定下图中左侧的矩形,您最终会得到右侧的 2 个矩形:

I'm using OpenCV and want to group together rectangles that have significant overlap. I've tried using groupRectangles for this, which takes a group threshold argument. With a threshold of 0 it doesn't do any grouping at all, and with a threshold of 1 is only returns rectangles that were the result of at least 2 rectangles. For example, given the rectangles on the left in the image below you end up with the 2 rectangles on the right:

我最终想要的是 3 个矩形.上图中右侧的 2,加上左侧图像右上角的矩形,该矩形不与任何其他矩形重叠.实现这一目标的最佳方法是什么?

What I'd like to end up with is 3 rectangles. The 2 on the right in the image above, plus the rectangle in the top right of the image to the left that doesn't overlap with any other rectangles. What's the best way to achieve this?

推荐答案

我最终采用的解决方案是在调用 groupRectangles 之前复制所有初始矩形.这样每个输入矩形都保证至少与另一个矩形组合在一起,并且会出现在输出中:

The solution I ended up going with was to duplicate all of the initial rectangles before calling groupRectangles. That way every input rectangle is guaranteed to be grouped with at least one other rectangle, and will appear in the output:

int size = rects.size();
for( int i = 0; i < size; i++ )
{
    rects.push_back(Rect(rects[i]));
}
groupRectangles(rects, 1, 0.2);

这篇关于OpenCV groupRectangles - 获取分组和未分组的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Bring window to front -gt; raise(),show(),activateWindow() don’t work(把窗户放在前面 -raise(),show(),activateWindow() 不起作用)
How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)(如何使用 Qt(跨平台)获取列表视频捕获设备名称(网络摄像机)?(C++))
How to compile Qt as static(如何将 Qt 编译为静态)
C++ over Qt : Controlling transparency of Labels and Buttons(C++ over Qt:控制标签和按钮的透明度)
How to know when a new USB storage device is connected in Qt?(Qt如何知道新的USB存储设备何时连接?)
What is an event loop in Qt?(Qt 中的事件循环是什么?)