Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 152:74b1fc68d4df
re-organized code to avoid cyclic python module dependencies
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 06 Sep 2011 18:44:23 -0400 |
parents | 4af774bb186d |
children | 668710d4c773 |
comparison
equal
deleted
inserted
replaced
151:4af774bb186d | 152:74b1fc68d4df |
---|---|
56 for j in xrange(cvmat.cols): | 56 for j in xrange(cvmat.cols): |
57 a[i,j] = cvmat[i,j] | 57 a[i,j] = cvmat[i,j] |
58 return a | 58 return a |
59 | 59 |
60 if opencvExists: | 60 if opencvExists: |
61 def arrayToCvMat(a, t = cv.CV_64FC1): | 61 def arrayToCvMat(a, t = cv2.cv.CV_64FC1): |
62 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.''' | 62 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.''' |
63 cvmat = cv.CreateMat(a.shape[0], a.shape[1], t) | 63 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t) |
64 for i in range(cvmat.rows): | 64 for i in range(cvmat.rows): |
65 for j in range(cvmat.cols): | 65 for j in range(cvmat.cols): |
66 cvmat[i,j] = a[i,j] | 66 cvmat[i,j] = a[i,j] |
67 return cvmat | 67 return cvmat |
68 | 68 |
133 invH = inv(homography) | 133 invH = inv(homography) |
134 invH /= invH[2,2] | 134 invH /= invH[2,2] |
135 return invH | 135 return invH |
136 | 136 |
137 if opencvExists: | 137 if opencvExists: |
138 def computeTranslation(img1, img2, img1Points, maxTranslation, minNMatches, windowSize = (5,5), level = 5, criteria = (cv.CV_TERMCRIT_EPS, 0, 0.01)): | 138 def computeTranslation(img1, img2, img1Points, maxTranslation, minNMatches, windowSize = (5,5), level = 5, criteria = (cv2.TERM_CRITERIA_EPS, 0, 0.01)): |
139 '''Computes the translation between of img2 with respect to img1 | 139 '''Computes the translation between of img2 with respect to img1 |
140 (loaded using OpenCV) | 140 (loaded using OpenCV) |
141 img1Points are used to compute the translation | 141 img1Points are used to compute the translation |
142 | 142 |
143 TODO add diagnostic if data is all over the place, and it most likely is not a translation (eg zoom)''' | 143 TODO add diagnostic if data is all over the place, and it most likely is not a translation (eg zoom)''' |