Skip to content

Commit f5ac845

Browse files
committed
add performance requirement
1 parent 3fd5641 commit f5ac845

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/prm_vision/opencv_armor_detector/src/OpenCVArmorDetector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ std::vector<cv::Point2f> OpenCVArmorDetector::detectArmorsInFrame(cv::Mat &frame
165165
cv::line(result, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 0, 255), 4, cv::LINE_AA);
166166
}
167167

168+
// Rect rotates, so we need to ensure height is always the longer side
168169
if (rect.angle > 45)
169170
{
170171
std::swap(rect.size.width, rect.size.height);

src/prm_vision/opencv_armor_detector/test/test_OpenCVArmorDetector.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ void testVideo(std::string video_path, std::string gt_path, OpenCVArmorDetector
1414
void testImgs(std::string folder_path, std::string gt_path, OpenCVArmorDetector *detector, float min_detection_rate, float max_loss_pix);
1515

1616
/* DETECTOR REQUIREMENTS */
17+
// Performance requirements
18+
#define MIN_FPS 144 // Minimum FPS required
19+
1720
// Pre-selected images (tighter requirements since we know an armor is present)
1821
#define MIN_DETECTION_RATE_EASY 0.95 // 95% detection rate required
1922
#define MIN_DETECTION_RATE_FAR_BACK 0.90 // 90% detection rate required
@@ -346,6 +349,9 @@ void testImgs(std::string folder_path, std::string gt_path, OpenCVArmorDetector
346349

347350
void testVideo(std::string video_path, std::string gt_path, OpenCVArmorDetector *detector, float min_detection_rate, float max_loss_pix)
348351
{
352+
// Start a stopwatch for performance testing
353+
auto start = std::chrono::high_resolution_clock::now();
354+
349355
// Read ground truths
350356
std::vector<std::vector<cv::Point2f>> gt;
351357
readGT(gt_path, gt);
@@ -391,13 +397,21 @@ void testVideo(std::string video_path, std::string gt_path, OpenCVArmorDetector
391397
frame_idx++;
392398
}
393399

400+
// Stop the stopwatch
401+
auto stop = std::chrono::high_resolution_clock::now();
402+
394403
// Calculate the average loss across all frames
395404
double loss = total_loss / detector->_frame_count;
396405

397406
// Check detection rate and loss
398407
double detection_rate = static_cast<double>(detector->_detected_frame) / static_cast<double>(detector->_frame_count);
399408
EXPECT_GE(detection_rate, min_detection_rate);
400409
EXPECT_LT(loss / detector->_frame_count, max_loss_pix);
410+
411+
// Check the FPS
412+
double elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count();
413+
double fps = static_cast<double>(detector->_frame_count) / (elapsed_time / 1000.0);
414+
EXPECT_GE(fps, MIN_FPS);
401415
}
402416

403417
void readGT(std::string file_path, std::vector<std::vector<cv::Point2f>> &gt)

0 commit comments

Comments
 (0)