Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/tests/cvutils.txt @ 1287:76f5693b530c
updated tests for numpy 2
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sat, 20 Jul 2024 20:35:21 -0400 |
| parents | aafbc0bab925 |
| children |
comparison
equal
deleted
inserted
replaced
| 1284:8e30c9a6ac6f | 1287:76f5693b530c |
|---|---|
| 8 >>> distortionCoefficients = array([-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816])# distortionCoefficients = array([-0.11759321, 0., 0., 0., 0.]) | 8 >>> distortionCoefficients = array([-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816])# distortionCoefficients = array([-0.11759321, 0., 0., 0., 0.]) |
| 9 >>> multiplicationFactor = 1.31 | 9 >>> multiplicationFactor = 1.31 |
| 10 >>> [map1, map2], tmp = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) | 10 >>> [map1, map2], tmp = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) |
| 11 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) | 11 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) |
| 12 >>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all() | 12 >>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all() |
| 13 True | 13 np.True_ |
| 14 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]]) | 14 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]]) |
| 15 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True) | 15 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True) |
| 16 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) # undistort and project as if seen by new camera | 16 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) # undistort and project as if seen by new camera |
| 17 >>> invNewCameraMatrix = linalg.inv(newCameraMatrix) | 17 >>> invNewCameraMatrix = linalg.inv(newCameraMatrix) |
| 18 >>> tmp = ones((imgPoints[0].shape[0], 3)) | 18 >>> tmp = ones((imgPoints[0].shape[0], 3)) |
| 19 >>> tmp[:,:2] = undistortedPoints | 19 >>> tmp[:,:2] = undistortedPoints |
| 20 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T | 20 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T |
| 21 >>> origPoints = cv2.projectPoints(reducedPoints, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2) | 21 >>> origPoints = cv2.projectPoints(reducedPoints, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2) |
| 22 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() | 22 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() |
| 23 True | 23 np.True_ |
| 24 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. | 24 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. |
| 25 True | 25 np.True_ |
| 26 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix) | 26 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix) |
| 27 >>> (reducedPoints == reducedPoints).all() | 27 >>> (reducedPoints == reducedPoints).all() |
| 28 True | 28 np.True_ |
| 29 | 29 |
| 30 >>> undistortedPoints2 = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort and project as if seen by new camera | 30 >>> undistortedPoints2 = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort and project as if seen by new camera |
| 31 >>> undistortedPoints2 = cvutils.newCameraProject(undistortedPoints2.T, newCameraMatrix) | 31 >>> undistortedPoints2 = cvutils.newCameraProject(undistortedPoints2.T, newCameraMatrix) |
| 32 >>> (undistortedPoints == undistortedPoints2.T).all() | 32 >>> (undistortedPoints == undistortedPoints2.T).all() |
| 33 True | 33 np.True_ |
| 34 | 34 |
| 35 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points | 35 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points |
| 36 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T | 36 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T |
| 37 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() | 37 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() |
| 38 True | 38 np.True_ |
| 39 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. | 39 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. |
| 40 True | 40 np.True_ |
| 41 | 41 |
| 42 >>> undistortedPoints = cvutils.imageToWorldProject(imgPoints[0].T, intrinsicCameraMatrix, distortionCoefficients) | 42 >>> undistortedPoints = cvutils.imageToWorldProject(imgPoints[0].T, intrinsicCameraMatrix, distortionCoefficients) |
| 43 >>> origPoints = cvutils.worldToImageProject(undistortedPoints, intrinsicCameraMatrix, distortionCoefficients).T | 43 >>> origPoints = cvutils.worldToImageProject(undistortedPoints, intrinsicCameraMatrix, distortionCoefficients).T |
| 44 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() | 44 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() |
| 45 True | 45 np.True_ |
| 46 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. | 46 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. |
| 47 True | 47 np.True_ |
