diff --git a/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/matching.hpp b/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/matching.hpp index 3c5e3a014e..2937a4c394 100644 --- a/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/matching.hpp +++ b/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/matching.hpp @@ -31,7 +31,7 @@ namespace autoware::object_recognition_utils { using autoware_utils_geometry::Polygon2d; // minimum area to avoid division by zero -static const double MIN_AREA = 1e-6; +static constexpr double MIN_AREA = 1e-6; inline double getConvexShapeArea(const Polygon2d & source_polygon, const Polygon2d & target_polygon) { @@ -66,7 +66,8 @@ inline double getUnionArea(const Polygon2d & source_polygon, const Polygon2d & t } template -double get2dIoU(const T1 source_object, const T2 target_object, const double min_union_area = 0.01) +double get2dIoU( + const T1 & source_object, const T2 & target_object, const double min_union_area = 0.01) { const auto source_polygon = autoware_utils_geometry::to_polygon2d(source_object); if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0; @@ -99,7 +100,7 @@ double get2dGeneralizedIoU(const T1 & source_object, const T2 & target_object) } template -double get2dPrecision(const T1 source_object, const T2 target_object) +double get2dPrecision(const T1 & source_object, const T2 & target_object) { const auto source_polygon = autoware_utils_geometry::to_polygon2d(source_object); const double source_area = boost::geometry::area(source_polygon); @@ -114,7 +115,7 @@ double get2dPrecision(const T1 source_object, const T2 target_object) } template -double get2dRecall(const T1 source_object, const T2 target_object) +double get2dRecall(const T1 & source_object, const T2 & target_object) { const auto source_polygon = autoware_utils_geometry::to_polygon2d(source_object); if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0; diff --git a/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/object_classification.hpp b/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/object_classification.hpp index 594b293592..c043c95b1a 100644 --- a/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/object_classification.hpp +++ b/common/autoware_object_recognition_utils/include/autoware/object_recognition_utils/object_classification.hpp @@ -15,7 +15,7 @@ #ifndef AUTOWARE__OBJECT_RECOGNITION_UTILS__OBJECT_CLASSIFICATION_HPP_ #define AUTOWARE__OBJECT_RECOGNITION_UTILS__OBJECT_CLASSIFICATION_HPP_ -#include "autoware_perception_msgs/msg/object_classification.hpp" +#include #include #include @@ -39,8 +39,7 @@ inline ObjectClassification getHighestProbClassification( inline std::uint8_t getHighestProbLabel( const std::vector & object_classifications) { - auto classification = getHighestProbClassification(object_classifications); - return classification.label; + return getHighestProbClassification(object_classifications).label; } inline bool isVehicle(const uint8_t label) @@ -57,8 +56,7 @@ inline bool isVehicle(const ObjectClassification & object_classification) inline bool isVehicle(const std::vector & object_classifications) { - auto highest_prob_label = getHighestProbLabel(object_classifications); - return isVehicle(highest_prob_label); + return isVehicle(getHighestProbLabel(object_classifications)); } inline bool isCarLikeVehicle(const uint8_t label) @@ -74,8 +72,7 @@ inline bool isCarLikeVehicle(const ObjectClassification & object_classification) inline bool isCarLikeVehicle(const std::vector & object_classifications) { - auto highest_prob_label = getHighestProbLabel(object_classifications); - return isCarLikeVehicle(highest_prob_label); + return isCarLikeVehicle(getHighestProbLabel(object_classifications)); } inline bool isLargeVehicle(const uint8_t label) @@ -91,8 +88,7 @@ inline bool isLargeVehicle(const ObjectClassification & object_classification) inline bool isLargeVehicle(const std::vector & object_classifications) { - auto highest_prob_label = getHighestProbLabel(object_classifications); - return isLargeVehicle(highest_prob_label); + return isLargeVehicle(getHighestProbLabel(object_classifications)); } inline uint8_t toLabel(const std::string & class_name) @@ -130,9 +126,7 @@ inline ObjectClassification toObjectClassification( inline std::vector toObjectClassifications( const std::string & class_name, float probability) { - std::vector classifications; - classifications.push_back(toObjectClassification(class_name, probability)); - return classifications; + return {toObjectClassification(class_name, probability)}; } inline std::string convertLabelToString(const uint8_t label) @@ -158,16 +152,15 @@ inline std::string convertLabelToString(const uint8_t label) } } -inline std::string convertLabelToString(const ObjectClassification object_classification) +inline std::string convertLabelToString(const ObjectClassification & object_classification) { return convertLabelToString(object_classification.label); } inline std::string convertLabelToString( - const std::vector object_classifications) + const std::vector & object_classifications) { - auto highest_prob_label = getHighestProbLabel(object_classifications); - return convertLabelToString(highest_prob_label); + return convertLabelToString(getHighestProbLabel(object_classifications)); } } // namespace autoware::object_recognition_utils diff --git a/common/autoware_object_recognition_utils/src/conversion.cpp b/common/autoware_object_recognition_utils/src/conversion.cpp index 6f8e6aa27c..160c03abd6 100644 --- a/common/autoware_object_recognition_utils/src/conversion.cpp +++ b/common/autoware_object_recognition_utils/src/conversion.cpp @@ -43,11 +43,12 @@ DetectedObject toDetectedObject(const TrackedObject & tracked_object) DetectedObjects toDetectedObjects(const TrackedObjects & tracked_objects) { - autoware_perception_msgs::msg::DetectedObjects detected_objects; + DetectedObjects detected_objects; detected_objects.header = tracked_objects.header; + detected_objects.objects.reserve(tracked_objects.objects.size()); for (const auto & tracked_object : tracked_objects.objects) { - detected_objects.objects.push_back(toDetectedObject(tracked_object)); + detected_objects.objects.emplace_back(toDetectedObject(tracked_object)); } return detected_objects; }