请详细解释下这段代码Rect<float> FaceTracker::GetActiveBoundingRectangleOnActiveStream() const { std::vector<Rect<float>> faces = GetActiveFaceRectangles(); if (faces.empty()) { return Rect<float>(); } float min_x0 = 1.0f, min_y0 = 1.0f, max_x1 = 0.0f, max_y1 = 0.0f; for (const auto& f : faces) { min_x0 = std::min(f.left, min_x0); min_y0 = std::min(f.top, min_y0); max_x1 = std::max(f.right(), max_x1); max_y1 = std::max(f.bottom(), max_y1); } Rect<float> bounding_rect(min_x0, min_y0, max_x1 - min_x0, max_y1 - min_y0); VLOGF(2) << "Active bounding rect w.r.t active array: " << bounding_rect; // Transform the normalized rectangle in the active sensor array space to the // active stream space. const float active_array_aspect_ratio = static_cast<float>(options_.active_array_dimension.width) / static_cast<float>(options_.active_array_dimension.height); const float active_stream_aspect_ratio = static_cast<float>(options_.active_stream_dimension.width) / static_cast<float>(options_.active_stream_dimension.height); if (active_array_aspect_ratio < active_stream_aspect_ratio) { // The active stream is cropped into letterbox with smaller height than the // active sensor array. Adjust the y coordinates accordingly. const float height_ratio = active_array_aspect_ratio / active_stream_aspect_ratio; bounding_rect.height = std::min(bounding_rect.height / height_ratio, 1.0f); const float y_offset = (1.0f - height_ratio) / 2; bounding_rect.top = std::max(bounding_rect.top - y_offset, 0.0f) / height_ratio; } else { // The active stream is cropped into pillarbox with smaller width than the // active sensor array. Adjust the x coordinates accordingly. const float width_ratio = active_stream_aspect_ratio / active_array_aspect_ratio; bounding_rect.width = std::min(bounding_rect.width / width_ratio, 1.0f); const float x_offset = (1.0f - width_ratio) / 2; bounding_rect.left = std::max(bounding_rect.left - x_offset, 0.0f) / width_ratio; } VLOGF(2) << "Active bounding rect w.r.t active stream: " << bounding_rect; return bounding_rect; }
时间: 2024-04-22 20:22:58 浏览: 135
Rect函数的傅里叶变换:Rect函数的傅里叶变换-matlab开发
5星 · 资源好评率100%
这段代码是一个类 FaceTracker 的成员函数 GetActiveBoundingRectangleOnActiveStream() 的实现。
该函数的作用是获取当前活动视频流中人脸的包围矩形,也就是所有人脸的最小矩形,返回一个 Rect<float> 类型的对象。
该函数的实现过程如下:
首先,调用 GetActiveFaceRectangles() 函数获取当前活动视频流中的所有人脸矩形,存储在 faces 变量中。
接着,判断 faces 是否为空,如果为空,则返回一个空的矩形(Rect<float>())。
如果 faces 不为空,则遍历 faces,计算所有人脸矩形的包围矩形,即最小的矩形,存储在 bounding_rect 变量中。
然后,根据 active_array_aspect_ratio 和 active_stream_aspect_ratio 计算出活动视频流的宽高比,判断活动视频流是被剪裁成了横向黑边或纵向黑边,进而计算出坐标的偏移量和缩放比例,将 bounding_rect 从活动传感器阵列空间转换为活动流空间,存储在 bounding_rect 变量中。
最后,返回 bounding_rect 变量。
函数中的 VLOGF(2) << ... 是一个日志输出语句,用于在输出日志时打印调试信息,2 表示日志输出级别为 verbose。
阅读全文