comparison python/cvutils.py @ 636:3058e00887bc

removed all issues because of tests with None, using is instead of == or !=
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 24 Mar 2015 18:11:28 +0100
parents 977407c9f815
children 852f5de42d01
comparison
equal deleted inserted replaced
635:6ae68383071e 636:3058e00887bc
93 cvmat[i,j] = a[i,j] 93 cvmat[i,j] = a[i,j]
94 return cvmat 94 return cvmat
95 95
96 def cvPlot(img, positions, color, lastCoordinate = None): 96 def cvPlot(img, positions, color, lastCoordinate = None):
97 last = lastCoordinate+1 97 last = lastCoordinate+1
98 if lastCoordinate != None and lastCoordinate >=0: 98 if lastCoordinate is not None and lastCoordinate >=0:
99 last = min(positions.length()-1, lastCoordinate) 99 last = min(positions.length()-1, lastCoordinate)
100 for i in range(0, last-1): 100 for i in range(0, last-1):
101 cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color) 101 cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color)
102 102
103 def cvImshow(windowName, img, rescale = 1.0): 103 def cvImshow(windowName, img, rescale = 1.0):
138 ret, img = capture.read() 138 ret, img = capture.read()
139 if ret: 139 if ret:
140 if printFrames: 140 if printFrames:
141 print('frame {0}'.format(frameNum)) 141 print('frame {0}'.format(frameNum))
142 frameNum+=1 142 frameNum+=1
143 if text != None: 143 if text is not None:
144 cv2.putText(img, text, (10,50), cv2.cv.CV_FONT_HERSHEY_PLAIN, 1, cvRed) 144 cv2.putText(img, text, (10,50), cv2.cv.CV_FONT_HERSHEY_PLAIN, 1, cvRed)
145 cvImshow(windowName, img, rescale) 145 cvImshow(windowName, img, rescale)
146 key = cv2.waitKey(wait) 146 key = cv2.waitKey(wait)
147 if saveKey(key): 147 if saveKey(key):
148 cv2.imwrite('image-{}.png'.format(frameNum), img) 148 cv2.imwrite('image-{}.png'.format(frameNum), img)
232 if capture.isOpened(): 232 if capture.isOpened():
233 key = -1 233 key = -1
234 ret = True 234 ret = True
235 frameNum = firstFrameNum 235 frameNum = firstFrameNum
236 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) 236 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum)
237 if lastFrameNumArg == None: 237 if lastFrameNumArg is None:
238 from sys import maxint 238 from sys import maxint
239 lastFrameNum = maxint 239 lastFrameNum = maxint
240 else: 240 else:
241 lastFrameNum = lastFrameNumArg 241 lastFrameNum = lastFrameNumArg
242 nZerosFilename = int(ceil(log10(lastFrameNum))) 242 nZerosFilename = int(ceil(log10(lastFrameNum)))
248 if printFrames: 248 if printFrames:
249 print('frame {0}'.format(frameNum)) 249 print('frame {0}'.format(frameNum))
250 for obj in objects: 250 for obj in objects:
251 if obj.existsAtInstant(frameNum): 251 if obj.existsAtInstant(frameNum):
252 if not hasattr(obj, 'projectedPositions'): 252 if not hasattr(obj, 'projectedPositions'):
253 if homography != None: 253 if homography is not None:
254 obj.projectedPositions = obj.positions.project(homography) 254 obj.projectedPositions = obj.positions.project(homography)
255 else: 255 else:
256 obj.projectedPositions = obj.positions 256 obj.projectedPositions = obj.positions
257 cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) 257 cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant())
258 if frameNum in boundingBoxes.keys(): 258 if frameNum in boundingBoxes.keys():
420 from numpy.lib.function_base import append 420 from numpy.lib.function_base import append
421 421
422 if points.shape[0] != 2: 422 if points.shape[0] != 2:
423 raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1])) 423 raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1]))
424 424
425 if (homography!=None) and homography.size>0: 425 if (homography is not None) and homography.size>0:
426 augmentedPoints = append(points,[[1]*points.shape[1]], 0) 426 augmentedPoints = append(points,[[1]*points.shape[1]], 0)
427 prod = dot(homography, augmentedPoints) 427 prod = dot(homography, augmentedPoints)
428 return prod[0:2]/prod[2] 428 return prod[0:2]/prod[2]
429 else: 429 else:
430 return points 430 return points