From 41431e11f50d70d879275f4dd4bb024fb4d89482 Mon Sep 17 00:00:00 2001 From: Dimitrios Katsaros Date: Wed, 20 Jul 2016 15:13:39 +0200 Subject: [PATCH] Imgcodecs: Implemented simple tests for PAM format --- modules/imgcodecs/test/test_grfmt.cpp | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index f305ca137a..4328372703 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -44,6 +44,7 @@ #include #include +#include using namespace cv; using namespace std; @@ -308,6 +309,7 @@ string ext_from_int(int ext) #ifdef HAVE_TIFF if (ext == 3) return ".tiff"; #endif + if (ext == 4) return ".pam"; return ""; } @@ -323,7 +325,7 @@ public: for (int k = 1; k <= 5; ++k) { - for (int ext = 0; ext < 4; ++ext) // 0 - png, 1 - bmp, 2 - pgm, 3 - tiff + for (int ext = 0; ext < 5; ++ext) // 0 - png, 1 - bmp, 2 - pgm, 3 - tiff { if(ext_from_int(ext).empty()) continue; @@ -1017,3 +1019,27 @@ TEST(Imgcodecs_Hdr, regression) ASSERT_FALSE(max > DBL_EPSILON); } } + +TEST(Imgcodecs_Pam, readwrite) +{ + string folder = string(cvtest::TS::ptr()->get_data_path()) + "readwrite/"; + string filepath = folder + "lena.pam"; + + cv::Mat img = cv::imread(filepath); + ASSERT_FALSE(img.empty()); + + std::vector params; + params.push_back(IMWRITE_PAM_TUPLETYPE); + params.push_back(IMWRITE_PAM_FORMAT_RGB); + + string writefile = cv::tempfile(".pam"); + EXPECT_NO_THROW(cv::imwrite(writefile, img, params)); + cv::Mat reread = cv::imread(writefile); + + string writefile_no_param = cv::tempfile(".pam"); + EXPECT_NO_THROW(cv::imwrite(writefile_no_param, img)); + cv::Mat reread_no_param = cv::imread(writefile_no_param); + + EXPECT_EQ(0, cvtest::norm(reread, reread_no_param, NORM_INF)); + EXPECT_EQ(0, cvtest::norm(img, reread, NORM_INF)); +} -- GitLab