Mercurial > hg > nsaunier > traffic-intelligence
diff scripts/compute-homography.py @ 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 | b0dac840c24f |
| children | 9c429c7efe89 |
line wrap: on
line diff
--- 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
