Mercurial Hosting > traffic-intelligence
diff scripts/dltrack.py @ 1250:77fbd0e2ba7d
dltrack works with moving average filtering
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 15 Feb 2024 22:04:35 -0500 |
parents | 2aa56b101041 |
children | dff5b678a33a |
line wrap: on
line diff
--- a/scripts/dltrack.py Thu Feb 15 14:09:52 2024 -0500 +++ b/scripts/dltrack.py Thu Feb 15 22:04:35 2024 -0500 @@ -59,10 +59,14 @@ lastFrameNum = args.lastFrameNum if args.maskFilename is not None: mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE) -elif params.maskFilename is not None: +elif params is not None and params.maskFilename is not None: mask = cv2.imread(params.maskFilename, cv2.IMREAD_GRAYSCALE) else: mask = None +if params is not None: + smoothingHalfWidth = params.smoothingHalfWidth +else: + smoothingHalfWidth = None # TODO use mask, remove short objects, smooth @@ -135,9 +139,14 @@ cv2.destroyAllWindows() # classification +shortObjectNumbers = [] for num, obj in objects.items(): - obj.setUserType(utils.mostCommon(obj.userTypes)) # improve? mix with speed? - + if obj.length() < 3: + shortObjectNumbers.append(num) + else: + obj.setUserType(utils.mostCommon(obj.userTypes)) # improve? mix with speed? +for num in shortObjectNumbers: + del objects[num] # TODO add quality control: avoid U-turns # merge bikes and people @@ -242,8 +251,14 @@ featureNum = features[0].getNum() obj.features=[moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))] obj.featureNumbers = [featureNum] +if smoothingHalfWidth is not None: # smoothing + for num, obj in objects.items(): + for f in obj.getFeatures(): + f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth) storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object') + + # todo save bbox and mask to study localization / representation # apply quality checks deviation and acceleration bounds?