changeset 1125:b358bed29ab4

updates and bugs
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 30 Jan 2020 10:17:07 -0500
parents 234e2228fd30
children 2682b4696cdf
files c/feature-based-tracking.cpp scripts/manual-video-analysis.py trafficintelligence/cvutils.py trafficintelligence/indicators.py trafficintelligence/moving.py
diffstat 5 files changed, 33 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Tue Jun 25 17:23:43 2019 -0400
+++ b/c/feature-based-tracking.cpp	Thu Jan 30 10:17:07 2020 -0500
@@ -231,15 +231,15 @@
 	for (int i=MAX(0, currPts[n].y-params.minFeatureDistanceKLT); i<MIN(videoSize.height, currPts[n].y+params.minFeatureDistanceKLT+1); i++)
 	  featureMask.at<uchar>(i,j)=0;
     goodFeaturesToTrack(currentFrameBW, newPts, params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, featureMask, params.blockSize, params.useHarrisDetector, params.k);
-    if (params.undistort)
+    if (params.undistort && newPts.size() > 0)
       undistortPoints(newPts, undistortedPts, intrinsicCameraMatrix, params.distortionCoefficients);
     else
       undistortedPts = newPts;
 	
     for (unsigned int i=0; i<newPts.size(); i++) {
-      FeatureTrajectoryPtr f = FeatureTrajectoryPtr(new FeatureTrajectory(frameNum, undistortedPts[i], homography));
-      featurePointMatches.push_back(FeaturePointMatch(f, currPts.size()));
-      currPts.push_back(newPts[i]);
+	FeatureTrajectoryPtr f = FeatureTrajectoryPtr(new FeatureTrajectory(frameNum, undistortedPts[i], homography));
+	featurePointMatches.push_back(FeaturePointMatch(f, currPts.size()));
+	currPts.push_back(newPts[i]);
     }
   
     if (params.display && !displayFrame.empty()) {
--- a/scripts/manual-video-analysis.py	Tue Jun 25 17:23:43 2019 -0400
+++ b/scripts/manual-video-analysis.py	Thu Jan 30 10:17:07 2020 -0500
@@ -143,15 +143,15 @@
             print('SKIPPED')
             out.write('{},{},SKIP\n'.format(oldUserConfig.userNum, oldUserConfig.name))
         elif key == ord('d'):
-            cap.set(1,frameNum+100)
+            cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+100)
         elif key == ord('s'):
-            cap.set(1,frameNum+10)
+            cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+10)
         elif key == ord('a'):
-            cap.set(1,frameNum+1)
+            cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+1)
         elif key == ord('x'):
-            cap.set(1,frameNum-10)
+            cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum-10)
         elif key == ord('c'):
-            cap.set(1,frameNum-100)
+            cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum-100)
         elif key == ord('l'):
             frameNum = int(input("Please enter the frame number you would like to skip to\n"))
             cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum)
--- a/trafficintelligence/cvutils.py	Tue Jun 25 17:23:43 2019 -0400
+++ b/trafficintelligence/cvutils.py	Thu Jan 30 10:17:07 2020 -0500
@@ -266,7 +266,7 @@
         ymax = max(y)
         xMm = px * (xmax - xmin)
         yMm = py * (ymax - ymin)
-        a = max(ymax - ymin + (2 * yMm), xmax - (xmin + 2 * xMm))
+        a = max(ymax - ymin + (2 * yMm), xmax - xmin + (2 * xMm))
         yCropMin = int(max(0, .5 * (ymin + ymax - a)))
         yCropMax = int(min(height - 1, .5 * (ymin + ymax + a)))
         xCropMin = int(max(0, .5 * (xmin + xmax - a)))
@@ -276,7 +276,7 @@
     def imageBox(img, obj, frameNum, width, height, px = 0.2, py = 0.2, minNPixels = 800):
         'Computes the bounding box of object at frameNum'
         yCropMin, yCropMax, xCropMin, xCropMax = imageBoxSize(obj, frameNum, width, height, px, py)
-        if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels:
+        if yCropMax > yCropMin and xCropMax > xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels:
             return img[yCropMin : yCropMax, xCropMin : xCropMax]
         else:
             return None
--- a/trafficintelligence/indicators.py	Tue Jun 25 17:23:43 2019 -0400
+++ b/trafficintelligence/indicators.py	Thu Jan 30 10:17:07 2020 -0500
@@ -74,8 +74,15 @@
     def getName(self):
         return self.name
 
-    def getValues(self):
-        return [self.__getitem__(t) for t in self.timeInterval]
+    def getValues(self, withNone = True):
+        result = [self.__getitem__(t) for t in self.timeInterval]
+        if withNone:
+            return result
+        else:
+            return [x for x in result if x is not None]
+
+    def getInstants(self):
+        return list(self.values.keys())
 
     def plot(self, options = '', xfactor = 1., yfactor = 1., timeShift = 0, **kwargs):
         if self.getTimeInterval().length() == 1:
--- a/trafficintelligence/moving.py	Tue Jun 25 17:23:43 2019 -0400
+++ b/trafficintelligence/moving.py	Thu Jan 30 10:17:07 2020 -0500
@@ -738,6 +738,11 @@
         else:
             return False
 
+    def append(self,other):
+        '''adds positions of other to the trajectory (in-place modification)'''
+        for p in other:
+            self.addPosition(p)
+
     def setPositionXY(self, i, x, y):
         if i < self.__len__():
             self.positions[0][i] = x
@@ -1076,11 +1081,6 @@
         lanes = [lane]*nPoints
         return CurvilinearTrajectory(S, Y, lanes)
 
-    def append(self,other):
-        '''adds positions of other to the curvilinear trajectory (in-place modification)'''
-        for p in other:
-            self.addPosition(p)
-
     @staticmethod
     def fromTrajectoryProjection(t, alignments, halfWidth = 3):
         ''' Add, for every object position, the class 'moving.CurvilinearTrajectory()'
@@ -1216,7 +1216,8 @@
                  'motorcycle',
                  'bicycle',
                  'bus',
-                 'truck']
+                 'truck',
+                 'automated']
 
 userType2Num = utils.inverseEnumeration(userTypeNames)
 
@@ -1425,6 +1426,12 @@
         else:
             return None
 
+    def getCurvilinearVelocities(self):
+        if hasattr(self, 'curvilinearVelocities'):
+            return self.curvilinearVelocities
+        else:
+            return None
+
     def plotCurvilinearPositions(self, lane = None, options = '', withOrigin = False, **kwargs):
         if hasattr(self, 'curvilinearPositions'):
             if lane is None: