comparison python/cvutils.py @ 515:727e3c529519

renamed all draw functions to plot for consistency
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 06 Jun 2014 14:10:42 -0400
parents ad518f0c3218
children fd9641cbd24b
comparison
equal deleted inserted replaced
514:1ba618fb0f70 515:727e3c529519
34 return chr(key&255)== 'q' or chr(key&255) == 'Q' 34 return chr(key&255)== 'q' or chr(key&255) == 'Q'
35 35
36 def saveKey(key): 36 def saveKey(key):
37 return chr(key&255) == 's' 37 return chr(key&255) == 's'
38 38
39 def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'): 39 def plotLines(filename, origins, destinations, w = 1, resultFilename='image.png'):
40 '''Draws lines over the image ''' 40 '''Draws lines over the image '''
41 import Image, ImageDraw # PIL 41 import Image, ImageDraw # PIL
42 42
43 img = Image.open(filename) 43 img = Image.open(filename)
44 44
46 #draw = aggdraw.Draw(img) 46 #draw = aggdraw.Draw(img)
47 #pen = aggdraw.Pen("red", width) 47 #pen = aggdraw.Pen("red", width)
48 for p1, p2 in zip(origins, destinations): 48 for p1, p2 in zip(origins, destinations):
49 draw.line([p1.x, p1.y, p2.x, p2.y], width = w, fill = (256,0,0)) 49 draw.line([p1.x, p1.y, p2.x, p2.y], width = w, fill = (256,0,0))
50 #draw.line([p1.x, p1.y, p2.x, p2.y], pen) 50 #draw.line([p1.x, p1.y, p2.x, p2.y], pen)
51 del draw 51 del draw
52 52
53 #out = utils.openCheck(resultFilename) 53 #out = utils.openCheck(resultFilename)
54 img.save(resultFilename) 54 img.save(resultFilename)
55 55
56 def matlab2PointCorrespondences(filename): 56 def matlab2PointCorrespondences(filename):
91 for i in range(cvmat.rows): 91 for i in range(cvmat.rows):
92 for j in range(cvmat.cols): 92 for j in range(cvmat.cols):
93 cvmat[i,j] = a[i,j] 93 cvmat[i,j] = a[i,j]
94 return cvmat 94 return cvmat
95 95
96 def draw(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 != 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)
245 if not hasattr(obj, 'projectedPositions'): 245 if not hasattr(obj, 'projectedPositions'):
246 if homography != None: 246 if homography != None:
247 obj.projectedPositions = obj.positions.project(homography) 247 obj.projectedPositions = obj.positions.project(homography)
248 else: 248 else:
249 obj.projectedPositions = obj.positions 249 obj.projectedPositions = obj.positions
250 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) 250 cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant())
251 if frameNum in boundingBoxes.keys(): 251 if frameNum in boundingBoxes.keys():
252 for rect in boundingBoxes[frameNum]: 252 for rect in boundingBoxes[frameNum]:
253 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) 253 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed)
254 elif obj.features != None: 254 elif obj.features != None:
255 imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height) 255 imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height)