comparison scripts/dltrack.py @ 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 b2f90cada58f
children
comparison
equal deleted inserted replaced
1277:7493751bfe19 1278:8e61ff3cd503
30 parser.add_argument('--undistort', dest = 'undistort', help = 'undistort the video', action = 'store_true') 30 parser.add_argument('--undistort', dest = 'undistort', help = 'undistort the video', action = 'store_true')
31 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') 31 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
32 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) 32 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
33 parser.add_argument('--display', dest = 'display', help = 'show the raw detection and tracking results', action = 'store_true') 33 parser.add_argument('--display', dest = 'display', help = 'show the raw detection and tracking results', action = 'store_true')
34 parser.add_argument('--no-image-coordinates', dest = 'notSavingImageCoordinates', help = 'not saving the raw detection and tracking results', action = 'store_true') 34 parser.add_argument('--no-image-coordinates', dest = 'notSavingImageCoordinates', help = 'not saving the raw detection and tracking results', action = 'store_true')
35 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to process', type = int, default = 0) 35 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to process', type = int)
36 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to process', type = int, default = inf) 36 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to process', type = int, default = inf)
37 parser.add_argument('--conf', dest = 'confidence', help = 'object confidence threshold for detection', type = float, default = 0.25) 37 parser.add_argument('--conf', dest = 'confidence', help = 'object confidence threshold for detection', type = float, default = 0.25)
38 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) 38 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)
39 parser.add_argument('--cyclist-iou', dest = 'cyclistIou', help = 'IoU threshold to associate a bike and ped bounding box', type = float, default = 0.15) 39 parser.add_argument('--cyclist-iou', dest = 'cyclistIou', help = 'IoU threshold to associate a bike and ped bounding box', type = float, default = 0.15)
40 parser.add_argument('--cyclist-match-prop', dest = 'cyclistMatchingProportion', help = 'minimum proportion of time a bike exists and is associated with a pedestrian to be merged as cyclist', type = float, default = 0.3) 40 parser.add_argument('--cyclist-match-prop', dest = 'cyclistMatchingProportion', help = 'minimum proportion of time a bike exists and is associated with a pedestrian to be merged as cyclist', type = float, default = 0.3)
41 #parser.add_argument('--max-temp-overal', dest = 'maxTemporalOverlap', help = 'maximum proportion of time to merge 2 bikes associated with same pedestrian', type = float, default = 0.05) 41 #parser.add_argument('--max-temp-overal', dest = 'maxTemporalOverlap', help = 'maximum proportion of time to merge 2 bikes associated with same pedestrian', type = float, default = 0.05)
42 42
43 args = parser.parse_args() 43 args = parser.parse_args()
44 params, videoFilename, databaseFilename, homography, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) 44 params, videoFilename, databaseFilename, homography, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args)
45
46 print(params, videoFilename, databaseFilename, homography)
45 47
46 if args.homographyFilename is not None: 48 if args.homographyFilename is not None:
47 homography = np.loadtxt(args.homographyFilename) 49 homography = np.loadtxt(args.homographyFilename)
48 if args.intrinsicCameraMatrixFilename is not None: 50 if args.intrinsicCameraMatrixFilename is not None:
49 intrinsicCameraMatrix = np.loadtxt(args.intrinsicCameraMatrixFilename) 51 intrinsicCameraMatrix = np.loadtxt(args.intrinsicCameraMatrixFilename)
54 if args.lastFrameNum is not None: 56 if args.lastFrameNum is not None:
55 lastFrameNum = args.lastFrameNum 57 lastFrameNum = args.lastFrameNum
56 elif args.configFilename is not None: 58 elif args.configFilename is not None:
57 lastFrameNum = params.lastFrameNum 59 lastFrameNum = params.lastFrameNum
58 else: 60 else:
59 lastFrameNum = args.lastFrameNum 61 lastFrameNum = np.inf
60 if args.maskFilename is not None: 62 if args.maskFilename is not None:
61 mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE) 63 mask = cv2.imread(args.maskFilename, cv2.IMREAD_GRAYSCALE)
62 elif params is not None and params.maskFilename is not None: 64 elif params is not None and params.maskFilename is not None:
63 mask = cv2.imread(params.maskFilename, cv2.IMREAD_GRAYSCALE) 65 mask = cv2.imread(params.maskFilename, cv2.IMREAD_GRAYSCALE)
64 else: 66 else:
93 frameNum = firstFrameNum 95 frameNum = firstFrameNum
94 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) 96 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum)
95 97
96 success, frame = capture.read() 98 success, frame = capture.read()
97 if not success: 99 if not success:
98 print('Input {} could not be read. Exiting'.format(args.videoFilename)) 100 print('Input {} could not be read. Exiting'.format(videoFilename))
99 import sys; sys.exit() 101 import sys; sys.exit()
100 102
101 results = model.track(source=frame, tracker=args.trackerFilename, classes=list(moving.cocoTypeNames.keys()), conf=args.confidence, persist=True, verbose=False) 103 results = model.track(source=frame, tracker=args.trackerFilename, classes=list(moving.cocoTypeNames.keys()), conf=args.confidence, persist=True, verbose=False)
102 while capture.isOpened() and success and frameNum <= lastFrameNum: 104 while capture.isOpened() and success and frameNum <= lastFrameNum:
103 result = results[0] 105 result = results[0]
235 if f.length() != len(f.tmpPositions): # interpolate 237 if f.length() != len(f.tmpPositions): # interpolate
236 f.positions = moving.Trajectory.fromPointDict(f.tmpPositions) 238 f.positions = moving.Trajectory.fromPointDict(f.tmpPositions)
237 else: 239 else:
238 f.positions = moving.Trajectory.fromPointList(list(f.tmpPositions.values())) 240 f.positions = moving.Trajectory.fromPointList(list(f.tmpPositions.values()))
239 if not args.notSavingImageCoordinates: 241 if not args.notSavingImageCoordinates:
240 storage.saveTrajectoriesToSqlite(utils.removeExtension(args.databaseFilename)+'-bb.sqlite', list(objects.values()), 'object') 242 storage.saveTrajectoriesToSqlite(utils.removeExtension(databaseFilename)+'-bb.sqlite', list(objects.values()), 'object')
241 # project and smooth 243 # project and smooth
242 for num, obj in objects.items(): 244 for num, obj in objects.items():
243 features = obj.getFeatures() 245 features = obj.getFeatures()
244 # possible to save bottom pedestrians? not consistent with other users 246 # possible to save bottom pedestrians? not consistent with other users
245 # if moving.userTypeNames[obj.getUserType()] == 'pedestrian': 247 # if moving.userTypeNames[obj.getUserType()] == 'pedestrian':
261 feature.smoothPositions(smoothingHalfWidth, replace = True)#f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth) 263 feature.smoothPositions(smoothingHalfWidth, replace = True)#f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth)
262 feature.computeVelocities() 264 feature.computeVelocities()
263 obj.features=[feature] 265 obj.features=[feature]
264 obj.featureNumbers = [featureNum] 266 obj.featureNumbers = [featureNum]
265 #saving 267 #saving
266 storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object') 268 storage.saveTrajectoriesToSqlite(databaseFilename, list(objects.values()), 'object')
267 269
268 270
269 271
270 # todo save bbox and mask to study localization / representation 272 # todo save bbox and mask to study localization / representation
271 # apply quality checks deviation and acceleration bounds? 273 # apply quality checks deviation and acceleration bounds?