test_rgbd.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # Python 2/3 compatibility
  3. from __future__ import print_function
  4. import os, numpy
  5. import cv2 as cv
  6. from tests_common import NewOpenCVTests
  7. class rgbd_test(NewOpenCVTests):
  8. def test_computeRgbdPlane(self):
  9. depth_image = self.get_sample('/cv/rgbd/depth.png', cv.IMREAD_ANYDEPTH)
  10. if depth_image is None:
  11. raise unittest.SkipTest("Missing files with test data")
  12. K = numpy.array([[525, 0, 320.5], [0, 525, 240.5], [0, 0, 1]])
  13. points3d = cv.rgbd.depthTo3d(depth_image, K)
  14. normals_computer = normals_computer = cv.rgbd.RgbdNormals_create(480, 640, 5, K)
  15. normals = normals_computer.apply(points3d)
  16. rgbd_plane = cv.rgbd.RgbdPlane_create(cv.rgbd.RgbdPlane_RGBD_PLANE_METHOD_DEFAULT, 40, 1600, 0.01, 0, 0, 0)
  17. _, planes_coeff = rgbd_plane.apply(points3d, normals)
  18. planes_coeff_expected = \
  19. numpy.asarray([[[-0.02447728, -0.8678335 , -0.49625182, 4.02800846]],
  20. [[-0.05055107, -0.86144137, -0.50533485, 3.95456314]],
  21. [[-0.03294908, -0.86964548, -0.49257591, 3.97052431]],
  22. [[-0.02886586, -0.87153459, -0.48948362, 7.77550507]],
  23. [[-0.04455929, -0.87659335, -0.47916424, 3.93200684]],
  24. [[-0.21514639, 0.18835169, -0.95824611, 7.59479475]],
  25. [[-0.01006953, -0.86679155, -0.49856904, 4.01355648]],
  26. [[-0.00876531, -0.87571168, -0.48275498, 3.96768975]],
  27. [[-0.06395926, -0.86951321, -0.48975089, 4.08618736]],
  28. [[-0.01403128, -0.87593341, -0.48222789, 7.74559402]],
  29. [[-0.01143177, -0.87495202, -0.4840748 , 7.75355816]]],
  30. dtype=numpy.float32)
  31. eps = 0.05
  32. self.assertLessEqual(cv.norm(planes_coeff, planes_coeff_expected, cv.NORM_L2), eps)
  33. if __name__ == '__main__':
  34. NewOpenCVTests.bootstrap()