Skip to content

Added resize flag handlers for imread and imdecode | Issue #16203#16309

Merged
alalek merged 2 commits intoopencv:3.4from
ganesh-k13:bugfix/imdecode-resize
Jan 20, 2020
Merged

Added resize flag handlers for imread and imdecode | Issue #16203#16309
alalek merged 2 commits intoopencv:3.4from
ganesh-k13:bugfix/imdecode-resize

Conversation

@ganesh-k13
Copy link
Copy Markdown
Contributor

@ganesh-k13 ganesh-k13 commented Jan 8, 2020

This pullrequest changes

  1. Added flag handler for imdecode which was the issue
  2. Take care of color resize cases
  3. Port changes to imread as well.

resolves #16203

force_builders=Win32

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Hi @sturkmen72, I have added the handlers as discussed. In addition to this I noticed that color resize was not taking place in case of imread, I fixed that as well.

@ganesh-k13 ganesh-k13 changed the title Added flag handlers for imread and imdecode | Issue #16203 Added resize flag handlers for imread and imdecode | Issue #16203 Jan 8, 2020
@sturkmen72
Copy link
Copy Markdown
Contributor

i believe your addition is not correct ( or unnecessary)

@sturkmen72
Copy link
Copy Markdown
Contributor

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Hi @sturkmen72 thanks for the response, so the addition to imread is not needed? Or even imdecode is not necessary? As mentioned in last comment, do I add that to imdecode?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Please add corresponding test for this feature - check that result image size is reduced properly.

@ganesh-k13 ganesh-k13 requested a review from alalek January 11, 2020 12:16
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Well done! Thank you 👍

@sturkmen72
Copy link
Copy Markdown
Contributor

imread manually resizes other formats than jpeg see https://github.com/opencv/opencv/blob/master/modules/imgcodecs/src/loadsave.cpp#L494-L497

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

@sturkmen72, thanks for that, shall I add that to imdecode as well as you showed earlier?

@alalek
Copy link
Copy Markdown
Member

alalek commented Jan 11, 2020

@ganesh-k13 Please fix warnings from Win32 builder (add static_cast<size_t>())

@sturkmen72
Copy link
Copy Markdown
Contributor

@alalek let me do some tests before merge

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

imread manually resizes other formats than jpeg see https://github.com/opencv/opencv/blob/master/modules/imgcodecs/src/loadsave.cpp#L494-L497

@sturkmen72, do we make this in a different PR, or shall I add it to imdecode now?

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Hey @sturkmen72 / @alalek, I'm getting cores if we add that if conditions and try other formats, if that if is not there then resize does not happen but no crash. It involves some work, can I raise a different PR for that, might involve more work. Please advise.

@ganesh-k13 ganesh-k13 requested a review from alalek January 13, 2020 05:27
@sturkmen72
Copy link
Copy Markdown
Contributor

you can add

    if( decoder->setScale( scale_denom ) > 1 ) // if decoder is JpegDecoder then decoder->setScale always returns 1
    {
        resize( mat, mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT);
    }
   decoder.release();

end of imdecode_
( delete decoder.release(); which located a few lines upper )

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Ohh thanks, I didn't see it was getting freed. I'll add that and test.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

@sturkmen72 thanks for the fix, it works. @alalek I have added a case for the same by resizing a PNG to hit that code path.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

@sturkmen72 / @alalek, any updates on this one? any changes needed?

@asmorkalov
Copy link
Copy Markdown
Contributor

Hello @ganesh-k13 The patch looks good to me. I can propose some test code enhancement: OpenCV TS module like Google Test supports parameterized tests (https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#value-parameterized-tests). It means that you can get rid of duplicated blocks of code and run the same test body for JPEG and other image formats. You can look on example in test_grfmt.cpp.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Thanks for the link @asmorkalov, I'll make those changes

@alalek
Copy link
Copy Markdown
Member

alalek commented Jan 16, 2020

Parametrized tests look like overkill here. Duplicated code and checks may be moved into common function, like this (important note, that return value should be 'void').

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Hi @alalek , @sturkmen72 , @asmorkalov, we can see that imread and imdecode have duplicate code in both test and src. I would suggest we make it a different PR as we have digressed from the initial issue. I can raise a new issue and PR for that.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Hi @alalek , @asmorkalov , I went ahead with refactor of tests anyways. I went with Value-Parameterized Tests as I wanted to try something new and it seems very well suited for our case. Please merge this PR if changes are satisfactory.

@asmorkalov
Copy link
Copy Markdown
Contributor

@ganesh-k13 Well done! Please squash your commits to have clean history and we can merge the patch. @alalek What do you think?

Undo imread change

Added Imread resize tests

Added imdecode flags check

Added imdecode tests for resize

Removed trailing whitespace

Removed IMREAD_IGNORE_ORIENTATION check

Added else condition

Removed IMREAD_IGNORE_ORIENTATION check in decode

Added HAVE_JPEG guards

Added static_cast for Win32

Added resize for non jpegs

Added tests for non jpeg resize case

Fixed resize value in assert

Changed tests to Value-Parameterized Tests

Changed tests to Value-Parameterized Tests | handled >> in cpp

Changed tests to Value-Parameterized Tests | removed trailing whitespace
@ganesh-k13 ganesh-k13 force-pushed the bugfix/imdecode-resize branch from 9f4e7ff to 3614b0b Compare January 17, 2020 11:22
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you!

@alalek alalek merged commit 80ade96 into opencv:3.4 Jan 20, 2020
@alalek alalek mentioned this pull request Jan 22, 2020
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.

4 participants