Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
1249:2aa56b101041 | 1250:77fbd0e2ba7d |
---|---|
57 lastFrameNum = params.lastFrameNum | 57 lastFrameNum = params.lastFrameNum |
58 else: | 58 else: |
59 lastFrameNum = args.lastFrameNum | 59 lastFrameNum = args.lastFrameNum |
60 if args.maskFilename is not None: | 60 if args.maskFilename is not None: |
61 mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE) | 61 mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE) |
62 elif params.maskFilename is not None: | 62 elif params is not None and params.maskFilename is not None: |
63 mask = cv2.imread(params.maskFilename, cv2.IMREAD_GRAYSCALE) | 63 mask = cv2.imread(params.maskFilename, cv2.IMREAD_GRAYSCALE) |
64 else: | 64 else: |
65 mask = None | 65 mask = None |
66 if params is not None: | |
67 smoothingHalfWidth = params.smoothingHalfWidth | |
68 else: | |
69 smoothingHalfWidth = None | |
66 | 70 |
67 # TODO use mask, remove short objects, smooth | 71 # TODO use mask, remove short objects, smooth |
68 | 72 |
69 # TODO add option to refine position with mask for vehicles, to save different positions | 73 # TODO add option to refine position with mask for vehicles, to save different positions |
70 # TODO work with optical flow (farneback or RAFT) https://pytorch.org/vision/main/models/raft.html | 74 # TODO work with optical flow (farneback or RAFT) https://pytorch.org/vision/main/models/raft.html |
133 results = model.track(source=frame, persist=True) | 137 results = model.track(source=frame, persist=True) |
134 capture.release() | 138 capture.release() |
135 cv2.destroyAllWindows() | 139 cv2.destroyAllWindows() |
136 | 140 |
137 # classification | 141 # classification |
142 shortObjectNumbers = [] | |
138 for num, obj in objects.items(): | 143 for num, obj in objects.items(): |
139 obj.setUserType(utils.mostCommon(obj.userTypes)) # improve? mix with speed? | 144 if obj.length() < 3: |
140 | 145 shortObjectNumbers.append(num) |
146 else: | |
147 obj.setUserType(utils.mostCommon(obj.userTypes)) # improve? mix with speed? | |
148 for num in shortObjectNumbers: | |
149 del objects[num] | |
141 # TODO add quality control: avoid U-turns | 150 # TODO add quality control: avoid U-turns |
142 | 151 |
143 # merge bikes and people | 152 # merge bikes and people |
144 twowheels = [num for num, obj in objects.items() if obj.getUserType() in (moving.userType2Num['motorcyclist'],moving.userType2Num['cyclist'])] | 153 twowheels = [num for num, obj in objects.items() if obj.getUserType() in (moving.userType2Num['motorcyclist'],moving.userType2Num['cyclist'])] |
145 pedestrians = [num for num, obj in objects.items() if obj.getUserType() == moving.userType2Num['pedestrian']] | 154 pedestrians = [num for num, obj in objects.items() if obj.getUserType() == moving.userType2Num['pedestrian']] |
240 #t = (moving.Trajectory.add(t1, t2)*0.5).asArray() | 249 #t = (moving.Trajectory.add(t1, t2)*0.5).asArray() |
241 projected = cvutils.imageToWorldProject(np.array(t).T, intrinsicCameraMatrix, distortionCoefficients, homography) | 250 projected = cvutils.imageToWorldProject(np.array(t).T, intrinsicCameraMatrix, distortionCoefficients, homography) |
242 featureNum = features[0].getNum() | 251 featureNum = features[0].getNum() |
243 obj.features=[moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))] | 252 obj.features=[moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))] |
244 obj.featureNumbers = [featureNum] | 253 obj.featureNumbers = [featureNum] |
254 if smoothingHalfWidth is not None: # smoothing | |
255 for num, obj in objects.items(): | |
256 for f in obj.getFeatures(): | |
257 f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth) | |
245 storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object') | 258 storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object') |
259 | |
260 | |
246 | 261 |
247 # todo save bbox and mask to study localization / representation | 262 # todo save bbox and mask to study localization / representation |
248 # apply quality checks deviation and acceleration bounds? | 263 # apply quality checks deviation and acceleration bounds? |
249 | 264 |
250 # def mergeBBoxes(tw, ped): | 265 # def mergeBBoxes(tw, ped): |