changeset 1278:8e61ff3cd503 default tip

correct bug to take into account first frame num in config, and other related bugs in dltrack.py
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 27 Jun 2024 15:31:36 -0400
parents 7493751bfe19
children
files scripts/display-trajectories.py scripts/dltrack.py trafficintelligence/storage.py
diffstat 3 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/display-trajectories.py	Thu Jun 27 15:31:17 2024 -0400
+++ b/scripts/display-trajectories.py	Thu Jun 27 15:31:36 2024 -0400
@@ -19,7 +19,7 @@
 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float)
 parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true')
 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int)
-parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int, default = inf)
+parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int)
 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float)
 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int)
 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to display', type = int)
@@ -41,6 +41,8 @@
     firstFrameNum = args.firstFrameNum
 if args.lastFrameNum is not None:
     lastFrameNum = args.lastFrameNum
+else:
+    lastFrameNum = inf
 if args.nObjects is not None:
     nObjects = args.nObjects
 else:
--- a/scripts/dltrack.py	Thu Jun 27 15:31:17 2024 -0400
+++ b/scripts/dltrack.py	Thu Jun 27 15:31:36 2024 -0400
@@ -32,7 +32,7 @@
 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
 parser.add_argument('--display', dest = 'display', help = 'show the raw detection and tracking results', action = 'store_true')
 parser.add_argument('--no-image-coordinates', dest = 'notSavingImageCoordinates', help = 'not saving the raw detection and tracking results', action = 'store_true')
-parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to process', type = int, default = 0)
+parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to process', type = int)
 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to process', type = int, default = inf)
 parser.add_argument('--conf', dest = 'confidence', help = 'object confidence threshold for detection', type = float, default = 0.25)
 parser.add_argument('--bike-prop', dest = 'bikeProportion', help = 'minimum proportion of time a person classified as bike or motorbike to be classified as cyclist', type = float, default = 0.2)
@@ -43,6 +43,8 @@
 args = parser.parse_args()
 params, videoFilename, databaseFilename, homography, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args)
 
+print(params, videoFilename, databaseFilename, homography)
+
 if args.homographyFilename is not None:
     homography = np.loadtxt(args.homographyFilename)
 if args.intrinsicCameraMatrixFilename is not None:
@@ -56,7 +58,7 @@
 elif args.configFilename is not None:
     lastFrameNum = params.lastFrameNum
 else:
-    lastFrameNum = args.lastFrameNum
+    lastFrameNum = np.inf
 if args.maskFilename is not None:
     mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE)
 elif params is not None and params.maskFilename is not None:
@@ -95,7 +97,7 @@
 
 success, frame = capture.read()
 if not success:
-    print('Input {} could not be read. Exiting'.format(args.videoFilename))
+    print('Input {} could not be read. Exiting'.format(videoFilename))
     import sys; sys.exit()
 
 results = model.track(source=frame, tracker=args.trackerFilename, classes=list(moving.cocoTypeNames.keys()), conf=args.confidence, persist=True, verbose=False)
@@ -237,7 +239,7 @@
         else:
             f.positions = moving.Trajectory.fromPointList(list(f.tmpPositions.values()))
 if not args.notSavingImageCoordinates:
-    storage.saveTrajectoriesToSqlite(utils.removeExtension(args.databaseFilename)+'-bb.sqlite', list(objects.values()), 'object')
+    storage.saveTrajectoriesToSqlite(utils.removeExtension(databaseFilename)+'-bb.sqlite', list(objects.values()), 'object')
 # project and smooth
 for num, obj in objects.items():
     features = obj.getFeatures()
@@ -263,7 +265,7 @@
     obj.features=[feature]
     obj.featureNumbers = [featureNum]
 #saving
-storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object')
+storage.saveTrajectoriesToSqlite(databaseFilename, list(objects.values()), 'object')
 
 
 
--- a/trafficintelligence/storage.py	Thu Jun 27 15:31:17 2024 -0400
+++ b/trafficintelligence/storage.py	Thu Jun 27 15:31:36 2024 -0400
@@ -1773,7 +1773,7 @@
     then checks what was passed on the command line
     for override (eg video filename and database filename'''
     if args.configFilename is not None: # consider there is a configuration file
-        parentPath = Path(args.configFilename).parent
+        #parentPath = Path(args.configFilename).parent
         params = ProcessParameters(args.configFilename)
         videoFilename = params.videoFilename
         databaseFilename = params.databaseFilename