Mercurial Hosting > traffic-intelligence
diff python/cvutils.py @ 926:dbd81710d515
new feature tracking in image space with point undistortion
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 10 Jul 2017 18:04:41 -0400 |
parents | a71455bd8367 |
children | 063d1267585d |
line wrap: on
line diff
--- a/python/cvutils.py Mon Jul 10 01:38:12 2017 -0400 +++ b/python/cvutils.py Mon Jul 10 18:04:41 2017 -0400 @@ -122,9 +122,6 @@ def computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients): newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) - #newCameraMatrix = deepcopy(intrinsicCameraMatrix) - #newCameraMatrix[0,2] = newImgSize[0]/2. - #newCameraMatrix[1,2] = newImgSize[1]/2. newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True) return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), None, newCameraMatrix, newImgSize, cv2.CV_32FC1) @@ -432,7 +429,7 @@ invMap2[y,x] = res[1] return invMap1, invMap2 - def cameraIntrinsicCalibration(path, checkerBoardSize=[6,7], secondPassSearch=False, display=False): + def intrinsicCameraCalibration(path, checkerBoardSize=[6,7], secondPassSearch=False, display=False, fixK2 = True, fixK3 = True, zeroTangent = True): ''' Camera calibration searches through all the images (jpg or png) located in _path_ for matches to a checkerboard pattern of size checkboardSize. These images should all be of the same camera with the same resolution. @@ -491,10 +488,18 @@ if len(objpoints) == 0 or len(imgpoints) == 0: return None try: - ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None) + flags = 0 + if fixK2: + flags += cv2.cv.CV_CALIB_FIX_K2 + if fixK3: + flags += cv2.cv.CV_CALIB_FIX_K3 + if zeroTangent: + flags += cv2.cv.CV_CALIB_ZERO_TANGENT_DIST + ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None, flags = flags) except NameError: return None savetxt('intrinsic-camera.txt', camera_matrix) + print 'error: {}'.format(ret) return camera_matrix, dist_coeffs def undistortImage(img, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., interpolation=cv2.INTER_LINEAR):