diff python/tests/cvutils.txt @ 932:66f382852e61

added new projection functions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 14 Jul 2017 00:12:03 -0400
parents 7db0f2853bfd
children 8ac7f61c6e4f
line wrap: on
line diff
--- a/python/tests/cvutils.txt	Thu Jul 13 00:52:53 2017 -0400
+++ b/python/tests/cvutils.txt	Fri Jul 14 00:12:03 2017 -0400
@@ -12,7 +12,7 @@
 True
 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]])
 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True)
->>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2)
+>>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) # undistort and project as if seen by new camera
 >>> invNewCameraMatrix = linalg.inv(newCameraMatrix)
 >>> tmp = ones((imgPoints[0].shape[0], 3))
 >>> tmp[:,:2] = undistortedPoints
@@ -22,8 +22,20 @@
 True
 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
 True
->>> origPoints = cvutils.projectArray(None, undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients, newCameraMatrix).T
+>>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix)
+>>> (reducedPoints == reducedPoints).all()
+True
+
+>>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points
+>>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T
 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
 True
 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
 True
+
+>>> undistortedPoints = cvutils.imageToWorldProject(imgPoints[0].T, intrinsicCameraMatrix, distortionCoefficients)
+>>> origPoints = cvutils.worldToImageProject(undistortedPoints, intrinsicCameraMatrix, distortionCoefficients).T
+>>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
+True
+>>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
+True