diff scripts/classify-objects.py @ 928:063d1267585d

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 12 Jul 2017 01:24:31 -0400
parents fd057a6b04db
children 0e63a918a1ca
line wrap: on
line diff
--- a/scripts/classify-objects.py	Tue Jul 11 17:56:23 2017 -0400
+++ b/scripts/classify-objects.py	Wed Jul 12 01:24:31 2017 -0400
@@ -75,8 +75,12 @@
 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
 
 if undistort: # setup undistortion
-    [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients)
-    height, width = map1.shape
+#     [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients)
+#     height, width = map1.shape
+    newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication)))
+    newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True)
+else:
+    newCameraMatrix = None
 
 pastObjects = []
 currentObjects = []
@@ -92,11 +96,11 @@
         if ret:
             if frameNum%50 == 0:
                 print('frame number: {}'.format(frameNum))
-            if undistort:
-                img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)            
+            #if undistort:
+            #    img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)            
             for obj in objects:
                 if obj.getFirstInstant() <= frameNum: # if images are skipped
-                    obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, classifierParams.maxPedestrianSpeed, classifierParams.maxCyclistSpeed, classifierParams.nFramesIgnoreAtEnds)
+                    obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, classifierParams.maxPedestrianSpeed, classifierParams.maxCyclistSpeed, classifierParams.nFramesIgnoreAtEnds, invHomography, newCameraMatrix, distortionCoefficients)
                     currentObjects.append(obj)
                     objects.remove(obj)
 
@@ -106,7 +110,7 @@
                     pastObjects.append(obj)
                     currentObjects.remove(obj)
                 else:
-                    obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm)
+                    obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm)
         frameNum += 1
     
     for obj in currentObjects: