Mercurial Hosting > traffic-intelligence
changeset 1166:7b4d732f82b3
adding an option to use image coordinates in point-correspondence file when undistorting
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 10 Jun 2021 23:51:42 -0400 |
parents | c5863e04d302 |
children | f67b4f892195 |
files | scripts/compute-homography.py |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/compute-homography.py Mon Apr 12 15:19:23 2021 -0400 +++ b/scripts/compute-homography.py Thu Jun 10 23:51:42 2021 -0400 @@ -15,8 +15,10 @@ - the first two lines are the x and y coordinates in the projected space (usually world space) - the last two lines are the x and y coordinates in the origin space (usually image space) +Image space is in ideal point space (no camera) if undistorting the camera + If providing video and world images, with a number of points to input -and a ration to convert pixels to world distance unit (eg meters per pixel), +and a ratio to convert pixels to world distance unit (eg meters per pixel), the images will be shown in turn and the user should click in the same order the corresponding points in world and image spaces.''', formatter_class=argparse.RawDescriptionHelpFormatter) @@ -31,7 +33,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, default = 1.) -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('--correspondences-imagepoints-in-image-space', dest = 'correspondencesImagePointsInImageSpace', help = 'if image points are provided in the actual image space (before undistortion)', 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() @@ -39,6 +42,8 @@ homography = np.array([]) if args.pointCorrespondencesFilename is not None: worldPts, videoPts = cvutils.loadPointCorrespondences(args.pointCorrespondencesFilename) + if args.correspondencesImagePointsInImageSpace: + videoPts = cv2.undistortPoints(videoPts.T, np.loadtxt(args.intrinsicCameraMatrixFilename), np.array(args.distortionCoefficients)).reshape(-1,2) homography, mask = cv2.findHomography(videoPts, worldPts) # method=0, ransacReprojThreshold=3 elif args.tsaiCameraFilename is not None: # hack using PDTV from pdtv import TsaiCamera