changeset 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 9d88a4d97473
children 20f9cd972dde
files python/calibration-translation.py python/cvutils.py python/display-trajectories.py
diffstat 2 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/python/calibration-translation.py	Mon Mar 18 23:37:45 2013 -0400
+++ b/python/calibration-translation.py	Thu Mar 21 14:01:46 2013 -0400
@@ -58,7 +58,7 @@
     frameFilename = utils.removeExtension(f)+'-frame.png' # TODO if frame image already exists, no need to search for it again
     if not os.path.exists(frameFilename):
         key = -1
-        while key != cvutils.cvKeyNumbers['y']:
+        while chr(key&255) != 'y':
             (ret, img) = captures[f].read()
             cv2.imshow('Image',img)
             print('Can one see the reference points in the image? (y/n)')
@@ -91,15 +91,15 @@
             cv2.circle(displayImg, tuple(p+t[0]), 3, (255,0,0))
         cv2.imshow('Image',displayImg)
 
-        while not(key == cvutils.cvKeyNumbers['y'] or key == cvutils.cvKeyNumbers['n']):
+        while not(chr(key&255) == 'y' or chr(key&255) == 'n'):
             print('Are the translated points rightly located (y/n)?')
             key = cv2.waitKey(0)
-        if key == cvutils.cvKeyNumbers['y']: # compute homography with translated numbers
+        if chr(key&255) == 'y': # compute homography with translated numbers
             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.')
 
-    if t==None or key != cvutils.cvKeyNumbers['y']:# if no translation could computed or it is not satisfactory
+    if t==None or chr(key&255) != 'y':# if no translation could computed or it is not satisfactory
         print('Select the corresponding points in the same order as in the reference image')
         plt.figure(1)
         plt.imshow(displayRef)
--- a/python/cvutils.py	Mon Mar 18 23:37:45 2013 -0400
+++ b/python/cvutils.py	Thu Mar 21 14:01:46 2013 -0400
@@ -24,10 +24,6 @@
                                          cvGreen,
                                          cvBlue])
 
-cvKeyNumbers = {'a':1048673,
-                'n': 1048686,
-                'y': 1048697}
-
 def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'):
     '''Draws lines over the image '''
     
@@ -97,7 +93,7 @@
             ret = True
             frameNum = firstFrameNum
             capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum)
-            while ret and key!= 113: # 'q'
+            while ret and chr(key&255)!= 'q':
                 ret, img = capture.read()
                 if ret:
                     print('frame {0}'.format(frameNum))
@@ -139,7 +135,7 @@
                 lastFrameNum = maxint
             else:
                 lastFrameNum = lastFrameNumArg
-            while ret and key!= 113 and frameNum < lastFrameNum: # 'q'
+            while ret and chr(key&255)!= 'q' and chr(key&255)!= 'Q' and frameNum < lastFrameNum:
                 ret, img = capture.read()
                 if ret:
                     print('frame {0}'.format(frameNum))
@@ -154,7 +150,7 @@
                             cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed)
                     cv2.imshow('frame', img)
                     key = cv2.waitKey()
-                    if key == 115:
+                    if chr(key&255) == 's':
                         cv2.imwrite('image.png', img)
                     frameNum += 1