Skip to content

Commit a9fce07

Browse files
fixed functionallity for the tests to pass and added logging definition
1 parent 9f21012 commit a9fce07

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <vector>
44
#include <filesystem>
55
#include <opencv2/opencv.hpp>
6+
67
int main()
78
{
89
// Running inference
@@ -11,7 +12,7 @@ int main()
1112
SEG::DL_INIT_PARAM params_decoder;
1213
std::tie(samSegmentors, params_encoder, params_decoder) = Initializer();
1314
std::filesystem::path current_path = std::filesystem::current_path();
14-
std::filesystem::path imgs_path = "/home/amigo/Documents/repos/hero_sam/pipeline/build/images"; // current_path / <- you could use
15+
std::filesystem::path imgs_path = "/home/amigo/Documents/repos/hero_sam/sam_inference/build/images"; // current_path / <- you could use
1516
for (auto &i : std::filesystem::directory_iterator(imgs_path))
1617
{
1718
if (i.path().extension() == ".jpg" || i.path().extension() == ".png" || i.path().extension() == ".jpeg")

src/sam_inference.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <regex>
44

55
#define benchmark
6-
#define ROI
6+
//#define ROI
77

88
SAM::SAM() {}
99

@@ -223,6 +223,8 @@ const char *SAM::TensorProcess(clock_t &starttime_1, const cv::Mat &iImg,
223223

224224
std::vector<cv::Rect> boundingBoxes;
225225
boundingBoxes.push_back(bbox);
226+
#else
227+
result.boxes.push_back(cv::Rect(0, 0, iImg.cols, iImg.rows));
226228
#endif // ROI
227229

228230
#ifdef benchmark

src/utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "utils.h"
22
#include <opencv2/ximgproc/edge_filter.hpp> // for guided filter
3+
#define LOGGING
34

45
// Constructor
56
Utils::Utils()
@@ -33,7 +34,8 @@ char *Utils::PreProcess(const cv::Mat &iImg, std::vector<int> iImgSize, cv::Mat
3334
resizeScales = iImg.rows / (float)iImgSize.at(1);
3435
cv::resize(oImg, oImg, cv::Size(int(iImg.cols / resizeScales), iImgSize.at(1)));
3536
}
36-
cv::Mat tempImg = cv::Mat::zeros(iImgSize.at(0), iImgSize.at(1), CV_8UC3);
37+
//cv::Mat tempImg = cv::Mat::zeros(iImgSize.at(0), iImgSize.at(1), CV_8UC3);
38+
cv::Mat tempImg = cv::Mat::zeros(iImgSize.at(1), iImgSize.at(0), CV_8UC3);
3739
oImg.copyTo(tempImg(cv::Rect(0, 0, oImg.cols, oImg.rows)));
3840
oImg = tempImg;
3941

@@ -198,6 +200,7 @@ void Utils::PostProcess(std::vector<Ort::Value> &output_tensors, const cv::Mat &
198200
result.masks.push_back(finalMask);
199201

200202
// Overlay for display on a copy (iImg is const)
203+
#ifdef LOGGING
201204
cv::Mat overlay = iImg.clone();
202205
std::vector<std::vector<cv::Point>> contours;
203206
cv::findContours(finalMask, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
@@ -210,6 +213,7 @@ void Utils::PostProcess(std::vector<Ort::Value> &output_tensors, const cv::Mat &
210213
cv::imshow("SAM Segmentation", overlay);
211214
cv::waitKey(0);
212215
cv::destroyAllWindows();
216+
#endif // LOGGING
213217
}
214218
else
215219
{

0 commit comments

Comments
 (0)