diff --git a/src/caffe/util/bbox_util.cpp b/src/caffe/util/bbox_util.cpp index e3b88bd1..82159df3 100644 --- a/src/caffe/util/bbox_util.cpp +++ b/src/caffe/util/bbox_util.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -1122,6 +1123,8 @@ vector GetColors(const int n) { return colors; } +static clock_t start_clock = clock(); + template void VisualizeBBox(const vector& images, const Blob* detections, const float threshold, const vector& colors, @@ -1133,6 +1136,10 @@ void VisualizeBBox(const vector& images, const Blob* detections, if (num_det == 0 || num_img == 0) { return; } + // Comute FPS. + float fps = num_img / (double(clock() - start_clock) / CLOCKS_PER_SEC); + start_clock = clock(); + const Dtype* detections_data = detections->cpu_data(); const int width = images[0].cols; const int height = images[0].rows; @@ -1154,8 +1161,23 @@ void VisualizeBBox(const vector& images, const Blob* detections, all_detections[img_idx][label].push_back(bbox); } + int fontface = cv::FONT_HERSHEY_SIMPLEX; + double scale = 1; + int thickness = 2; + int baseline = 0; + char buffer[50]; for (int i = 0; i < num_img; ++i) { cv::Mat image = images[i]; + // Show FPS. + snprintf(buffer, sizeof(buffer), "FPS: %.2f", fps); + cv::Size text = cv::getTextSize(buffer, fontface, scale, thickness, + &baseline); + cv::rectangle(image, cv::Point(0, 0), + cv::Point(text.width, text.height + baseline), + CV_RGB(255, 255, 255), CV_FILLED); + cv::putText(image, buffer, cv::Point(0, text.height + baseline / 2.), + fontface, scale, CV_RGB(0, 0, 0), thickness, 8); + // Draw bboxes. for (map >::iterator it = all_detections[i].begin(); it != all_detections[i].end(); ++it) { int label = it->first; @@ -1171,11 +1193,6 @@ void VisualizeBBox(const vector& images, const Blob* detections, cv::Point bottom_right_pt(bboxes[j].xmax(), bboxes[j].ymax()); cv::rectangle(image, top_left_pt, bottom_right_pt, color, 4); cv::Point bottom_left_pt(bboxes[j].xmin(), bboxes[j].ymax()); - int fontface = cv::FONT_HERSHEY_SIMPLEX; - double scale = 1; - int thickness = 2; - int baseline = 0; - char buffer[50]; snprintf(buffer, sizeof(buffer), "%s: %.2f", label_name.c_str(), bboxes[j].score()); cv::Size text = cv::getTextSize(buffer, fontface, scale, thickness,