Skip to content

Commit 964d95f

Browse files
corrected tests for the new segmentation way of inference (initialize and segment anything interfaces changed) and added one more test to check the image dimensions W,H
1 parent 01da1fc commit 964d95f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

test/sam_test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ class SamInferenceTest : public ::testing::Test
2828
NonSquareImgSize = { testImage_800x600.cols, testImage_800x600.rows };
2929

3030
// Use package helpers to build default params and SAM objects.
31-
std::tie(samSegmentors, params_encoder, params_decoder) = Initializer();
31+
std::tie(samSegmentors, params_encoder, params_decoder, res, resSam) = Initializer();
3232

3333
#ifdef USE_CUDA
3434
params_encoder.cudaEnable = true; // Enable CUDA if compiled with it
3535
#else
3636
params_encoder.cudaEnable = false; // Otherwise run on CPU
3737
#endif
38+
3839
}
3940

4041
// Clean up the SAM objects after each test.
@@ -46,6 +47,8 @@ class SamInferenceTest : public ::testing::Test
4647
std::vector<int> NonSquareImgSize;
4748
std::vector<std::unique_ptr<SAM>> samSegmentors;
4849
SEG::DL_INIT_PARAM params_encoder, params_decoder;
50+
SEG::DL_RESULT res;
51+
std::vector<SEG::DL_RESULT> resSam;
4952
};
5053

5154
// Simple smoke test: we can construct a SAM object without throwing.
@@ -84,8 +87,8 @@ TEST_F(SamInferenceTest, FullInferencePipeline)
8487
GTEST_SKIP() << "Models not found in build dir";
8588
}
8689

87-
auto masks = SegmentAnything(samSegmentors, params_encoder, params_decoder, testImage_realistic);
90+
SegmentAnything(samSegmentors, params_encoder, params_decoder, testImage_realistic, resSam, res);
8891

8992
// We only check that a vector is returned. (You can strengthen this to EXPECT_FALSE(masks.empty()).)
90-
EXPECT_TRUE(masks.size() >= 0) << "Masks should be a valid output vector";
93+
EXPECT_TRUE(res.masks.size() >= 0) << "Masks should be a valid output vector";
9194
}

test/test_utils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ TEST_F(UtilsTest, PreprocessTopLeftPaddingAndAspect) {
6666
}
6767
}
6868

69+
// Explicitly ensure imgSize is interpreted as [W, H] in PreProcess for non-square targets.
70+
TEST_F(UtilsTest, PreprocessNonSquareWidthHeightOrder) {
71+
// Input image: H=300, W=500
72+
cv::Mat img(300, 500, CV_8UC3, cv::Scalar(5, 6, 7));
73+
74+
// Target canvas (W,H) with non-square dims
75+
std::vector<int> target{640, 480};
76+
cv::Mat out;
77+
78+
ASSERT_EQ(u.PreProcess(img, target, out), nullptr);
79+
// cols = width, rows = height
80+
EXPECT_EQ(out.cols, target[0]);
81+
EXPECT_EQ(out.rows, target[1]);
82+
EXPECT_EQ(out.size(), cv::Size(target[0], target[1]));
83+
}
84+
6985
// Parameterized fixture: used with TEST_P to run the same test body
7086
// for many (input size, target size) pairs.
7187
class UtilsPreprocessParamTest

0 commit comments

Comments
 (0)