Skip to content

Commit f87e8ee

Browse files
committed
Working args
1 parent daa5337 commit f87e8ee

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "yolo_onnx_ros/yolo_inference.hpp"
22

3-
std::tuple<std::unique_ptr<YOLO_V8>, DL_INIT_PARAM> Initialize();
3+
#include <filesystem>
4+
5+
std::tuple<std::unique_ptr<YOLO_V8>, DL_INIT_PARAM> Initialize(const std::filesystem::path& model_filename);
6+
47
std::vector<DL_RESULT> Detector(std::unique_ptr<YOLO_V8>& p, const cv::Mat& img);
5-
int ReadCocoYaml(std::unique_ptr<YOLO_V8>& p);
8+
9+
int ReadCocoYaml(const std::filesystem::path& filename, std::unique_ptr<YOLO_V8>& p);

src/detection.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ std::vector<DL_RESULT> Detector(std::unique_ptr<YOLO_V8>& p, const cv::Mat& img)
9090

9191

9292

93-
int ReadCocoYaml(std::unique_ptr<YOLO_V8>& p) {
93+
int ReadCocoYaml(const std::filesystem::path& filename, std::unique_ptr<YOLO_V8>& p)
94+
{
9495
// Open the YAML file
95-
std::ifstream file("data/coco.yaml");
96+
std::ifstream file(filename);
9697
if (!file.is_open())
9798
{
9899
std::cerr << "Failed to open file" << std::endl;
@@ -138,15 +139,14 @@ int ReadCocoYaml(std::unique_ptr<YOLO_V8>& p) {
138139
return 0;
139140
}
140141

141-
std::tuple<std::unique_ptr<YOLO_V8>, DL_INIT_PARAM> Initialize()
142+
std::tuple<std::unique_ptr<YOLO_V8>, DL_INIT_PARAM> Initialize(const std::filesystem::path& model_filename)
142143
{
143144
std::unique_ptr<YOLO_V8> yoloDetector = std::make_unique<YOLO_V8>();
144-
ReadCocoYaml(yoloDetector);
145+
ReadCocoYaml(model_filename.parent_path() / "coco.yaml", yoloDetector);
145146
DL_INIT_PARAM params;
146147
params.rectConfidenceThreshold = 0.1;
147148
params.iouThreshold = 0.5;
148-
// Mayve change the model from V11 to V8
149-
params.modelPath = "yolo11m.onnx";
149+
params.modelPath = model_filename;
150150
params.imgSize = { 640, 640 };
151151
#if defined(YOLO_ONNX_ROS_CUDA_ENABLED) && YOLO_ONNX_ROS_CUDA_ENABLED
152152
params.cudaEnable = true;

src/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
#include <fstream>
66
#include <random>
77

8-
int main()
8+
int main(int argc, char *argv[])
99
{
1010
std::unique_ptr<YOLO_V8> yoloDetector;
1111
DL_INIT_PARAM params;
1212

13-
std::tie(yoloDetector, params) = Initialize();
13+
if (argc < 2)
14+
{
15+
std::cerr << "Not enough args provided" << std::endl;
16+
return 1;
17+
}
18+
19+
const std::filesystem::path model_name = argv[1];
20+
21+
std::tie(yoloDetector, params) = Initialize(model_name);
1422

1523
std::filesystem::path current_path = std::filesystem::current_path();
1624
std::filesystem::path imgs_path = current_path / "images";

0 commit comments

Comments
 (0)