Mercurial > hg > nsaunier > traffic-intelligence
comparison python/calibration-translation.py @ 303:514f6b98cd8c
fixed bug with keys from waitKey on Ubuntu 12.10
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 21 Mar 2013 14:01:46 -0400 |
| parents | b0719b3ad3db |
| children |
comparison
equal
deleted
inserted
replaced
| 302:9d88a4d97473 | 303:514f6b98cd8c |
|---|---|
| 56 for f in filenames: | 56 for f in filenames: |
| 57 captures[f] = cv2.VideoCapture(f) | 57 captures[f] = cv2.VideoCapture(f) |
| 58 frameFilename = utils.removeExtension(f)+'-frame.png' # TODO if frame image already exists, no need to search for it again | 58 frameFilename = utils.removeExtension(f)+'-frame.png' # TODO if frame image already exists, no need to search for it again |
| 59 if not os.path.exists(frameFilename): | 59 if not os.path.exists(frameFilename): |
| 60 key = -1 | 60 key = -1 |
| 61 while key != cvutils.cvKeyNumbers['y']: | 61 while chr(key&255) != 'y': |
| 62 (ret, img) = captures[f].read() | 62 (ret, img) = captures[f].read() |
| 63 cv2.imshow('Image',img) | 63 cv2.imshow('Image',img) |
| 64 print('Can one see the reference points in the image? (y/n)') | 64 print('Can one see the reference points in the image? (y/n)') |
| 65 key = cv2.waitKey(0) | 65 key = cv2.waitKey(0) |
| 66 | 66 |
| 89 displayImg = cv2.cvtColor(images[filenames[i]], cv2.COLOR_GRAY2RGB) #.copy() | 89 displayImg = cv2.cvtColor(images[filenames[i]], cv2.COLOR_GRAY2RGB) #.copy() |
| 90 for p in imgPts: | 90 for p in imgPts: |
| 91 cv2.circle(displayImg, tuple(p+t[0]), 3, (255,0,0)) | 91 cv2.circle(displayImg, tuple(p+t[0]), 3, (255,0,0)) |
| 92 cv2.imshow('Image',displayImg) | 92 cv2.imshow('Image',displayImg) |
| 93 | 93 |
| 94 while not(key == cvutils.cvKeyNumbers['y'] or key == cvutils.cvKeyNumbers['n']): | 94 while not(chr(key&255) == 'y' or chr(key&255) == 'n'): |
| 95 print('Are the translated points rightly located (y/n)?') | 95 print('Are the translated points rightly located (y/n)?') |
| 96 key = cv2.waitKey(0) | 96 key = cv2.waitKey(0) |
| 97 if key == cvutils.cvKeyNumbers['y']: # compute homography with translated numbers | 97 if chr(key&255) == 'y': # compute homography with translated numbers |
| 98 newImgPts = np.array([p+t[0] for p in imgPts]) | 98 newImgPts = np.array([p+t[0] for p in imgPts]) |
| 99 else: | 99 else: |
| 100 print('No translation could be found automatically. You will have to manually input world reference points.') | 100 print('No translation could be found automatically. You will have to manually input world reference points.') |
| 101 | 101 |
| 102 if t==None or key != cvutils.cvKeyNumbers['y']:# if no translation could computed or it is not satisfactory | 102 if t==None or chr(key&255) != 'y':# if no translation could computed or it is not satisfactory |
| 103 print('Select the corresponding points in the same order as in the reference image') | 103 print('Select the corresponding points in the same order as in the reference image') |
| 104 plt.figure(1) | 104 plt.figure(1) |
| 105 plt.imshow(displayRef) | 105 plt.imshow(displayRef) |
| 106 plt.figure(2) | 106 plt.figure(2) |
| 107 plt.imshow(img) | 107 plt.imshow(img) |
