Skip to content

Commit 26f4adb

Browse files
committed
Now using PITRAC_ROOT to determine the absolute paths to the YOLO data. Downgraded a few info logging statements to be trace instead (trying to keep the info statements to things that an end user would be more likely interested in). Removed some overly-chatty logging from pulse-strobe identification. Added timing logging around the YOLO processing.
1 parent 8003f8a commit 26f4adb

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

Software/LMSourceCode/ImageProcessing/ball_image_proc.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ namespace golf_sim {
204204
// TODO: Fix defaults or remove these entirely
205205
std::string BallImageProc::kDetectionMethod = "legacy";
206206
std::string BallImageProc::kBallPlacementDetectionMethod = "legacy";
207-
// Default ONNX model path - can be overridden by config file
207+
// Default ONNX model path - can be overridden by config file or (more likely) the PITRAC_ROOT environment variable
208208
#ifdef _WIN32
209209
std::string BallImageProc::kONNXModelPath = "../../Software/GroundTruthAnnotator/experiments/high_performance_300e2/weights/best.onnx";
210210
#else
@@ -366,10 +366,27 @@ namespace golf_sim {
366366
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kPlacedNarrowingStartingParam2", kPlacedNarrowingStartingParam2);
367367
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kPlacedNarrowingRadiiDpParam", kPlacedNarrowingRadiiDpParam);
368368

369+
// ONNX Detection Configuration
370+
371+
369372
// ONNX Detection Configuration
370373
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kDetectionMethod", kDetectionMethod);
371-
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kBallPlacementDetectionMethod", kBallPlacementDetectionMethod);
372374
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kONNXModelPath", kONNXModelPath);
375+
376+
// Get the ONNX path from the .json file and then use the PITRAC_ROOT environment variable to help compute the absolute path
377+
// We expect that environment variable to be set in both the Pi and Windows environments
378+
std::string root_path = GolfSimConfiguration::GetPiTracRootPath();
379+
if (root_path.empty()) {
380+
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kONNXModelPath", kONNXModelPath);
381+
}
382+
else {
383+
kONNXModelPath = root_path + "/" + kONNXModelPath;
384+
GS_LOG_MSG(info, "Using PITRAC_ROOT environment variable to set ONNX model path to: " + kONNXModelPath);
385+
}
386+
387+
388+
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kDetectionMethod", kDetectionMethod);
389+
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kBallPlacementDetectionMethod", kBallPlacementDetectionMethod);
373390
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kONNXConfidenceThreshold", kONNXConfidenceThreshold);
374391
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kONNXNMSThreshold", kONNXNMSThreshold);
375392
GolfSimConfiguration::SetConstant("gs_config.ball_identification.kONNXInputSize", kONNXInputSize);
@@ -4200,7 +4217,7 @@ namespace golf_sim {
42004217
return true;
42014218
}
42024219

4203-
GS_LOG_MSG(info, "Loading YOLO model from: " + kONNXModelPath);
4220+
GS_LOG_MSG(trace, "Loading YOLO model from: " + kONNXModelPath);
42044221
auto start_time = std::chrono::high_resolution_clock::now();
42054222

42064223
yolo_model_ = cv::dnn::readNetFromONNX(kONNXModelPath);
@@ -4226,7 +4243,7 @@ namespace golf_sim {
42264243

42274244
auto end_time = std::chrono::high_resolution_clock::now();
42284245
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
4229-
GS_LOG_MSG(info, "YOLO model preloaded successfully in " +
4246+
GS_LOG_MSG(trace, "YOLO model preloaded successfully in " +
42304247
std::to_string(duration.count()) + "ms. First detection will be fast!");
42314248

42324249
return true;
@@ -4251,7 +4268,7 @@ namespace golf_sim {
42514268
{
42524269
std::lock_guard<std::mutex> lock(yolo_model_mutex_);
42534270
if (!yolo_model_loaded_) {
4254-
GS_LOG_MSG(info, "Loading YOLO model for the first time (one-time ~500ms operation)...");
4271+
GS_LOG_MSG(trace, "Loading YOLO model for the first time (one-time ~500ms operation)...");
42554272
auto start_time = std::chrono::high_resolution_clock::now();
42564273

42574274
yolo_model_ = cv::dnn::readNetFromONNX(kONNXModelPath);
@@ -4278,13 +4295,16 @@ namespace golf_sim {
42784295

42794296
auto end_time = std::chrono::high_resolution_clock::now();
42804297
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
4281-
GS_LOG_MSG(info, "YOLO model loaded and cached successfully in " +
4298+
GS_LOG_MSG(trace, "YOLO model loaded and cached successfully in " +
42824299
std::to_string(duration.count()) + "ms. Buffers pre-allocated. Future detections will be fast!");
42834300
}
42844301
}
42854302

42864303
cv::dnn::Net& net = yolo_model_;
42874304

4305+
auto processing_start_time = std::chrono::high_resolution_clock::now();
4306+
GS_LOG_MSG(trace, "YOLO processing started.");
4307+
42884308
if (preprocessed_img.channels() == 1) {
42894309
cv::cvtColor(preprocessed_img, yolo_input_buffer_, cv::COLOR_GRAY2RGB);
42904310
} else if (preprocessed_img.channels() == 3) {
@@ -4436,7 +4456,11 @@ namespace golf_sim {
44364456
detected_circles.push_back(circle);
44374457
}
44384458

4439-
GS_LOG_TRACE_MSG(trace, "ONNX detected " + std::to_string(detected_circles.size()) + " balls");
4459+
auto processing_end_time = std::chrono::high_resolution_clock::now();
4460+
auto processing_duration = std::chrono::duration_cast<std::chrono::milliseconds>(processing_end_time - processing_start_time);
4461+
GS_LOG_MSG(trace, "YOLO model completed processing in " + std::to_string(processing_duration.count()) + " ms.");
4462+
4463+
GS_LOG_TRACE_MSG(trace, "ONNX detected " + std::to_string(detected_circles.size()) + " balls. YOLO processing complete");
44404464
return !detected_circles.empty();
44414465

44424466
} catch (const cv::Exception& e) {

0 commit comments

Comments
 (0)