Skip to content

Enable PNG exif orientation test#26181

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
sturkmen72:png_exif_test
Nov 13, 2024
Merged

Enable PNG exif orientation test#26181
asmorkalov merged 1 commit intoopencv:4.xfrom
sturkmen72:png_exif_test

Conversation

@sturkmen72
Copy link
Copy Markdown
Contributor

Pull Request Readiness Checklist

related to #23122

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@sturkmen72
Copy link
Copy Markdown
Contributor Author

sturkmen72 commented Sep 23, 2024

RFC :
IMREAD_UNCHANGED_APPLY_EXIF = 7 this means IMREAD_COLOR | IMREAD_ANYCOLOR | IMREAD_ANYDEPTH but i think we can use it.
another option:
IMREAD_UNCHANGED_APPLY_EXIF = 512
or any suggestion

.
.
using
~cv::IMREAD_IGNORE_ORIENTATION suggested before by @vrabaud. this maybe better than adding a new flag ?

EXPECT_LE(vec.val[1], colorThresholdLow);
EXPECT_LE(vec.val[2], colorThresholdLow);

m_img = imread(filename, IMREAD_ADD_ALPHA);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test itself is still disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when

m_img = imread(filename, IMREAD_ANYCOLOR);

    ASSERT_FALSE(m_img.empty());

    EXPECT_EQ(4, m_img.channels());

**the test fails **

[----------] 8 tests from ExifFiles/Imgcodecs_PNG_Exif
[ RUN ] ExifFiles/Imgcodecs_PNG_Exif.exif_orientation/0, where GetParam() = "readwrite/testExifOrientation_1.png"
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(191): error: Expected equality of these values:
4
m_img.channels()
Which is: 3
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(196): error: Expected: (vec4.val[0]) <= (colorThresholdLow), actual: '\xFE' (254) vs 5
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(198): error: Expected: (vec4.val[2]) >= (colorThresholdHigh), actual: '\0' vs 250
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(202): error: Expected: (vec4.val[0]) <= (colorThresholdLow), actual: '\xFF' (255) vs 5
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(203): error: Expected: (vec4.val[1]) >= (colorThresholdHigh), actual: '\0' vs 250
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(208): error: Expected: (vec4.val[0]) >= (colorThresholdHigh), actual: '\x2' (2) vs 250
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(209): error: Expected: (vec4.val[1]) <= (colorThresholdLow), actual: '\xFD' (253) vs 5
[ FAILED ] ExifFiles/Imgcodecs_PNG_Exif.exif_orientation/0, where GetParam() = "readwrite/testExifOrientation_1.png" (2 ms)
[ RUN ] ExifFiles/Imgcodecs_PNG_Exif.exif_orientation/1, where GetParam() = "readwrite/testExifOrientation_2.png"
C:\build\precommit_windows64\4.x\opencv\modules\imgcodecs\test\test_png.cpp(191): error: Expected equality of these values:
4
m_img.channels()
Which is: 3


static inline int calcType(int type, int flags)
{
if (flags == IMREAD_ADD_ALPHA)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is cv::IMREAD_ANYCOLOR option. It should presume alpha channel, if it's present in the original image.

Copy link
Copy Markdown
Contributor Author

@sturkmen72 sturkmen72 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the issues #22090 #21695 related cv::IMREAD_ANYCOLOR

@sturkmen72 sturkmen72 changed the title WIP: Enable PNG exif orientation test Enable PNG exif orientation test Sep 29, 2024
@sturkmen72
Copy link
Copy Markdown
Contributor Author

as stated in the test code

 * 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.

I think this is acceptable until something better is done.
I can add a new flag, but I think it would be better if it did not appear in the documentation for a while.

@asmorkalov asmorkalov self-assigned this Nov 13, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Nov 13, 2024
Comment on lines +49 to +52
* 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.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to add it to documentation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants