Skip to content

Commit c717544

Browse files
authored
Not using BaseTest legacy code anymore
Put all the testing code in the Test()
1 parent 2163803 commit c717544

File tree

1 file changed

+19
-55
lines changed

1 file changed

+19
-55
lines changed

modules/ximgproc/test/test_globalmatting.cpp

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// It is subject to the license terms in the LICENSE file found in the top-level directory
33
// of this distribution and at http://opencv.org/license.html.
44
#include "test_precomp.hpp"
5-
using namespace cv;
65

76
namespace opencv_test
87
{
@@ -13,71 +12,36 @@ namespace opencv_test
1312
const std::string TRIMAP_FILENAME = "trimap/doll.png";
1413

1514

16-
class CV_GlobalMattingTest : public cvtest::BaseTest
15+
void runModel()
1716
{
18-
public:
19-
CV_GlobalMattingTest();
20-
21-
protected:
22-
Ptr<GlobalMatting> gm;
23-
virtual void run(int);
24-
void runModel();
25-
26-
};
27-
28-
void CV_GlobalMattingTest::runModel()
29-
{
30-
std::string folder = std::string(cvtest::TS::ptr()->get_data_path());
31-
std::string img_path = folder + INPUT_DIR + "/" + IMAGE_FILENAME;
32-
std::string trimap_path = folder + INPUT_DIR + "/" + TRIMAP_FILENAME;
17+
18+
Ptr<GlobalMatting> gm = makePtr<GlobalMatting>();
19+
std::string img_path = cvtest::findDataFile(INPUT_DIR + "/" + IMAGE_FILENAME);
20+
std::string trimap_path = cvtest::findDataFile(INPUT_DIR + "/" + TRIMAP_FILENAME);
3321

3422
Mat img = cv::imread(img_path,cv::IMREAD_COLOR);
3523
Mat trimap = cv::imread(trimap_path,cv::IMREAD_GRAYSCALE);
36-
if(img.empty() || trimap.empty())
37-
{
38-
ts->printf(cvtest::TS::LOG,"Test images not found!\n");
39-
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
40-
return;
41-
}
42-
if(img.cols!=trimap.cols || img.rows!=trimap.rows)
43-
{
44-
ts->printf(cvtest::TS::LOG,"Dimensions of trimap and the image are not the same");
45-
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
46-
return;
47-
}
24+
ASSERT_FALSE(img.empty()) << "The Image could not be loaded: "<< img_path;
25+
ASSERT_FALSE(trimap.empty()) << "The trimap could not be loaded: "<< trimap_path;
26+
27+
ASSERT_EQ(img.cols,trimap.cols);
28+
ASSERT_EQ(img.rows,trimap.rows);
4829
Mat foreground,alpha;
4930
int niter = 9;
50-
this->gm->getMat(img,trimap,foreground,alpha,niter);
51-
if(alpha.empty())
52-
{
53-
ts->printf(cvtest::TS::LOG,"Could not find the alpha matte for the image\n");
54-
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
55-
return;
56-
}
57-
58-
if(alpha.cols!=img.cols || alpha.rows!=img.rows)
59-
{
60-
ts->printf(cvtest::TS::LOG,"The dimensions of the output are not correct");
61-
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
62-
return;
63-
}
31+
gm->getMat(img,trimap,foreground,alpha,niter);
32+
33+
ASSERT_FALSE(foreground.empty()) << " Could not extract the foreground " <<
34+
ASSERT_FALSE(alpha.empty()) << " Could not generate alpha matte " <<
35+
36+
ASSERT_EQ(alpha.cols,img.cols)
37+
ASSERT_EQ(alpha.rows,img.rows)
38+
6439
}
6540

66-
CV_GlobalMattingTest::CV_GlobalMattingTest()
67-
{
68-
gm = makePtr<GlobalMatting>();
69-
}
70-
void CV_GlobalMattingTest::run(int)
71-
{
72-
runModel();
73-
}
74-
75-
7641

7742
TEST(CV_GlobalMattingTest,accuracy)
7843
{
79-
CV_GlobalMattingTest test;
80-
test.safe_run();
44+
runModel();
8145
}
8246

8347
}

0 commit comments

Comments
 (0)