comparison 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
comparison
equal deleted inserted replaced
931:8148991b1dab 932:66f382852e61
10 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) 10 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
11 >>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all() 11 >>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all()
12 True 12 True
13 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]]) 13 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]])
14 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True) 14 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True)
15 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) 15 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) # undistort and project as if seen by new camera
16 >>> invNewCameraMatrix = linalg.inv(newCameraMatrix) 16 >>> invNewCameraMatrix = linalg.inv(newCameraMatrix)
17 >>> tmp = ones((imgPoints[0].shape[0], 3)) 17 >>> tmp = ones((imgPoints[0].shape[0], 3))
18 >>> tmp[:,:2] = undistortedPoints 18 >>> tmp[:,:2] = undistortedPoints
19 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T 19 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T
20 >>> origPoints = cv2.projectPoints(reducedPoints, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2) 20 >>> origPoints = cv2.projectPoints(reducedPoints, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2)
21 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() 21 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
22 True 22 True
23 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. 23 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
24 True 24 True
25 >>> origPoints = cvutils.projectArray(None, undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients, newCameraMatrix).T 25 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix)
26 >>> (reducedPoints == reducedPoints).all()
27 True
28
29 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points
30 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T
26 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() 31 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
27 True 32 True
28 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. 33 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
29 True 34 True
35
36 >>> undistortedPoints = cvutils.imageToWorldProject(imgPoints[0].T, intrinsicCameraMatrix, distortionCoefficients)
37 >>> origPoints = cvutils.worldToImageProject(undistortedPoints, intrinsicCameraMatrix, distortionCoefficients).T
38 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
39 True
40 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
41 True