2
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
3
// of this distribution and at http://opencv.org/license.html.
4
4
#include " test_precomp.hpp"
5
- using namespace cv ;
6
5
7
6
namespace opencv_test
8
7
{
@@ -13,71 +12,36 @@ namespace opencv_test
13
12
const std::string TRIMAP_FILENAME = " trimap/doll.png" ;
14
13
15
14
16
- class CV_GlobalMattingTest : public cvtest ::BaseTest
15
+ void runModel ()
17
16
{
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);
33
21
34
22
Mat img = cv::imread (img_path,cv::IMREAD_COLOR);
35
23
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 );
48
29
Mat foreground,alpha;
49
30
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
+
64
39
}
65
40
66
- CV_GlobalMattingTest::CV_GlobalMattingTest ()
67
- {
68
- gm = makePtr<GlobalMatting>();
69
- }
70
- void CV_GlobalMattingTest::run (int )
71
- {
72
- runModel ();
73
- }
74
-
75
-
76
41
77
42
TEST (CV_GlobalMattingTest,accuracy)
78
43
{
79
- CV_GlobalMattingTest test;
80
- test.safe_run ();
44
+ runModel ();
81
45
}
82
46
83
47
}
0 commit comments