Skip to content

Commit ef1f775

Browse files
Create single point of contact for Initialization and Detection (inference)
1 parent 1742156 commit ef1f775

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/detection.cpp

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

8-
std::vector<DL_RESULT> DetectObjects(std::unique_ptr<YOLO_V8>& p, const cv::Mat& img) {
8+
void Detector(std::unique_ptr<YOLO_V8>& p, std::vector<DL_RESULT>& res, const cv::Mat& img) {
9+
910

10-
std::vector<DL_RESULT> res;
1111
p->RunSession(img, res);
1212

1313
for (auto& re : res)
@@ -42,12 +42,12 @@ std::vector<DL_RESULT> DetectObjects(std::unique_ptr<YOLO_V8>& p, const cv::Mat&
4242

4343

4444
}
45-
std::cout << "Press any key to exit" << std::endl;
46-
cv::imshow("Result of Detection", img);
47-
cv::waitKey(0);
48-
cv::destroyAllWindows();
49-
return res;
50-
}
45+
//std::cout << "Press any key to exit" << std::endl;
46+
//cv::imshow("Result of Detection", img);
47+
//cv::waitKey(0);
48+
//cv::destroyAllWindows();
49+
50+
}
5151

5252

5353

@@ -137,14 +137,15 @@ int ReadCocoYaml(std::unique_ptr<YOLO_V8>& p) {
137137
return 0;
138138
}
139139

140-
std::unique_ptr<YOLO_V8> Initialize()
140+
std::tuple<std::unique_ptr<YOLO_V8>, std::vector<DL_RESULT>> Initialize()
141141
{
142142
std::unique_ptr<YOLO_V8> yoloDetector = std::make_unique<YOLO_V8>();
143-
143+
std::vecroet<DL_RESULT> res;
144144
ReadCocoYaml(yoloDetector);
145145
DL_INIT_PARAM params;
146146
params.rectConfidenceThreshold = 0.1;
147147
params.iouThreshold = 0.5;
148+
// Mayve change the model from V11 to V8
148149
params.modelPath = "yolo11m.onnx";
149150
params.imgSize = { 640, 640 };
150151
#ifdef USE_CUDA
@@ -163,7 +164,7 @@ std::unique_ptr<YOLO_V8> Initialize()
163164

164165
#endif
165166
yoloDetector->CreateSession(params);
166-
return yoloDetector;
167+
return std::make_tuple(std::move(yoloDetector), std::move(res));
167168
}
168169

169170

src/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
int main()
99
{
1010
// An example of how to use the YOLO_V8 class for object detection
11-
std::unique_ptr<YOLO_V8> yoloDetector = Initialize();
11+
std::unique_ptr<YOLO_V8> yoloDetector;
12+
std::vector<DL_RESULT> results;
13+
std::tie(yoloDetector, results) = Initialize();
14+
1215
std::filesystem::path current_path = std::filesystem::current_path();
1316
std::filesystem::path imgs_path = current_path / "images";
1417
for (auto& i : std::filesystem::directory_iterator(imgs_path))
@@ -17,8 +20,7 @@ int main()
1720
{
1821
std::string img_path = i.path().string();
1922
cv::Mat img = cv::imread(img_path);
20-
std::vector<DL_RESULT> results;
21-
results = DetectObjects(yoloDetector, img);
23+
DetectObjects(yoloDetector, img, results);
2224
}
2325
}
2426

0 commit comments

Comments
 (0)