comparison python/cvutils.py @ 406:37c7b46f6e21

update to OpenCV 2.6
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 07 Aug 2013 11:42:34 -0400
parents f29204e68aab
children 91954c76d12c
comparison
equal deleted inserted replaced
405:a9e275b4ecb7 406:37c7b46f6e21
82 def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=3.0): 82 def computeHomography(srcPoints, dstPoints, method=0, ransacReprojThreshold=3.0):
83 '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)''' 83 '''Returns the homography matrix mapping from srcPoints to dstPoints (dimension Nx2)'''
84 H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold) 84 H, mask = cv2.findHomography(srcPoints, dstPoints, method, ransacReprojThreshold)
85 return H 85 return H
86 86
87 def arrayToCvMat(a, t = cv2.cv.CV_64FC1): 87 def arrayToCvMat(a, t = cv2.CV_64FC1):
88 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.''' 88 '''Converts a numpy array to an OpenCV CvMat, with default type CV_64FC1.'''
89 print('Deprecated, use new interface') 89 print('Deprecated, use new interface')
90 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t) 90 cvmat = cv2.cv.CreateMat(a.shape[0], a.shape[1], t)
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):
120 capture = cv2.VideoCapture(filename) 120 capture = cv2.VideoCapture(filename)
121 if capture.isOpened(): 121 if capture.isOpened():
122 key = -1 122 key = -1
123 ret = True 123 ret = True
124 frameNum = firstFrameNum 124 frameNum = firstFrameNum
125 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) 125 capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum)
126 while ret and not quitKey(key): 126 while ret and not quitKey(key):
127 ret, img = capture.read() 127 ret, img = capture.read()
128 if ret: 128 if ret:
129 if printFrames: 129 if printFrames:
130 print('frame {0}'.format(frameNum)) 130 print('frame {0}'.format(frameNum))
139 '''Returns nFrames images from the video sequence''' 139 '''Returns nFrames images from the video sequence'''
140 from math import floor, log10 140 from math import floor, log10
141 images = [] 141 images = []
142 capture = cv2.VideoCapture(videoFilename) 142 capture = cv2.VideoCapture(videoFilename)
143 if capture.isOpened(): 143 if capture.isOpened():
144 nDigits = int(floor(log10(capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))))+1 144 nDigits = int(floor(log10(capture.get(cv2.CAP_PROP_FRAME_COUNT))))+1
145 ret = False 145 ret = False
146 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) 146 capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum)
147 imgNum = 0 147 imgNum = 0
148 while imgNum<nFrames: 148 while imgNum<nFrames:
149 ret, img = capture.read() 149 ret, img = capture.read()
150 i = 0 150 i = 0
151 while not ret and i<10: 151 while not ret and i<10:
164 return images 164 return images
165 165
166 def getFPS(videoFilename): 166 def getFPS(videoFilename):
167 capture = cv2.VideoCapture(videoFilename) 167 capture = cv2.VideoCapture(videoFilename)
168 if capture.isOpened(): 168 if capture.isOpened():
169 fps = capture.get(cv2.cv.CV_CAP_PROP_FPS) 169 fps = capture.get(cv2.CAP_PROP_FPS)
170 capture.release() 170 capture.release()
171 return fps 171 return fps
172 else: 172 else:
173 print 'Cannot load file ' + videoFilename 173 print 'Cannot load file ' + videoFilename
174 return None 174 return None
178 capture = cv2.VideoCapture(videoFilename) 178 capture = cv2.VideoCapture(videoFilename)
179 if capture.isOpened(): 179 if capture.isOpened():
180 key = -1 180 key = -1
181 ret = True 181 ret = True
182 frameNum = firstFrameNum 182 frameNum = firstFrameNum
183 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum) 183 capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum)
184 if not lastFrameNumArg: 184 if not lastFrameNumArg:
185 from sys import maxint 185 from sys import maxint
186 lastFrameNum = maxint 186 lastFrameNum = maxint
187 else: 187 else:
188 lastFrameNum = lastFrameNumArg 188 lastFrameNum = lastFrameNumArg