所以基本上我已经创建了自己的行人检测算法(出于某些研究目的我需要它,因此决定不使用提供的 HoG 检测器)。
检测后,我会在检测到的物体/人周围有许多重叠的矩形。然后我会应用非最大值抑制来保留局部最大值。但是在非极大值抑制算法的搜索范围之外的位置仍然存在重叠的矩形。
您将如何合并矩形?我尝试使用 grouprectangles,但不知何故我不知道它是如何得出结果的(例如 grouprectangles( rects, 1.0, 0.2 ) )
我应用了一个基本的合并算法,如果有矩形重叠一定比例的区域,我会合并,代码如下所示。
/**
* Merge a set of rectangles if there's an overlap between each rectangle for more than
* specified overlap area
* @param boxes a set of rectangles to be merged
* @param overlap the minimum area of overlap before 2 rectangles are merged
* @param group_threshold only the rectangles that have more than the remaining group_threshold rectangles will be retained
* @return a set of merged rectangles
**/
vector<Rect> Util::mergeRectangles( const vector<Rect>& boxes, float overlap, int group_threshold ) {
vector<Rect> output;
vector<Rect> intersected;
vector< vector<Rect> > partitions;
vector<Rect> rects( boxes.begin(), boxes.end() );
while( rects.size() > 0 ) {
Rect a = rects[rects.size() - 1];
int a_area = a.area();
rects.pop_back();
if( partitions.empty() ) {
vector<Rect> vec;
vec.push_back( a );
partitions.push_back( vec );
}
else {
bool merge = false;
for( int i = 0; i < partitions.size(); i++ ){
for( int j = 0; j < partitions[i].size(); j++ ) {
Rect b = partitions[i][j];
int b_area = b.area();
Rect intersect = a & b;
int intersect_area = intersect.area();
if (( a_area == b_area ) && ( intersect_area >= overlap * a_area ))
merge = true;
else if (( a_area < b_area ) && ( intersect_area >= overlap * a_area ) )
merge = true;
else if (( b_area < a_area ) && ( intersect_area >= overlap * b_area ) )
merge = true;
if( merge )
break;
}
if( merge ) {
partitions[i].push_back( a );
break;
}
}
if( !merge ) {
vector<Rect> vec;
vec.push_back( a );
partitions.push_back( vec );
}
}
}
for( int i = 0; i < partitions.size(); i++ ) {
if( partitions[i].size() <= group_threshold )
continue;
Rect merged = partitions[i][0];
for( int j = 1; j < partitions[i].size(); j++ ) {
merged |= partitions[i][j];
}
output.push_back( merged );
}
return output;
}
但是,如果这实际上是一种在计算机视觉中合并矩形的可接受方式,我现在想要的是什么,尤其是当我想检查我的算法的精确召回率时。我的方法有时似乎过于简单,每个合并的矩形都变得越来越大,主要是因为 merged |= partitions[i][j]; 找到了包含两个矩形的最小矩形。
如果这是合并检测窗口的可接受方式,合并重叠的通用值是多少(即如果重叠面积 >= 多少百分比)?
最佳答案
我敢说没有“公认”的方式来合并某些感兴趣的领域。甚至合并点的百分比也完全取决于您要执行的操作。
您可以尝试使用某种权重/投票机制,根据原始检测到的方 block 的大小,为某些观察结果赋予更大的权重(也可以使用其他东西,因为与其他东西的重叠量或重叠数)。
您还可以将找到的方 block 合并到某种掩码中。这将创建一个图像,其中所有方 block 都是白色像素,其他所有内容都是黑色。通过在原始图像上使用该蒙版,您应该有一组非常精确的“合并”感兴趣区域,它们与您找到的正方形一样大。
关于opencv - 在 OpenCV/计算机视觉中合并检测窗口的常用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16206370/