nsaunier/traffic-intelligence
correct bug to take into account first frame num in config, and other related bugs in dltrack.py
Commit 8e61ff3cd503 · Nicolas Saunier · 2024-06-27 15:31 -0400
Comments
No comments yet.
Diff
diff --git a/scripts/display-trajectories.py b/scripts/display-trajectories.py
--- a/scripts/display-trajectories.py
+++ b/scripts/display-trajectories.py
@@ -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:
diff --git a/scripts/dltrack.py b/scripts/dltrack.py
--- a/scripts/dltrack.py
+++ b/scripts/dltrack.py
@@ -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')
diff --git a/trafficintelligence/storage.py b/trafficintelligence/storage.py
--- a/trafficintelligence/storage.py
+++ b/trafficintelligence/storage.py
@@ -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