Skip to content

Commit 48a48fe

Browse files
committed
Enable PNG exif orientation test
1 parent 450e741 commit 48a48fe

File tree

6 files changed

+155
-229
lines changed

6 files changed

+155
-229
lines changed

modules/imgcodecs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ endif()
190190
if(TARGET opencv_test_imgcodecs AND HAVE_OPENEXR AND "$ENV{OPENCV_IO_ENABLE_OPENEXR}")
191191
ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_ENABLE_OPENEXR_TESTS=1)
192192
endif()
193-
if(TARGET opencv_test_imgcodecs AND ((HAVE_PNG AND NOT (PNG_VERSION VERSION_LESS "1.6.31")) OR HAVE_SPNG))
193+
if(TARGET opencv_test_imgcodecs AND ((HAVE_PNG AND NOT (PNG_VERSION_STRING VERSION_LESS "1.6.31")) OR HAVE_SPNG))
194194
# details: https://github.com/glennrp/libpng/commit/68cb0aaee3de6371b81a4613476d9b33e43e95b1
195195
ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_PNG_WITH_EXIF=1)
196196
endif()

modules/imgcodecs/src/loadsave.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ static Size validateInputImageSize(const Size& size)
8383

8484
static inline int calcType(int type, int flags)
8585
{
86+
if ( (flags & (IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH)) == (IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH))
87+
return type;
88+
8689
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
8790
{
8891
if( (flags & IMREAD_ANYDEPTH) == 0 )

modules/imgcodecs/test/test_avif.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -187,51 +187,6 @@ INSTANTIATE_TEST_CASE_P(
187187

188188
////////////////////////////////////////////////////////////////////////////////
189189

190-
typedef testing::TestWithParam<string> Imgcodecs_AVIF_Exif;
191-
192-
TEST_P(Imgcodecs_AVIF_Exif, exif_orientation) {
193-
const string root = cvtest::TS::ptr()->get_data_path();
194-
const string filename = root + GetParam();
195-
const int colorThresholdHigh = 250;
196-
const int colorThresholdLow = 5;
197-
198-
Mat m_img = imread(filename);
199-
ASSERT_FALSE(m_img.empty());
200-
Vec3b vec;
201-
202-
// Checking the first quadrant (with supposed red)
203-
vec = m_img.at<Vec3b>(2, 2); // some point inside the square
204-
EXPECT_LE(vec.val[0], colorThresholdLow);
205-
EXPECT_LE(vec.val[1], colorThresholdLow);
206-
EXPECT_GE(vec.val[2], colorThresholdHigh);
207-
208-
// Checking the second quadrant (with supposed green)
209-
vec = m_img.at<Vec3b>(2, 7); // some point inside the square
210-
EXPECT_LE(vec.val[0], colorThresholdLow);
211-
EXPECT_GE(vec.val[1], colorThresholdHigh);
212-
EXPECT_LE(vec.val[2], colorThresholdLow);
213-
214-
// Checking the third quadrant (with supposed blue)
215-
vec = m_img.at<Vec3b>(7, 2); // some point inside the square
216-
EXPECT_GE(vec.val[0], colorThresholdHigh);
217-
EXPECT_LE(vec.val[1], colorThresholdLow);
218-
EXPECT_LE(vec.val[2], colorThresholdLow);
219-
}
220-
221-
const string exif_files[] = {"readwrite/testExifOrientation_1.avif",
222-
"readwrite/testExifOrientation_2.avif",
223-
"readwrite/testExifOrientation_3.avif",
224-
"readwrite/testExifOrientation_4.avif",
225-
"readwrite/testExifOrientation_5.avif",
226-
"readwrite/testExifOrientation_6.avif",
227-
"readwrite/testExifOrientation_7.avif",
228-
"readwrite/testExifOrientation_8.avif"};
229-
230-
INSTANTIATE_TEST_CASE_P(ExifFiles, Imgcodecs_AVIF_Exif,
231-
testing::ValuesIn(exif_files));
232-
233-
////////////////////////////////////////////////////////////////////////////////
234-
235190
class Imgcodecs_Avif_Animation_RoundTripSuite
236191
: public Imgcodecs_Avif_RoundTripSuite {
237192
public:

modules/imgcodecs/test/test_exif.cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
}

modules/imgcodecs/test/test_jpeg.cpp

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,6 @@ extern "C" {
1111
#include "jpeglib.h"
1212
}
1313

14-
/**
15-
* Test for check whether reading exif orientation tag was processed successfully or not
16-
* The test info is the set of 8 images named testExifRotate_{1 to 8}.jpg
17-
* The test image is the square 10x10 points divided by four sub-squares:
18-
* (R corresponds to Red, G to Green, B to Blue, W to white)
19-
* --------- ---------
20-
* | R | G | | G | R |
21-
* |-------| - (tag 1) |-------| - (tag 2)
22-
* | B | W | | W | B |
23-
* --------- ---------
24-
*
25-
* --------- ---------
26-
* | W | B | | B | W |
27-
* |-------| - (tag 3) |-------| - (tag 4)
28-
* | G | R | | R | G |
29-
* --------- ---------
30-
*
31-
* --------- ---------
32-
* | R | B | | G | W |
33-
* |-------| - (tag 5) |-------| - (tag 6)
34-
* | G | W | | R | B |
35-
* --------- ---------
36-
*
37-
* --------- ---------
38-
* | W | G | | B | R |
39-
* |-------| - (tag 7) |-------| - (tag 8)
40-
* | B | R | | W | G |
41-
* --------- ---------
42-
*
43-
*
44-
* Every image contains exif field with orientation tag (0x112)
45-
* After reading each image the corresponding matrix must be read as
46-
* ---------
47-
* | R | G |
48-
* |-------|
49-
* | B | W |
50-
* ---------
51-
*
52-
*/
53-
54-
typedef testing::TestWithParam<string> Imgcodecs_Jpeg_Exif;
55-
56-
TEST_P(Imgcodecs_Jpeg_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-
Mat m_img = imread(filename);
64-
ASSERT_FALSE(m_img.empty());
65-
Vec3b vec;
66-
67-
//Checking the first quadrant (with supposed red)
68-
vec = m_img.at<Vec3b>(2, 2); //some point inside the square
69-
EXPECT_LE(vec.val[0], colorThresholdLow);
70-
EXPECT_LE(vec.val[1], colorThresholdLow);
71-
EXPECT_GE(vec.val[2], colorThresholdHigh);
72-
73-
//Checking the second quadrant (with supposed green)
74-
vec = m_img.at<Vec3b>(2, 7); //some point inside the square
75-
EXPECT_LE(vec.val[0], colorThresholdLow);
76-
EXPECT_GE(vec.val[1], colorThresholdHigh);
77-
EXPECT_LE(vec.val[2], colorThresholdLow);
78-
79-
//Checking the third quadrant (with supposed blue)
80-
vec = m_img.at<Vec3b>(7, 2); //some point inside the square
81-
EXPECT_GE(vec.val[0], colorThresholdHigh);
82-
EXPECT_LE(vec.val[1], colorThresholdLow);
83-
EXPECT_LE(vec.val[2], colorThresholdLow);
84-
}
85-
86-
const string exif_files[] =
87-
{
88-
"readwrite/testExifOrientation_1.jpg",
89-
"readwrite/testExifOrientation_2.jpg",
90-
"readwrite/testExifOrientation_3.jpg",
91-
"readwrite/testExifOrientation_4.jpg",
92-
"readwrite/testExifOrientation_5.jpg",
93-
"readwrite/testExifOrientation_6.jpg",
94-
"readwrite/testExifOrientation_7.jpg",
95-
"readwrite/testExifOrientation_8.jpg"
96-
};
97-
98-
INSTANTIATE_TEST_CASE_P(ExifFiles, Imgcodecs_Jpeg_Exif,
99-
testing::ValuesIn(exif_files));
100-
101-
//==================================================================================================
102-
10314
TEST(Imgcodecs_Jpeg, encode_empty)
10415
{
10516
cv::Mat img;

0 commit comments

Comments
 (0)