comparison python/cvutils.py @ 435:17185fe77316

added error messages if video not opened
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 02 Dec 2013 16:39:50 -0500
parents 2be846d36dec
children 5304299e53a5
comparison
equal deleted inserted replaced
434:9a714f32fc9f 435:17185fe77316
132 if text != None: 132 if text != None:
133 cv2.putText(img, text, (10,50), cv2.cv.CV_FONT_HERSHEY_PLAIN, 1, cvRed) 133 cv2.putText(img, text, (10,50), cv2.cv.CV_FONT_HERSHEY_PLAIN, 1, cvRed)
134 cvImshow('frame', img, rescale) 134 cvImshow('frame', img, rescale)
135 key = cv2.waitKey(wait) 135 key = cv2.waitKey(wait)
136 cv2.destroyAllWindows() 136 cv2.destroyAllWindows()
137 else:
138 print('Video capture for {} failed'.format(videoFilename))
137 139
138 def getImagesFromVideo(videoFilename, firstFrameNum = 0, nFrames = 1, saveImage = False, outputPrefix = 'image'): 140 def getImagesFromVideo(videoFilename, firstFrameNum = 0, nFrames = 1, saveImage = False, outputPrefix = 'image'):
139 '''Returns nFrames images from the video sequence''' 141 '''Returns nFrames images from the video sequence'''
140 from math import floor, log10 142 from math import floor, log10
141 images = [] 143 images = []
158 else: 160 else:
159 images.append(img) 161 images.append(img)
160 imgNum +=1 162 imgNum +=1
161 capture.release() 163 capture.release()
162 else: 164 else:
163 print('Video capture failed') 165 print('Video capture for {} failed'.format(videoFilename))
164 return images 166 return images
165 167
166 def getFPS(videoFilename): 168 def getFPS(videoFilename):
167 capture = cv2.VideoCapture(videoFilename) 169 capture = cv2.VideoCapture(videoFilename)
168 if capture.isOpened(): 170 if capture.isOpened():
169 fps = capture.get(cv2.cv.CV_CAP_PROP_FPS) 171 fps = capture.get(cv2.cv.CV_CAP_PROP_FPS)
170 capture.release() 172 capture.release()
171 return fps 173 return fps
172 else: 174 else:
173 print 'Cannot load file ' + videoFilename 175 print('Video capture for {} failed'.format(videoFilename))
174 return None 176 return None
175 177
176 def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800): 178 def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800):
177 'Computes the bounding box of object at frameNum' 179 'Computes the bounding box of object at frameNum'
178 x = [] 180 x = []
244 key = cv2.waitKey() 246 key = cv2.waitKey()
245 if saveKey(key): 247 if saveKey(key):
246 cv2.imwrite('image.png', img) 248 cv2.imwrite('image.png', img)
247 frameNum += 1 249 frameNum += 1
248 cv2.destroyAllWindows() 250 cv2.destroyAllWindows()
251 else:
252 print 'Cannot load file ' + videoFilename
249 253
250 def computeHomographyFromPDTV(cameraFilename, method=0, ransacReprojThreshold=3.0): 254 def computeHomographyFromPDTV(cameraFilename, method=0, ransacReprojThreshold=3.0):
251 '''Returns the homography matrix at ground level from PDTV format 255 '''Returns the homography matrix at ground level from PDTV format
252 https://bitbucket.org/hakanardo/pdtv''' 256 https://bitbucket.org/hakanardo/pdtv'''
253 import pdtv 257 import pdtv