Mercurial Hosting > traffic-intelligence
comparison python/tests/cvutils.txt @ 930:7db0f2853bfd
corrected projection back to image space
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 13 Jul 2017 00:31:54 -0400 |
parents | be28a3538dc9 |
children | 66f382852e61 |
comparison
equal
deleted
inserted
replaced
929:be28a3538dc9 | 930:7db0f2853bfd |
---|---|
1 >>> import cv2, cvutils | 1 >>> import cv2, cvutils |
2 >>> from numpy import array, round, ones | 2 >>> from numpy import array, round, ones, dot, linalg, absolute |
3 >>> img = cv2.imread("../samples/val-dor-117-111.png") | 3 >>> img = cv2.imread("../samples/val-dor-117-111.png") |
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]) | 7 >>> 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., 0., 0., 0.]) | |
9 >>> multiplicationFactor = 1.31 | 8 >>> multiplicationFactor = 1.31 |
10 >>> [map1, map2] = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) | 9 >>> [map1, map2] = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) |
11 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) | 10 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) |
12 >>> (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() |
13 True | 12 True |
14 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]]) | 13 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]]) |
15 >>> 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) |
16 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) | 15 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) |
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 >>> origPoints = cv2.projectPoints(tmp, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2) | 19 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T |
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() | |
22 True | |
23 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. | |
24 True | |
25 >>> origPoints = cvutils.projectArray(None, undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients, newCameraMatrix).T | |
26 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all() | |
27 True | |
28 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6. | |
29 True |