You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python - cv2.resize with INTER_NEAREST return corrupted slice for channels > 4 #15075
OpenCV => 4.1.0
Operating System / Platform => Ubuntu 16.04.1, Linux 4.13.0
Python => 3.6.8
numpy => 1.16.4
Detailed description
cv2.resize with an array having a 3rd-dimension > 4 (must be an odd number) and nearest-neighbor interpolation returns corrupted data in the last channel. It is not deterministic and looks like memory corruption.
Steps to reproduce
importnumpyasnpimportcv2# up to DIM=4 is OKDIM=5T=np.zeros((12, 12,DIM)).astype(np.uint8)
T[2, 2, DIM-1] =1print("Sum: ", T.sum())
print(T[:, :, DIM-1])
R=cv2.resize(T, None, fx=0.9, fy=1,interpolation=cv2.INTER_NEAREST)
# it does not help to supply a pre-allocated array either#R = np.zeros((12, 11, DIM)).astype(np.uint8)#R = cv2.resize(T, dsize=R.shape[:2], dst=R, interpolation=cv2.INTER_NEAREST)print("Sum: ", R.sum())
print(R[:, :, DIM-1])
But I don't know how this change affect on other modules witch uses NN resize.
I create pull request to future investigate what it breaks or not. #16497
Activity
keeper121 commentedon Feb 3, 2020
Seems problem in resizeNNInvoker class with loop over image.
https://github.com/keeper121/opencv/blob/57c99914133bea42b1fd6e176ebf35e210d7163d/modules/imgproc/src/resize.cpp#L1044-L1050
The last array's dimension not going through the loop if it has odd size.
Potential fix is replace loop defenition with:
After that provided code works as expected.
Output:
But I don't know how this change affect on other modules witch uses NN resize.
I create pull request to future investigate what it breaks or not.
#16497