Fix NN resize with dimentions > 4#16497
Conversation
|
@keeper121 Thanks a lot for contribution! Could you add test for the case you've fixed? |
|
@asmorkalov Hi, what format the test case should look like? This bug comes from #15075. It has python script which do nearest neighbor resize. Output before: Output after fix: The PR fixes case when input image has odd size of channel dimension more than 4. It occurs in https://github.com/keeper121/opencv/blob/57c99914133bea42b1fd6e176ebf35e210d7163d/modules/imgproc/src/resize.cpp#L1044-L1050 where the last image's channel part is not going through the loop. |
|
c++ test with the test data you posted before is enough. |
|
Also you can extend existing C++ test for resize to case with 4 channels too. |
Separate test is better. |
|
@alalek Hi, I added separate test. I run it with: opencv_test_imgproc --gtest_filter=Resize_NN.accuracy output before fix output after fix Should I add something else? |
|
There are build warnings on Windows: Please take a look and fix. |
|
@keeper121 I checked branch 3.4 and the issue is reproducible there too. Could you rebease it on top of 3.4 and we will merge the changes from 3.4 into master during regular procedure (weekly/bi-weekly). So, please:
Note: no need to re-open PR, apply changes "inplace". |
| namespace opencv_test { namespace { | ||
|
|
||
| TEST(Resize_NN, accuracy) | ||
| { |
There was a problem hiding this comment.
No need to create a new file.
Please put code after this resize test: https://github.com/opencv/opencv/blob/4.2.0/modules/imgproc/test/test_imgwarp.cpp#L1403-L1414
Please add issue number into test name.
Please avoid indentation in namespaces.
| const int N = 10; | ||
| double scale_factor = 0.9; | ||
| int i1 = 5, j1 = 5; // position of pixel | ||
| for (int i = 2; i < N; ++i) |
There was a problem hiding this comment.
Please test 5 channels only.
Lets avoid overcomplicated tests.
| dst = dst.reshape(1, dst.cols * dst.rows * dst.channels()); | ||
| double sum = cv::sum(dst)[0]; | ||
| EXPECT_EQ(i, sum) << "Resize NN TEST mat from " << cols << "x" << rows << "x" << i << " failed with sum " << sum << " should be " << i; |
There was a problem hiding this comment.
3 lines alternative:
EXPECT_EQ(i, cvtest::norm(dst, NORM_L1)) << test.size;`
alalek
left a comment
There was a problem hiding this comment.
Well done! Thank you for contribution 👍
|
Fix has been reverted: #16600 |
|
@alalek How can I debug it? valgrind-3.15.0 on my Ubuntu 19.10 (g++ 7.5) is not showing any error. I'll try to fix it if it possible. |
* Fix NN resize with dimentions > 4 * add test check for nn resize with channels > 4 * Change types from float to double * Del unnecessary test file. Move nn test to test_imgwarp. Add 5 channels test only.
relates #15075
This pullrequest changes
This resolves issue #15075
Fixes NN resize image last dimension values with odd dims > 4.