comparison python/cvutils.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 9d88a4d97473
children ca9131968bce
comparison
equal deleted inserted replaced
302:9d88a4d97473 303:514f6b98cd8c
22 cvBlue = (255,0,0) 22 cvBlue = (255,0,0)
23 cvColors = utils.PlottingPropertyValues([cvRed, 23 cvColors = utils.PlottingPropertyValues([cvRed,
24 cvGreen, 24 cvGreen,
25 cvBlue]) 25 cvBlue])
26 26
27 cvKeyNumbers = {'a':1048673,
28 'n': 1048686,
29 'y': 1048697}
30
31 def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'): 27 def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'):
32 '''Draws lines over the image ''' 28 '''Draws lines over the image '''
33 29
34 img = Image.open(filename) 30 img = Image.open(filename)
35 31
95 if capture.isOpened(): 91 if capture.isOpened():
96 key = -1 92 key = -1
97 ret = True 93 ret = True
98 frameNum = firstFrameNum 94 frameNum = firstFrameNum
99 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) 95 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum)
100 while ret and key!= 113: # 'q' 96 while ret and chr(key&255)!= 'q':
101 ret, img = capture.read() 97 ret, img = capture.read()
102 if ret: 98 if ret:
103 print('frame {0}'.format(frameNum)) 99 print('frame {0}'.format(frameNum))
104 frameNum+=1 100 frameNum+=1
105 cv2.imshow('frame', img) 101 cv2.imshow('frame', img)
137 if not lastFrameNumArg: 133 if not lastFrameNumArg:
138 from sys import maxint 134 from sys import maxint
139 lastFrameNum = maxint 135 lastFrameNum = maxint
140 else: 136 else:
141 lastFrameNum = lastFrameNumArg 137 lastFrameNum = lastFrameNumArg
142 while ret and key!= 113 and frameNum < lastFrameNum: # 'q' 138 while ret and chr(key&255)!= 'q' and chr(key&255)!= 'Q' and frameNum < lastFrameNum:
143 ret, img = capture.read() 139 ret, img = capture.read()
144 if ret: 140 if ret:
145 print('frame {0}'.format(frameNum)) 141 print('frame {0}'.format(frameNum))
146 for obj in objects: 142 for obj in objects:
147 if obj.existsAtInstant(frameNum): 143 if obj.existsAtInstant(frameNum):
152 obj.projectedPositions = obj.positions 148 obj.projectedPositions = obj.positions
153 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) 149 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant())
154 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) 150 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed)
155 cv2.imshow('frame', img) 151 cv2.imshow('frame', img)
156 key = cv2.waitKey() 152 key = cv2.waitKey()
157 if key == 115: 153 if chr(key&255) == 's':
158 cv2.imwrite('image.png', img) 154 cv2.imwrite('image.png', img)
159 frameNum += 1 155 frameNum += 1
160 156
161 def printCvMat(cvmat, out = stdout): 157 def printCvMat(cvmat, out = stdout):
162 '''Prints the cvmat to out''' 158 '''Prints the cvmat to out'''