changeset 538:bd1ad468e928

corrected bug and added capability to save undistorted image
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 03 Jul 2014 13:57:32 -0400
parents 6c264b914846
children 53587cc86f7d 6c0923f1ce68
files python/cvutils.py scripts/compute-homography.py
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/python/cvutils.py	Wed Jul 02 17:43:16 2014 -0400
+++ b/python/cvutils.py	Thu Jul 03 13:57:32 2014 -0400
@@ -144,7 +144,7 @@
                     key = cv2.waitKey(wait)
             cv2.destroyAllWindows()
         else:
-            print('Video capture for {} failed'.format(videoFilename))
+            print('Video capture for {} failed'.format(filename))
 
     def getImagesFromVideo(videoFilename, firstFrameNum = 0, nFrames = 1, saveImage = False, outputPrefix = 'image'):
         '''Returns nFrames images from the video sequence'''
--- a/scripts/compute-homography.py	Wed Jul 02 17:43:16 2014 -0400
+++ b/scripts/compute-homography.py	Thu Jul 03 13:57:32 2014 -0400
@@ -28,7 +28,8 @@
 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float)
-parser.add_argument('--undistort', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true')
+parser.add_argument('--undistort', dest = 'undistort', help = 'undistort the video (because features have been extracted that way', action = 'store_true')
+parser.add_argument('--save', dest = 'saveImages', help = 'save the undistorted video frame (display option must be chosen)', action = 'store_true')
 
 args = parser.parse_args()
 
@@ -108,6 +109,8 @@
     if args.undistort:        
         [map1, map2] = cvutils.computeUndistortMaps(videoImg.shape[1], videoImg.shape[0], args.undistortedImageMultiplication, np.loadtxt(args.intrinsicCameraMatrixFilename), args.distortionCoefficients)
         videoImg = cv2.remap(videoImg, map1, map2, interpolation=cv2.INTER_LINEAR)
+        if args.saveImages:
+            cv2.imwrite(utils.removeExtension(args.videoFrameFilename)+'-undistorted.png', videoImg)
     invHomography = np.linalg.inv(homography)
     projectedWorldPts = cvutils.projectArray(invHomography, worldPts.T).T
     projectedVideoPts = cvutils.projectArray(homography, videoPts.T).T