Mercurial Hosting > traffic-intelligence
diff python/tests/cvutils.txt @ 929:be28a3538dc9
work in progress on projection
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 12 Jul 2017 18:00:53 -0400 |
parents | 52aa03260f03 |
children | 7db0f2853bfd |
line wrap: on
line diff
--- a/python/tests/cvutils.txt Wed Jul 12 01:24:31 2017 -0400 +++ b/python/tests/cvutils.txt Wed Jul 12 18:00:53 2017 -0400 @@ -1,10 +1,19 @@ >>> import cv2, cvutils ->>> from numpy import array, round +>>> from numpy import array, round, ones >>> img = cv2.imread("../samples/val-dor-117-111.png") >>> width = img.shape[1] >>> height = img.shape[0] >>> intrinsicCameraMatrix = array([[ 377.42, 0. , 639.12], [ 0. , 378.43, 490.2 ], [ 0. , 0. , 1. ]]) ->>> [map1, map2] = cvutils.computeUndistortMaps(width, height, 1.31, intrinsicCameraMatrix, [-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816]) +>>> distortionCoefficients = array([-0.11759321, 0.0148536, 0.00030756, -0.00020578, -0.00091816]) +>>> distortionCoefficients = array([-0.11759321, 0., 0., 0., 0.]) +>>> multiplicationFactor = 1.31 +>>> [map1, map2] = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients) >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) ->>> (undistorted.shape == array([int(round(height*1.31)), int(round(width*1.31)), 3])).all() +>>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all() 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) +>>> tmp = ones((imgPoints[0].shape[0], 3)) +>>> tmp[:,:2] = undistortedPoints +>>> origPoints = cv2.projectPoints(tmp, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2)