Mercurial Hosting > traffic-intelligence
annotate python/cvutils.py @ 372:349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
In general, shapely should be used, especially for lots of points:
from shapely.geometry import Polygon, Point
poly = Polygon(array([[0,0],[0,1],[1,1],[1,0]]))
p = Point(0.5,0.5)
poly.contains(p) -> returns True
poly.contains(Point(-1,-1)) -> returns False
You can convert a moving.Point to a shapely point: p = moving.Point(1,2) p.asShapely() returns the equivalent shapely point
If you have several points to test, use moving.pointsInPolygon(points, polygon) where points are moving.Point and polygon is a shapely polygon.
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 16 Jul 2013 17:00:17 -0400 |
parents | 22ddb8f85495 |
children | 387cc0142211 |
rev | line source |
---|---|
28 | 1 #! /usr/bin/env python |
2 '''Image/Video utilities''' | |
3 | |
4 import Image, ImageDraw # PIL | |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
5 try: |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
6 import cv2 |
365
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
7 opencvAvailable = True |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
8 except ImportError: |
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
9 print('OpenCV library could not be loaded') |
365
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
10 opencvAvailable = False |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
11 try: |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
12 import skimage |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
13 skimageAvailable = True |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
14 except ImportError: |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
15 print('Scikit-image library could not be loaded') |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
16 skimageAvailable = False |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
17 |
99
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
18 from sys import stdout |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
19 |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
20 import utils |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
21 |
44
be3ae926e4e8
added simple intersection description, function to load collision points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
28
diff
changeset
|
22 #import aggdraw # agg on top of PIL (antialiased drawing) |
28 | 23 #import utils |
24 | |
25 __metaclass__ = type | |
26 | |
151
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
27 cvRed = (0,0,255) |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
28 cvGreen = (0,255,0) |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
29 cvBlue = (255,0,0) |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
30 cvColors = utils.PlottingPropertyValues([cvRed, |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
31 cvGreen, |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
32 cvBlue]) |
4af774bb186d
wrote a simple script to compute homography from point correspondences and display the reprojection for visual verification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
150
diff
changeset
|
33 |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
34 def quitKey(key): |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
35 return chr(key&255)== 'q' or chr(key&255) == 'Q' |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
36 |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
37 def saveKey(key): |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
38 return chr(key&255) == 's' |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
39 |
28 | 40 def drawLines(filename, origins, destinations, w = 1, resultFilename='image.png'): |
41 '''Draws lines over the image ''' | |
42 | |
43 img = Image.open(filename) | |
44 | |
45 draw = ImageDraw.Draw(img) | |
46 #draw = aggdraw.Draw(img) | |
47 #pen = aggdraw.Pen("red", width) | |
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)) | |
50 #draw.line([p1.x, p1.y, p2.x, p2.y], pen) | |
51 del draw | |
52 | |
53 #out = utils.openCheck(resultFilename) | |
54 img.save(resultFilename) | |
55 | |
159
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
56 def matlab2PointCorrespondences(filename): |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
57 '''Loads and converts the point correspondences saved |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
58 by the matlab camera calibration tool''' |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
59 from numpy.lib.io import loadtxt, savetxt |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
60 from numpy.lib.function_base import append |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
61 points = loadtxt(filename, delimiter=',') |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
62 savetxt(utils.removeExtension(filename)+'-point-correspondences.txt',append(points[:,:2].T, points[:,3:].T, axis=0)) |
115f7f90286d
updated calibration-translation and added function to convert point correspondences
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
156
diff
changeset
|
63 |
160
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
64 def loadPointCorrespondences(filename): |
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
65 '''Loads and returns the corresponding points in world (first 2 lines) and image spaces (last 2 lines)''' |
233
ab1a11176d7b
initial sqlite code and bug corrected in cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
227
diff
changeset
|
66 from numpy.lib.npyio import loadtxt |
160
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
67 from numpy import float32 |
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
68 points = loadtxt(filename, dtype=float32) |
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
69 return (points[:2,:].T, points[2:,:].T) # (world points, image points) |
b0719b3ad3db
created function to load point correspondences and updates scripts that use it
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
159
diff
changeset
|
70 |
99
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
71 def cvMatToArray(cvmat): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
72 '''Converts an OpenCV CvMat to numpy array.''' |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
73 from numpy.core.multiarray import zeros |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
74 a = zeros((cvmat.rows, cvmat.cols))#array([[0.0]*cvmat.width]*cvmat.height) |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
75 for i in xrange(cvmat.rows): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
76 for j in xrange(cvmat.cols): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
77 a[i,j] = cvmat[i,j] |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
78 return a |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
79 |
365
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
80 if opencvAvailable: |
302
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
266
diff
changeset
|
81 def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=0.0): |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
266
diff
changeset
|
82 '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)''' |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
266
diff
changeset
|
83 H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold) |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
266
diff
changeset
|
84 return H |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
266
diff
changeset
|
85 |
152
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
151
diff
changeset
|
86 def arrayToCvMat(a, t = cv2.cv.CV_64FC1): |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
87 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.''' |
152
74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
151
diff
changeset
|
88 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t) |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
89 for i in range(cvmat.rows): |
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
90 for j in range(cvmat.cols): |
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
91 cvmat[i,j] = a[i,j] |
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
92 return cvmat |
99
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
93 |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
94 def draw(img, positions, color, lastCoordinate = None): |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
95 last = lastCoordinate+1 |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
96 if lastCoordinate != None and lastCoordinate >=0: |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
97 last = min(positions.length()-1, lastCoordinate) |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
98 for i in range(0, last-1): |
223
c31722fcc9de
minor modifications for integer drawing in OpenCV
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
218
diff
changeset
|
99 cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color) |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
100 |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
101 def playVideo(filename, firstFrameNum = 0, frameRate = -1): |
150
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
102 '''Plays the video''' |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
103 wait = 5 |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
104 if frameRate > 0: |
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
105 wait = int(round(1000./frameRate)) |
149
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
106 capture = cv2.VideoCapture(filename) |
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
107 if capture.isOpened(): |
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
108 key = -1 |
227
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
109 ret = True |
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
110 frameNum = firstFrameNum |
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
111 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
112 while ret and not quitKey(key): |
149
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
113 ret, img = capture.read() |
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
114 if ret: |
226
91197f6a03fe
added goto framenum
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
224
diff
changeset
|
115 print('frame {0}'.format(frameNum)) |
91197f6a03fe
added goto framenum
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
224
diff
changeset
|
116 frameNum+=1 |
149
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
117 cv2.imshow('frame', img) |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
118 key = cv2.waitKey(wait) |
346
5f75d6c23ed5
added opencv function to destroy OpenCV windows (seems to work only on Windows)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
319
diff
changeset
|
119 cv2.destroyAllWindows() |
149
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
120 |
216
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
121 def getImagesFromVideo(filename, nImages = 1, saveImage = False): |
150
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
122 '''Returns nImages images from the video sequence''' |
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
123 images = [] |
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
124 capture = cv2.VideoCapture(filename) |
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
125 if capture.isOpened(): |
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
126 ret = False |
216
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
127 numImg = 0 |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
128 while numImg<nImages: |
171
8e7b354666ec
corrected bug in to get images from video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
160
diff
changeset
|
129 ret, img = capture.read() |
216
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
130 i = 0 |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
131 while not ret and i<10: |
150
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
132 ret, img = capture.read() |
216
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
133 i += 1 |
171
8e7b354666ec
corrected bug in to get images from video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
160
diff
changeset
|
134 if img.size>0: |
216
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
135 numImg +=1 |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
136 if saveImage: |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
137 cv2.imwrite('image{0:04d}.png'.format(numImg), img) |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
138 else: |
51acf43e421a
modified the function to read and save images from a movie
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
204
diff
changeset
|
139 images.append(img) |
150
404f3cade05f
added python function to get image frames from video filenames
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
149
diff
changeset
|
140 return images |
149
0f552c8b1650
added python function to play video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
141 |
248
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
142 def displayTrajectories(videoFilename, objects, homography = None, firstFrameNum = 0, lastFrameNumArg = None): |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
143 '''Displays the objects overlaid frame by frame over the video ''' |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
144 capture = cv2.VideoCapture(videoFilename) |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
145 if capture.isOpened(): |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
146 key = -1 |
227
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
147 ret = True |
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
148 frameNum = firstFrameNum |
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
149 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) |
248
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
150 if not lastFrameNumArg: |
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
151 from sys import maxint |
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
152 lastFrameNum = maxint |
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
153 else: |
571ba5ed22e2
added utils for bus processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
243
diff
changeset
|
154 lastFrameNum = lastFrameNumArg |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
155 while ret and not quitKey(key) and frameNum < lastFrameNum: |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
156 ret, img = capture.read() |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
157 if ret: |
227
b7612c6d5702
cleaned the code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
226
diff
changeset
|
158 print('frame {0}'.format(frameNum)) |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
159 for obj in objects: |
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
160 if obj.existsAtInstant(frameNum): |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
161 if not hasattr(obj, 'projectedPositions'): |
218
b5772df11b37
corrected bugs to load objects and display trajectories over videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
216
diff
changeset
|
162 if homography != None: |
b5772df11b37
corrected bugs to load objects and display trajectories over videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
216
diff
changeset
|
163 obj.projectedPositions = obj.positions.project(homography) |
b5772df11b37
corrected bugs to load objects and display trajectories over videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
216
diff
changeset
|
164 else: |
b5772df11b37
corrected bugs to load objects and display trajectories over videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
216
diff
changeset
|
165 obj.projectedPositions = obj.positions |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
166 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) |
223
c31722fcc9de
minor modifications for integer drawing in OpenCV
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
218
diff
changeset
|
167 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
168 cv2.imshow('frame', img) |
266
aba9711b3149
small modificatons and reorganization
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
248
diff
changeset
|
169 key = cv2.waitKey() |
305
ca9131968bce
added sample to replay video
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
303
diff
changeset
|
170 if saveKey(key): |
266
aba9711b3149
small modificatons and reorganization
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
248
diff
changeset
|
171 cv2.imwrite('image.png', img) |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
172 frameNum += 1 |
346
5f75d6c23ed5
added opencv function to destroy OpenCV windows (seems to work only on Windows)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
319
diff
changeset
|
173 cv2.destroyAllWindows() |
203
e2f31813ade6
added code to display trajectories on videa
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
171
diff
changeset
|
174 |
99
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
175 def printCvMat(cvmat, out = stdout): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
176 '''Prints the cvmat to out''' |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
177 for i in xrange(cvmat.rows): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
178 for j in xrange(cvmat.cols): |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
179 out.write('{0} '.format(cvmat[i,j])) |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
180 out.write('\n') |
e7dc5a780f09
added conversion functions and homography computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
98
diff
changeset
|
181 |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
182 def projectArray(homography, points): |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
183 '''Returns the coordinates of the projected points (format 2xN points) |
28 | 184 through homography''' |
315
82b9be447608
bugfix for dot import
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
305
diff
changeset
|
185 from numpy.core import dot |
28 | 186 from numpy.core.multiarray import array |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
187 from numpy.lib.function_base import append |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
188 |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
189 if points.shape[0] != 2: |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
190 raise Exception('points of dimension {0} {1}'.format(points.shape[0], points.shape[1])) |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
191 |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
192 if (homography!=None) and homography.size>0: |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
193 augmentedPoints = append(points,[[1]*points.shape[1]], 0) |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
194 prod = dot(homography, augmentedPoints) |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
195 return prod[0:2]/prod[2] |
28 | 196 else: |
197 return p | |
198 | |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
199 def project(homography, p): |
319 | 200 '''Returns the coordinates of the projection of the point p with coordinates p[0], p[1] |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
201 through homography''' |
243
e0988a8ace0c
started adapting and moving to other modules Mohamed's work
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
236
diff
changeset
|
202 from numpy import array |
e0988a8ace0c
started adapting and moving to other modules Mohamed's work
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
236
diff
changeset
|
203 return projectArray(homography, array([[p[0]],[p[1]]])) |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
204 |
28 | 205 def projectTrajectory(homography, trajectory): |
206 '''Projects a series of points in the format | |
207 [[x1, x2, ...], | |
98
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
208 [y1, y2, ...]]''' |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
209 from numpy.core.multiarray import array |
b85912ab4064
refactored projection functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
63
diff
changeset
|
210 return projectArray(homography, array(trajectory)) |
28 | 211 |
48
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
212 def invertHomography(homography): |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
213 'Returns an inverted homography' |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
214 from numpy.linalg.linalg import inv |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
215 invH = inv(homography) |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
216 invH /= invH[2,2] |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
217 return invH |
8aed225f71d8
rearranged code for function readline and getlines (and characters), moved invertHomography to cvutils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
44
diff
changeset
|
218 |
365
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
219 if opencvAvailable: |
154
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
220 def computeTranslation(img1, img2, img1Points, maxTranslation2, minNMatches, windowSize = (5,5), level = 5, criteria = (cv2.TERM_CRITERIA_EPS, 0, 0.01)): |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
221 '''Computes the translation of img2 with respect to img1 |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
222 (loaded using OpenCV as numpy arrays) |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
223 img1Points are used to compute the translation |
100
2a3cafcf5faf
added function to compute the translation between two images
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
99
diff
changeset
|
224 |
154
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
225 TODO add diagnostic if data is all over the place, and it most likely is not a translation (eg zoom, other non linear distortion)''' |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
226 from numpy.core.multiarray import array |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
227 from numpy.lib.function_base import median |
154
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
228 from numpy.core.fromnumeric import sum |
100
2a3cafcf5faf
added function to compute the translation between two images
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
99
diff
changeset
|
229 |
154
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
230 nextPoints = array([]) |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
231 (img2Points, status, track_error) = cv2.calcOpticalFlowPyrLK(img1, img2, img1Points, nextPoints, winSize=windowSize, maxLevel=level, criteria=criteria) |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
232 # calcOpticalFlowPyrLK(prevImg, nextImg, prevPts[, nextPts[, status[, err[, winSize[, maxLevel[, criteria[, derivLambda[, flags]]]]]]]]) -> nextPts, status, err |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
233 delta = [] |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
234 for (k, (p1,p2)) in enumerate(zip(img1Points, img2Points)): |
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
235 if status[k] == 1: |
154
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
236 dp = p2-p1 |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
237 d = sum(dp**2) |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
238 if d < maxTranslation2: |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
239 delta.append(dp) |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
240 if len(delta) >= minNMatches: |
668710d4c773
updated computeTranslation with cv2
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
152
diff
changeset
|
241 return median(delta, axis=0) |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
242 else: |
156
2eef5620c0b3
added key values for opencv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
154
diff
changeset
|
243 print(dp) |
112
67555e968b5e
added tests if OpenCV python libraries are not available
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
102
diff
changeset
|
244 return None |
365
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
245 |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
246 if skimageAvailable: |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
247 def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(3, 3), visualize=False, normalize=False): |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
248 from os import listdir |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
249 from matplotlib.pyplot import imread, imshow, figure, subplot |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
250 from skimage.feature import hog |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
251 from skimage import color, transform |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
252 from numpy import array, float32 |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
253 |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
254 inputData = [] |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
255 for filename in listdir(imageDirectory): |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
256 img = imread(imageDirectory+filename) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
257 bwImg = color.rgb2gray(img) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
258 inputImg = transform.resize(bwImg, rescaleSize) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
259 features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, visualize, normalize) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
260 if visualize: |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
261 hogViz = features[1] |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
262 features = features[0] |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
263 figure() |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
264 subplot(1,2,1) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
265 imshow(img) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
266 subplot(1,2,2) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
267 imshow(hogViz) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
268 inputData.append(features) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
269 |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
270 nImages = len(inputData) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
271 return array(inputData, dtype = float32), array([classLabel]*nImages, dtype = float32) |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
272 |
22ddb8f85495
added function to create HOG training set
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
346
diff
changeset
|
273 |