所以基本上我已经创建了自己的行人检测算法(我需要它用于一些研究目的,因此决定不使用提供的 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;
}
但是,如果这实际上是在计算机视觉中合并矩形的一种公认方法,我现在想做什么,尤其是当我想检查我的算法的精确召回率时。我的方法有时似乎过于简单,每个合并的矩形都变得越来越大,主要是因为合并 |= partitions[i][j]; 它找到包围两个矩形的最小矩形。
如果这是合并检测窗口的可接受方式,那么合并重叠的常用值是多少(即如果重叠面积 >= 百分比)?