test_solvepnp.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. # Python 2/3 compatibility
  3. from __future__ import print_function
  4. import numpy as np
  5. import cv2 as cv
  6. from tests_common import NewOpenCVTests
  7. class solvepnp_test(NewOpenCVTests):
  8. def test_regression_16040(self):
  9. obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
  10. img_points = np.array(
  11. [[700, 400], [700, 600], [900, 600], [900, 400]], dtype=np.float32
  12. )
  13. cameraMatrix = np.array(
  14. [[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
  15. )
  16. distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
  17. r = np.array([], dtype=np.float32)
  18. x, r, t, e = cv.solvePnPGeneric(
  19. obj_points, img_points, cameraMatrix, distCoeffs, reprojectionError=r
  20. )
  21. def test_regression_16040_2(self):
  22. obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
  23. img_points = np.array(
  24. [[[700, 400], [700, 600], [900, 600], [900, 400]]], dtype=np.float32
  25. )
  26. cameraMatrix = np.array(
  27. [[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
  28. )
  29. distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
  30. r = np.array([], dtype=np.float32)
  31. x, r, t, e = cv.solvePnPGeneric(
  32. obj_points, img_points, cameraMatrix, distCoeffs, reprojectionError=r
  33. )
  34. def test_regression_16049(self):
  35. obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
  36. img_points = np.array(
  37. [[[700, 400], [700, 600], [900, 600], [900, 400]]], dtype=np.float32
  38. )
  39. cameraMatrix = np.array(
  40. [[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
  41. )
  42. distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
  43. x, r, t, e = cv.solvePnPGeneric(
  44. obj_points, img_points, cameraMatrix, distCoeffs
  45. )
  46. if e is None:
  47. # noArray() is supported, see https://github.com/opencv/opencv/issues/16049
  48. pass
  49. else:
  50. eDump = cv.utils.dumpInputArray(e)
  51. self.assertEqual(eDump, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=1 dims(-1)=2 size(-1)=1x1 type(-1)=CV_32FC1")
  52. if __name__ == '__main__':
  53. NewOpenCVTests.bootstrap()