Skip to content

Commit 8dd0b1d

Browse files
committed
fix const reference
1 parent 16a618d commit 8dd0b1d

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

yolox_ros_cpp/yolox_cpp/include/yolox_cpp/coco_names.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace yolox_cpp{
9393
{0.857, 0.857, 0.857},
9494
{0.000, 0.447, 0.741},
9595
{0.314, 0.717, 0.741},
96-
{0.50, 0.5, 0}
96+
{0.500, 0.500, 0.000}
9797
};
9898
}
9999
#endif

yolox_ros_cpp/yolox_cpp/include/yolox_cpp/utils.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,44 @@
88
#include "core.hpp"
99
#include "coco_names.hpp"
1010

11-
namespace yolox_cpp{
12-
namespace utils{
11+
namespace yolox_cpp
12+
{
13+
namespace utils
14+
{
1315

14-
static std::vector<std::string> read_class_labels_file(file_name_t file_name)
16+
static std::vector<std::string> read_class_labels_file(const file_name_t &file_name)
1517
{
1618
std::vector<std::string> class_names;
1719
std::ifstream ifs(file_name);
1820
std::string buff;
19-
if(ifs.fail()){
21+
if (ifs.fail())
22+
{
2023
return class_names;
2124
}
22-
while (getline(ifs, buff)) {
25+
while (getline(ifs, buff))
26+
{
2327
if (buff == "")
2428
continue;
2529
class_names.push_back(buff);
2630
}
2731
return class_names;
2832
}
2933

30-
static void draw_objects(cv::Mat bgr, const std::vector<Object>& objects, const std::vector<std::string>& class_names=COCO_CLASSES)
34+
static void draw_objects(cv::Mat bgr, const std::vector<Object> &objects, const std::vector<std::string> &class_names = COCO_CLASSES)
3135
{
3236

33-
for (size_t i = 0; i < objects.size(); i++)
37+
for (const Object &obj : objects)
3438
{
35-
const Object& obj = objects[i];
36-
37-
int color_index = obj.label % 80;
39+
const int color_index = obj.label % 80;
3840
cv::Scalar color = cv::Scalar(color_list[color_index][0], color_list[color_index][1], color_list[color_index][2]);
3941
float c_mean = cv::mean(color)[0];
4042
cv::Scalar txt_color;
41-
if (c_mean > 0.5){
43+
if (c_mean > 0.5)
44+
{
4245
txt_color = cv::Scalar(0, 0, 0);
43-
}else{
46+
}
47+
else
48+
{
4449
txt_color = cv::Scalar(255, 255, 255);
4550
}
4651

@@ -68,4 +73,4 @@ namespace yolox_cpp{
6873
}
6974
}
7075
}
71-
#endif
76+
#endif

yolox_ros_cpp/yolox_ros_cpp/include/yolox_ros_cpp/yolox_ros_cpp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ namespace yolox_ros_cpp{
3939
rclcpp::Publisher<bboxes_ex_msgs::msg::BoundingBoxes>::SharedPtr pub_bboxes_;
4040
image_transport::Publisher pub_image_;
4141

42-
bboxes_ex_msgs::msg::BoundingBoxes objects_to_bboxes(cv::Mat, std::vector<yolox_cpp::Object>, std_msgs::msg::Header);
42+
bboxes_ex_msgs::msg::BoundingBoxes objects_to_bboxes(const cv::Mat&, const std::vector<yolox_cpp::Object>&, const std_msgs::msg::Header&);
4343
};
4444
}

yolox_ros_cpp/yolox_ros_cpp/src/yolox_ros_cpp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ namespace yolox_ros_cpp
131131
pub_img = cv_bridge::CvImage(img->header, "bgr8", frame).toImageMsg();
132132
this->pub_image_.publish(pub_img);
133133
}
134-
bboxes_ex_msgs::msg::BoundingBoxes YoloXNode::objects_to_bboxes(cv::Mat frame, std::vector<yolox_cpp::Object> objects, std_msgs::msg::Header header)
134+
135+
bboxes_ex_msgs::msg::BoundingBoxes YoloXNode::objects_to_bboxes(
136+
const cv::Mat &frame, const std::vector<yolox_cpp::Object> &objects, const std_msgs::msg::Header &header)
135137
{
136138
bboxes_ex_msgs::msg::BoundingBoxes boxes;
137139
boxes.header = header;
138-
for (auto obj : objects)
140+
for (const auto &obj : objects)
139141
{
140142
bboxes_ex_msgs::msg::BoundingBox box;
141143
box.probability = obj.prob;
142-
box.class_id = yolox_cpp::COCO_CLASSES[obj.label];
144+
box.class_id = this->class_names_[obj.label];
143145
box.xmin = obj.rect.x;
144146
box.ymin = obj.rect.y;
145147
box.xmax = (obj.rect.x + obj.rect.width);

0 commit comments

Comments
 (0)