Mercurial Hosting > traffic-intelligence
changeset 158:2d7c6d767a39
corrected and improved calibration-translation.py
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 09 Sep 2011 19:23:11 -0400 |
parents | 3aab19947a34 |
children | 115f7f90286d |
files | python/calibration-translation.py |
diffstat | 1 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/python/calibration-translation.py Thu Sep 08 19:25:02 2011 -0400 +++ b/python/calibration-translation.py Fri Sep 09 19:23:11 2011 -0400 @@ -13,10 +13,11 @@ # development for the data collected and stabilized by Paul in Summer 2011 # todo test other features -options = utils.parseCLIOptions('Program to re-calibrate an initial calibration based on point correspondences by adjusting the points to slightly different viewpoints, where all the points are still visible\n\nUsage: ', ['ref_video=', 'ref_homography=', 'ref_points='], sys.argv, ['mask_img=']) +options = utils.parseCLIOptions('Program to re-calibrate an initial calibration based on point correspondences by adjusting the points to slightly different viewpoints, where all the points are still visible\n\nUsage: ', ['ref_video=', 'ref_points='], sys.argv, ['mask_img=']) +#, 'ref_homography=' referenceVideoFilename=options['--ref_video']#'1440-1459_Mercalli.avi' -referenceHomographyFilename=options['--ref_homography']#'1440-1459_Mercalli-homography.txt' +#referenceHomographyFilename=options['--ref_homography']#'1440-1459_Mercalli-homography.txt' points = np.loadtxt(options['--ref_points'], dtype=np.float32) # '1440-1459_Mercalli-point-correspondences.txt' wldPts = points[:2,:].T imgPts = points[2:,:].T @@ -30,10 +31,10 @@ filenames = [f for f in utils.listfiles('.','avi')] # directory to examine should be current directory -referenceHomography = np.loadtxt(referenceHomographyFilename) +#referenceHomography = np.loadtxt(referenceHomographyFilename) referenceVideoIndex = filenames.index(referenceVideoFilename) -indices = set(range(len(filenames))) -indices.discard(referenceVideoIndex) +indices = set([1, 2, 3, 4, 5, 6, 7, 9, 10, 11])#set(range(len(filenames))) +#indices.discard(referenceVideoIndex) images = {} #features = {} @@ -55,9 +56,10 @@ cv2.putText(displayRef, str(j+1), tuple(p), cv2.FONT_HERSHEY_PLAIN, 1, (255,0,0)) cv2.imshow('Reference',displayRef) -key = -1 for f in filenames: # get suitable image references for each video captures[f] = cv2.VideoCapture(f) + # TODO if frame image already exists, no need to search for it again + key = -1 while key != cvutils.cvKeyNumbers['y']: (ret, img) = captures[f].read() cv2.imshow('Image',img) @@ -65,7 +67,7 @@ key = cv2.waitKey(0) images[f] = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) - cv2.imwrite(utils.removeExtension(filenames[i])+'-frame.png') + cv2.imwrite(utils.removeExtension(f)+'-frame.png', img) #images[f] = cv2.imread(f, cv2.CV_LOAD_IMAGE_GRAYSCALE) #features[f] = cv2.goodFeaturesToTrack(images[f], 1000, 0.02, 2, useHarrisDetector = True, mask=maskImg) # todo put parameters on the command line ? # goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]]) @@ -89,11 +91,11 @@ cv2.circle(displayImg, tuple(p+t[0]), 3, (255,0,0)) cv2.imshow('Image',displayImg) - while key != cvutils.cvKeyNumbers['y'] and key != cvutils.cvKeyNumbers['n']: + while not(key == cvutils.cvKeyNumbers['y'] or key == cvutils.cvKeyNumbers['n']): print('Are the translated points rightly located (y/n)?') key = cv2.waitKey(0) if key == cvutils.cvKeyNumbers['y']: # compute homography with translated numbers - newImgPts = [p+t[0] for p in imgPts] + newImgPts = np.array([p+t[0] for p in imgPts]) else: print('No translation could be found automatically. You will have to manually input world reference points.') @@ -111,6 +113,6 @@ homography, mask = cv2.findHomography(newImgPts, wldPts) # method=0, ransacReprojThreshold=3 print homography np.savetxt(utils.removeExtension(filenames[i])+'-homography.txt',homography) - np.savetxt(utils.removeExtension(filenames[i])+'-point-correspondences.txt', append(wldPts.T, newImgPts.T, axis=0)) + np.savetxt(utils.removeExtension(filenames[i])+'-point-correspondences.txt', np.append(wldPts.T, newImgPts.T, axis=0)) cv2.destroyAllWindows()