comparison python/tests/cvutils.txt @ 933:8ac7f61c6e4f

major rework of homography calibration, no in ideal points if correcting for distortion
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 14 Jul 2017 02:11:21 -0400
parents 66f382852e61
children
comparison
equal deleted inserted replaced
932:66f382852e61 933:8ac7f61c6e4f
4 >>> width = img.shape[1] 4 >>> width = img.shape[1]
5 >>> height = img.shape[0] 5 >>> height = img.shape[0]
6 >>> intrinsicCameraMatrix = array([[ 377.42, 0. , 639.12], [ 0. , 378.43, 490.2 ], [ 0. , 0. , 1. ]]) 6 >>> intrinsicCameraMatrix = array([[ 377.42, 0. , 639.12], [ 0. , 378.43, 490.2 ], [ 0. , 0. , 1. ]])
7 >>> distortionCoefficients = array([-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816])# distortionCoefficients = array([-0.11759321, 0., 0., 0., 0.]) 7 >>> distortionCoefficients = array([-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816])# distortionCoefficients = array([-0.11759321, 0., 0., 0., 0.])
8 >>> multiplicationFactor = 1.31 8 >>> multiplicationFactor = 1.31
9 >>> [map1, map2] = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) 9 >>> [map1, map2], tmp = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients)
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)
24 True 24 True
25 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix) 25 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix)
26 >>> (reducedPoints == reducedPoints).all() 26 >>> (reducedPoints == reducedPoints).all()
27 True 27 True
28 28
29 >>> undistortedPoints2 = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort and project as if seen by new camera
30 >>> undistortedPoints2 = cvutils.newCameraProject(undistortedPoints2.T, newCameraMatrix)
31 >>> (undistortedPoints == undistortedPoints2.T).all()
32 True
33
29 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points 34 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points
30 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T 35 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T
31 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() 36 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
32 True 37 True
33 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. 38 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.