gpt4 book ai didi

c++ - 两个 bb 之间的重叠分数

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:08 26 4
gpt4 key购买 nike

我正在尝试创建一个函数来计算两个边界框之间的交集比。我有关于两个矩形的 Rect 信息。我创建了一个交集函数,它返回两个框之间的双倍交集分数:

double Detection::overlapBB(Rect a, Rect b){

int xa1 = a.x; int xa2 = a.x + a.width;
int ya1 = a.y; int ya2 = a.y + a.height;
int xb1 = b.x; int xb2 = b.x + b.width;
int yb1 = b.y; int yb2 = b.y + b.height;

cout << "The first rectangle:("<< xa1 << "," <<ya1 <<"),(" <<xa2<<"," <<ya2 <<")" <<endl;
cout << "The second rectangle:("<< xb1 << "," <<yb1 <<"),(" <<xb2<<"," <<yb2 <<")" <<endl;


int surfaceA = a.width*a.height;
int surfaceB = b.width*b.height;

int xn1 = Max(xa1, xb1); int yn1 = Max(ya1, yb1);
int xn2 = Min(xa2, xb2); int yn2 = Min(ya2, yb2);

cout << "The second rectangle:("<< xn1 << "," <<yn1 <<"),(" <<xn2<<"," <<yn2 <<")" <<endl;

//int SI = (xn2 - xn1)*(yn2-yn1);
int SI = Max(0, Max(xa2, xb2) - Min(xa1, xb1)) * Max(0, Max(ya2, yb2) - Min(ya1, yb1));
int SU = surfaceA +surfaceB - SI;

cout << SI << " " <<SU << " " <<surfaceA<< " " <<surfaceB << endl;

double intersection = ((double)SI/(double)SU);


return intersection;

}

我注意到,当一个矩形在另一个矩形内时,返回的变量不正确。我可以为完全重叠和部分重叠的情况创建语句吗?

最佳答案

Fere Res 检查此范式 intersection detection .

关于c++ - 两个 bb 之间的重叠分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375611/

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