cv::Rect largest_rect;
bool found_largest = false;
double max_area = 0.0;
std::string det_name;
for (auto it = dets.begin(); it != dets.end(); ++it) {
const Detect& det = it->second;
double area = det.rect.width * det.rect.height;
// 如果找到更大的框,更新最大框
if (area > max_area) {
max_area = area;
largest_rect = det.rect;
found_largest = true;
det_name=it->first;
}
}
合并成一个最大检测框
// 初始化最小和最大坐标
int min_x = INT_MAX;
int min_y = INT_MAX;
int max_x = INT_MIN;
int max_y = INT_MIN;
// 遍历所有的检测框,找到最小和最大坐标
for (const auto& it : dets) {
const Detect& det = it.second;
min_x = std::min(min_x, det.rect.x);
min_y = std::min(min_y, det.rect.y);
max_x = std::max(max_x, det.rect.x + det.rect.width);
max_y = std::max(max_y, det.rect.y + det.rect.height);
}
// 创建合并后的矩形框
cv::Rect largest_rect(min_x, min_y, max_x - min_x, max_y - min_y);