|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level |
| 3 | +// directory of this distribution and at http://opencv.org/license.html |
| 4 | + |
| 5 | +#include "test_precomp.hpp" |
| 6 | + |
| 7 | +namespace opencv_test { namespace { |
| 8 | + |
| 9 | +/** |
| 10 | + * Test to check whether the EXIF orientation tag was processed successfully or not. |
| 11 | + * The test uses a set of 8 images named testExifOrientation_{1 to 8}.(extension). |
| 12 | + * Each test image is a 10x10 square, divided into four smaller sub-squares: |
| 13 | + * (R corresponds to Red, G to Green, B to Blue, W to White) |
| 14 | + * --------- --------- |
| 15 | + * | R | G | | G | R | |
| 16 | + * |-------| - (tag 1) |-------| - (tag 2) |
| 17 | + * | B | W | | W | B | |
| 18 | + * --------- --------- |
| 19 | + * |
| 20 | + * --------- --------- |
| 21 | + * | W | B | | B | W | |
| 22 | + * |-------| - (tag 3) |-------| - (tag 4) |
| 23 | + * | G | R | | R | G | |
| 24 | + * --------- --------- |
| 25 | + * |
| 26 | + * --------- --------- |
| 27 | + * | R | B | | G | W | |
| 28 | + * |-------| - (tag 5) |-------| - (tag 6) |
| 29 | + * | G | W | | R | B | |
| 30 | + * --------- --------- |
| 31 | + * |
| 32 | + * --------- --------- |
| 33 | + * | W | G | | B | R | |
| 34 | + * |-------| - (tag 7) |-------| - (tag 8) |
| 35 | + * | B | R | | W | G | |
| 36 | + * --------- --------- |
| 37 | + * |
| 38 | + * |
| 39 | + * Each image contains an EXIF field with an orientation tag (0x112). |
| 40 | + * After reading each image and applying the orientation tag, |
| 41 | + * the resulting image should be: |
| 42 | + * --------- |
| 43 | + * | R | G | |
| 44 | + * |-------| |
| 45 | + * | B | W | |
| 46 | + * --------- |
| 47 | + * |
| 48 | + * Note: |
| 49 | + * The flags parameter of the imread function is set as IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH. |
| 50 | + * Using this combination is an undocumented trick to load images similarly to the IMREAD_UNCHANGED flag, |
| 51 | + * preserving the alpha channel (if present) while also applying the orientation. |
| 52 | + */ |
| 53 | + |
| 54 | +typedef testing::TestWithParam<string> Exif; |
| 55 | + |
| 56 | +TEST_P(Exif, exif_orientation) |
| 57 | +{ |
| 58 | + const string root = cvtest::TS::ptr()->get_data_path(); |
| 59 | + const string filename = root + GetParam(); |
| 60 | + const int colorThresholdHigh = 250; |
| 61 | + const int colorThresholdLow = 5; |
| 62 | + |
| 63 | + // Refer to the note in the explanation above. |
| 64 | + Mat m_img = imread(filename, IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH); |
| 65 | + ASSERT_FALSE(m_img.empty()); |
| 66 | + |
| 67 | + if (m_img.channels() == 3) |
| 68 | + { |
| 69 | + Vec3b vec; |
| 70 | + |
| 71 | + //Checking the first quadrant (with supposed red) |
| 72 | + vec = m_img.at<Vec3b>(2, 2); //some point inside the square |
| 73 | + EXPECT_LE(vec.val[0], colorThresholdLow); |
| 74 | + EXPECT_LE(vec.val[1], colorThresholdLow); |
| 75 | + EXPECT_GE(vec.val[2], colorThresholdHigh); |
| 76 | + |
| 77 | + //Checking the second quadrant (with supposed green) |
| 78 | + vec = m_img.at<Vec3b>(2, 7); //some point inside the square |
| 79 | + EXPECT_LE(vec.val[0], colorThresholdLow); |
| 80 | + EXPECT_GE(vec.val[1], colorThresholdHigh); |
| 81 | + EXPECT_LE(vec.val[2], colorThresholdLow); |
| 82 | + |
| 83 | + //Checking the third quadrant (with supposed blue) |
| 84 | + vec = m_img.at<Vec3b>(7, 2); //some point inside the square |
| 85 | + EXPECT_GE(vec.val[0], colorThresholdHigh); |
| 86 | + EXPECT_LE(vec.val[1], colorThresholdLow); |
| 87 | + EXPECT_LE(vec.val[2], colorThresholdLow); |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + Vec4b vec; |
| 92 | + |
| 93 | + //Checking the first quadrant (with supposed red) |
| 94 | + vec = m_img.at<Vec4b>(2, 2); //some point inside the square |
| 95 | + EXPECT_LE(vec.val[0], colorThresholdLow); |
| 96 | + EXPECT_LE(vec.val[1], colorThresholdLow); |
| 97 | + EXPECT_GE(vec.val[2], colorThresholdHigh); |
| 98 | + |
| 99 | + //Checking the second quadrant (with supposed green) |
| 100 | + vec = m_img.at<Vec4b>(2, 7); //some point inside the square |
| 101 | + EXPECT_LE(vec.val[0], colorThresholdLow); |
| 102 | + EXPECT_GE(vec.val[1], colorThresholdHigh); |
| 103 | + EXPECT_LE(vec.val[2], colorThresholdLow); |
| 104 | + |
| 105 | + //Checking the third quadrant (with supposed blue) |
| 106 | + vec = m_img.at<Vec4b>(7, 2); //some point inside the square |
| 107 | + EXPECT_GE(vec.val[0], colorThresholdHigh); |
| 108 | + EXPECT_LE(vec.val[1], colorThresholdLow); |
| 109 | + EXPECT_LE(vec.val[2], colorThresholdLow); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +const string exif_files[] = |
| 114 | +{ |
| 115 | +#ifdef HAVE_JPEG |
| 116 | + "readwrite/testExifOrientation_1.jpg", |
| 117 | + "readwrite/testExifOrientation_2.jpg", |
| 118 | + "readwrite/testExifOrientation_3.jpg", |
| 119 | + "readwrite/testExifOrientation_4.jpg", |
| 120 | + "readwrite/testExifOrientation_5.jpg", |
| 121 | + "readwrite/testExifOrientation_6.jpg", |
| 122 | + "readwrite/testExifOrientation_7.jpg", |
| 123 | + "readwrite/testExifOrientation_8.jpg", |
| 124 | +#endif |
| 125 | +#ifdef OPENCV_IMGCODECS_PNG_WITH_EXIF |
| 126 | + "readwrite/testExifOrientation_1.png", |
| 127 | + "readwrite/testExifOrientation_2.png", |
| 128 | + "readwrite/testExifOrientation_3.png", |
| 129 | + "readwrite/testExifOrientation_4.png", |
| 130 | + "readwrite/testExifOrientation_5.png", |
| 131 | + "readwrite/testExifOrientation_6.png", |
| 132 | + "readwrite/testExifOrientation_7.png", |
| 133 | + "readwrite/testExifOrientation_8.png", |
| 134 | +#endif |
| 135 | +#ifdef HAVE_AVIF |
| 136 | + "readwrite/testExifOrientation_1.avif", |
| 137 | + "readwrite/testExifOrientation_2.avif", |
| 138 | + "readwrite/testExifOrientation_3.avif", |
| 139 | + "readwrite/testExifOrientation_4.avif", |
| 140 | + "readwrite/testExifOrientation_5.avif", |
| 141 | + "readwrite/testExifOrientation_6.avif", |
| 142 | + "readwrite/testExifOrientation_7.avif", |
| 143 | + "readwrite/testExifOrientation_8.avif", |
| 144 | +#endif |
| 145 | +}; |
| 146 | + |
| 147 | +INSTANTIATE_TEST_CASE_P(Imgcodecs, Exif, |
| 148 | + testing::ValuesIn(exif_files)); |
| 149 | + |
| 150 | +} |
| 151 | +} |
0 commit comments