mirror of
https://github.com/opencv/opencv.git
synced 2026-11-14 12:18:09 -06:00
drop ND prefix from the functions - #30207 Merge pull request #30207 from abhishek-gola:core-drop-nd-suffix ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] 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 - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
#!/usr/bin/env python
|
|
'''
|
|
Binding coverage for the n-dimensional transpose, split, repeat, concat, slice and flipND,
|
|
including the overloads that share a name with the older 2D functions.
|
|
'''
|
|
|
|
import numpy as np
|
|
import cv2 as cv
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
|
|
class nd_transform_test(NewOpenCVTests):
|
|
|
|
def nd(self, shape, dtype=np.float32):
|
|
return cv.Mat(np.arange(np.prod(shape), dtype=dtype).reshape(shape), wrap_channels=False)
|
|
|
|
def test_transpose(self):
|
|
a = np.arange(12, dtype=np.float32).reshape(3, 4)
|
|
self.assertEqual(cv.norm(cv.transpose(a), a.T, cv.NORM_INF), 0)
|
|
|
|
b = self.nd((2, 3, 4))
|
|
expected = np.transpose(b, (2, 0, 1))
|
|
np.testing.assert_array_equal(cv.transpose(b, [2, 0, 1]), expected)
|
|
np.testing.assert_array_equal(cv.transposeND(b, [2, 0, 1]), expected)
|
|
|
|
def test_split(self):
|
|
img = np.arange(24, dtype=np.uint8).reshape(2, 4, 3)
|
|
channels = cv.split(img)
|
|
self.assertEqual(len(channels), 3)
|
|
for c in range(3):
|
|
np.testing.assert_array_equal(channels[c], img[:, :, c])
|
|
|
|
b = self.nd((2, 6, 4))
|
|
parts = cv.split(b, 1, [2, 4])
|
|
self.assertEqual(len(parts), 2)
|
|
np.testing.assert_array_equal(parts[0], b[:, :2])
|
|
np.testing.assert_array_equal(parts[1], b[:, 2:])
|
|
np.testing.assert_array_equal(cv.concat(parts, 1), b)
|
|
|
|
def test_repeat(self):
|
|
a = np.arange(6, dtype=np.float32).reshape(2, 3)
|
|
np.testing.assert_array_equal(cv.repeat(a, 2, 3), np.tile(a, (2, 3)))
|
|
|
|
b = self.nd((2, 3, 4))
|
|
np.testing.assert_array_equal(cv.repeat(b, [1, 2, 3]), np.tile(b, (1, 2, 3)))
|
|
|
|
def test_slice(self):
|
|
b = self.nd((4, 9, 5))
|
|
np.testing.assert_array_equal(cv.slice(b, [0, 8], [4, -1], [1, -1]), b[:, ::-1])
|
|
|
|
def test_flip(self):
|
|
a = np.arange(12, dtype=np.float32).reshape(3, 4)
|
|
np.testing.assert_array_equal(cv.flip(a, -1), a[::-1, ::-1])
|
|
np.testing.assert_array_equal(cv.flip(a, 0), a[::-1])
|
|
np.testing.assert_array_equal(cv.flip(a, 1), a[:, ::-1])
|
|
np.testing.assert_array_equal(cv.flipND(a, -1), a[:, ::-1])
|
|
|
|
b = self.nd((2, 3, 4))
|
|
np.testing.assert_array_equal(cv.flipND(b, 0), b[::-1])
|
|
np.testing.assert_array_equal(cv.flipND(b, -1), b[..., ::-1])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
NewOpenCVTests.bootstrap()
|