diff python/cvutils.py @ 895:739acd338cc0

added script to extract camera info from tacal file by Lund University (T analyst)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 01 Jun 2017 14:54:11 -0400
parents 0c1fed9e8862
children f5a49b603e8b
line wrap: on
line diff
--- a/python/cvutils.py	Thu Jun 01 10:33:07 2017 -0400
+++ b/python/cvutils.py	Thu Jun 01 14:54:11 2017 -0400
@@ -388,6 +388,14 @@
         H, mask = cv2.findHomography(array(srcPoints), array(dstPoints), method = 0) # No need for different methods for finding homography
         return H
 
+    def getIntrinsicCameraMatrix(cameraData):
+        return array([[cameraData['f']*cameraData['Sx']/cameraData['dx'], 0, cameraData['Cx']],
+                      [0, cameraData['f']/cameraData['dy'], cameraData['Cy']],
+                      [0, 0, 1.]])
+
+    def getDistortionCoefficients(cameraData):
+        return array([cameraData['k']]+4*[0])
+    
     def undistortedCoordinates(map1, map2, x, y, maxDistance = 1.):
         '''Returns the coordinates of a point in undistorted image
         map1 and map2 are the mapping functions from undistorted image
@@ -480,11 +488,11 @@
         ## Close up image loading and calibrate
         cv2.destroyAllWindows()
         if len(objpoints) == 0 or len(imgpoints) == 0: 
-            return False
+            return None
         try:
             ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
         except NameError:
-            return False
+            return None
         savetxt('intrinsic-camera.txt', camera_matrix)
         return camera_matrix, dist_coeffs