mirror of
https://github.com/opencv/opencv.git
synced 2024-12-16 18:39:12 +08:00
152 lines
5.2 KiB
C++
152 lines
5.2 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
|
// directory of this distribution and at http://opencv.org/license.html
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
namespace opencv_test { namespace {
|
|
|
|
/**
|
|
* Test to check whether the EXIF orientation tag was processed successfully or not.
|
|
* The test uses a set of 8 images named testExifOrientation_{1 to 8}.(extension).
|
|
* Each test image is a 10x10 square, divided into four smaller sub-squares:
|
|
* (R corresponds to Red, G to Green, B to Blue, W to White)
|
|
* --------- ---------
|
|
* | R | G | | G | R |
|
|
* |-------| - (tag 1) |-------| - (tag 2)
|
|
* | B | W | | W | B |
|
|
* --------- ---------
|
|
*
|
|
* --------- ---------
|
|
* | W | B | | B | W |
|
|
* |-------| - (tag 3) |-------| - (tag 4)
|
|
* | G | R | | R | G |
|
|
* --------- ---------
|
|
*
|
|
* --------- ---------
|
|
* | R | B | | G | W |
|
|
* |-------| - (tag 5) |-------| - (tag 6)
|
|
* | G | W | | R | B |
|
|
* --------- ---------
|
|
*
|
|
* --------- ---------
|
|
* | W | G | | B | R |
|
|
* |-------| - (tag 7) |-------| - (tag 8)
|
|
* | B | R | | W | G |
|
|
* --------- ---------
|
|
*
|
|
*
|
|
* Each image contains an EXIF field with an orientation tag (0x112).
|
|
* After reading each image and applying the orientation tag,
|
|
* the resulting image should be:
|
|
* ---------
|
|
* | R | G |
|
|
* |-------|
|
|
* | B | W |
|
|
* ---------
|
|
*
|
|
* Note:
|
|
* The flags parameter of the imread function is set as IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH.
|
|
* Using this combination is an undocumented trick to load images similarly to the IMREAD_UNCHANGED flag,
|
|
* preserving the alpha channel (if present) while also applying the orientation.
|
|
*/
|
|
|
|
typedef testing::TestWithParam<string> Exif;
|
|
|
|
TEST_P(Exif, exif_orientation)
|
|
{
|
|
const string root = cvtest::TS::ptr()->get_data_path();
|
|
const string filename = root + GetParam();
|
|
const int colorThresholdHigh = 250;
|
|
const int colorThresholdLow = 5;
|
|
|
|
// Refer to the note in the explanation above.
|
|
Mat m_img = imread(filename, IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH);
|
|
ASSERT_FALSE(m_img.empty());
|
|
|
|
if (m_img.channels() == 3)
|
|
{
|
|
Vec3b vec;
|
|
|
|
//Checking the first quadrant (with supposed red)
|
|
vec = m_img.at<Vec3b>(2, 2); //some point inside the square
|
|
EXPECT_LE(vec.val[0], colorThresholdLow);
|
|
EXPECT_LE(vec.val[1], colorThresholdLow);
|
|
EXPECT_GE(vec.val[2], colorThresholdHigh);
|
|
|
|
//Checking the second quadrant (with supposed green)
|
|
vec = m_img.at<Vec3b>(2, 7); //some point inside the square
|
|
EXPECT_LE(vec.val[0], colorThresholdLow);
|
|
EXPECT_GE(vec.val[1], colorThresholdHigh);
|
|
EXPECT_LE(vec.val[2], colorThresholdLow);
|
|
|
|
//Checking the third quadrant (with supposed blue)
|
|
vec = m_img.at<Vec3b>(7, 2); //some point inside the square
|
|
EXPECT_GE(vec.val[0], colorThresholdHigh);
|
|
EXPECT_LE(vec.val[1], colorThresholdLow);
|
|
EXPECT_LE(vec.val[2], colorThresholdLow);
|
|
}
|
|
else
|
|
{
|
|
Vec4b vec;
|
|
|
|
//Checking the first quadrant (with supposed red)
|
|
vec = m_img.at<Vec4b>(2, 2); //some point inside the square
|
|
EXPECT_LE(vec.val[0], colorThresholdLow);
|
|
EXPECT_LE(vec.val[1], colorThresholdLow);
|
|
EXPECT_GE(vec.val[2], colorThresholdHigh);
|
|
|
|
//Checking the second quadrant (with supposed green)
|
|
vec = m_img.at<Vec4b>(2, 7); //some point inside the square
|
|
EXPECT_LE(vec.val[0], colorThresholdLow);
|
|
EXPECT_GE(vec.val[1], colorThresholdHigh);
|
|
EXPECT_LE(vec.val[2], colorThresholdLow);
|
|
|
|
//Checking the third quadrant (with supposed blue)
|
|
vec = m_img.at<Vec4b>(7, 2); //some point inside the square
|
|
EXPECT_GE(vec.val[0], colorThresholdHigh);
|
|
EXPECT_LE(vec.val[1], colorThresholdLow);
|
|
EXPECT_LE(vec.val[2], colorThresholdLow);
|
|
}
|
|
}
|
|
|
|
const string exif_files[] =
|
|
{
|
|
#ifdef HAVE_JPEG
|
|
"readwrite/testExifOrientation_1.jpg",
|
|
"readwrite/testExifOrientation_2.jpg",
|
|
"readwrite/testExifOrientation_3.jpg",
|
|
"readwrite/testExifOrientation_4.jpg",
|
|
"readwrite/testExifOrientation_5.jpg",
|
|
"readwrite/testExifOrientation_6.jpg",
|
|
"readwrite/testExifOrientation_7.jpg",
|
|
"readwrite/testExifOrientation_8.jpg",
|
|
#endif
|
|
#ifdef OPENCV_IMGCODECS_PNG_WITH_EXIF
|
|
"readwrite/testExifOrientation_1.png",
|
|
"readwrite/testExifOrientation_2.png",
|
|
"readwrite/testExifOrientation_3.png",
|
|
"readwrite/testExifOrientation_4.png",
|
|
"readwrite/testExifOrientation_5.png",
|
|
"readwrite/testExifOrientation_6.png",
|
|
"readwrite/testExifOrientation_7.png",
|
|
"readwrite/testExifOrientation_8.png",
|
|
#endif
|
|
#ifdef HAVE_AVIF
|
|
"readwrite/testExifOrientation_1.avif",
|
|
"readwrite/testExifOrientation_2.avif",
|
|
"readwrite/testExifOrientation_3.avif",
|
|
"readwrite/testExifOrientation_4.avif",
|
|
"readwrite/testExifOrientation_5.avif",
|
|
"readwrite/testExifOrientation_6.avif",
|
|
"readwrite/testExifOrientation_7.avif",
|
|
"readwrite/testExifOrientation_8.avif",
|
|
#endif
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgcodecs, Exif,
|
|
testing::ValuesIn(exif_files));
|
|
|
|
}
|
|
}
|