changeset 398:3399bd48cb40

Ajout d'une méthode pour obtenir le nombre de FPS Méthode de capture des trames vidéos plus résistante aux erreur Utilisation d'un dictionnaire pour les fichier de configuration afin de garder le nom des sections
author Jean-Philippe Jodoin <jpjodoin@gmail.com>
date Mon, 29 Jul 2013 13:46:07 -0400
parents b36b00dd27c3
children c389fae9689a
files python/cvutils.py python/utils.py
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/python/cvutils.py	Sun Jul 28 18:04:20 2013 -0400
+++ b/python/cvutils.py	Mon Jul 29 13:46:07 2013 -0400
@@ -140,8 +140,8 @@
         from math import floor, log10
         images = []
         capture = cv2.VideoCapture(videoFilename)
-        nDigits = int(floor(log10(capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))))+1
-        if capture.isOpened():        
+        if capture.isOpened():
+            nDigits = int(floor(log10(capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))))+1
             ret = False
             capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum)
             imgNum = 0
@@ -158,8 +158,22 @@
                     else:
                         images.append(img)
                     imgNum +=1
+            capture.release()
+        else:
+            print('Video capture failed')
         return images
 
+    
+    def getFPS(videoFilename):
+        capture = cv2.VideoCapture(videoFilename)
+        if capture.isOpened():
+            fps = capture.get(cv2.cv.CV_CAP_PROP_FPS)
+            capture.release()
+            return fps
+        else:
+            print 'Cannot load file ' + videoFilename
+            return None
+
     def displayTrajectories(videoFilename, objects, boundingBoxes, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1.):
         '''Displays the objects overlaid frame by frame over the video '''
         capture = cv2.VideoCapture(videoFilename)
--- a/python/utils.py	Sun Jul 28 18:04:20 2013 -0400
+++ b/python/utils.py	Mon Jul 29 13:46:07 2013 -0400
@@ -557,7 +557,10 @@
         from ConfigParser import ConfigParser
         config = ConfigParser()
         config.readfp(openCheck(filename))
-        return [SceneParameters(config, sectionName) for sectionName in config.sections()]
+        configDict = dict()
+        for sectionName in config.sections():
+            configDict[sectionName] = SceneParameters(config, sectionName) 
+        return configDict
 
 
 #########################