How can I implement a multi-track imm tracker with Matlab Coder compatability
Mostrar comentarios más antiguos
Hello,
I am trying to implement a multi-track imm tracker that is compatible with matlab coder.
This tracker need to maintain multiple tracks using multiple imm trackers. Therefore my implementation includes "persistent trackers" where trackers is a cell array of trackingIMM. The problem is I get the following error: "Unable to determine that every element of 'trackers{:}' is assigned before this line", eventhough I initiallized all of the cell array with trackingIMM(which I would like to prevent from doing so) as the error discription indicated. Here is my code:
function [state, cov, dist, lh, model_prob] = immTracking(track_id, max_id, fcn, prev_state, prev_cov, meas, meas_cov, dt)
persistent trackers
if isempty(trackers)
trackers = cell(1, max_id);
for i=1:length(trackers)
trackers{i} = trackingIMM();
end
end
if isequal(trackers{track_id}.State, zeros(6,1))
trackers{track_id} = trackingIMM('State', prev_state, 'StateCovariance', prev_cov);
end
switch(fcn)
case 1 %predict
tracker = clone(trackers{track_id});
[state, cov] = predict(tracker, dt);
case 2 %correct
tracker = clone(trackers{track_id});
[state, cov, dist, lh, model_prob] = correct_filter(tracker, meas, meas_cov, dt);
case 3 %update
tracker = trackers{track_id};
[state, cov, dist, lh, model_prob] = correct_filter(tracker, meas, meas_cov, dt);
case 4 %clear
trackers{track_id} = tracking_IMM();
end
end
function [state, cov, dist, lh, model_prob] = correct_filter(tracker, meas, meas_cov, dt)
predict(tracker, dt);
tracker.MeasurementNoise = meas_cov;
dist = distance(tracker, meas);
lh = likelihood(tracker, meas);
[state, cov] = correct(tracker, meas, 'rectangular');
model_prob = tracker.ModelProbabilities;
end
I would really appriciate any help with fixing this error or a better architecture for this implementation.
I only need this functionality because I do the actual initialization, association, etc' in a bigger java project which will use this as it's model for every track it initiallizes.
1 comentario
Stav Danino
el 13 de Sept. de 2021
Respuestas (1)
Elad Kivelevitch
el 13 de Sept. de 2021
Editada: Elad Kivelevitch
el 13 de Sept. de 2021
0 votos
There might be several reasons why codegen will not work for this code.
- For the error you're getting: first make sure that max_id is a coder.Constant type. This will make sure that the cell array you are creating is of a known size. This should never be modified in a future call.
- Additionally, you may want to use trackers = repmat({trackingIMM()}, 1, max_id) instead of allocating an empty cell.
- When you construct the trackers/filters (well, I prefer to call them filters, because a tracker is already a multi-object tracker with many tracks and filters inside it), you use the default constructor for trackingIMM. Please make sure that your models are exactly matching the models that the default constructor's set of models.
- In the next if-block, you reconstruct your IMM if the values of state are different. Instead, you can use the initialize method. No need to construct an IMM.
- In the switch-case block, you clone the filter. Cloning means that you created a NEW filter with a separate handle and assigned it the values of the old filter. Any operation you do will work on the new handle not the old handle. This I don't understand at all. Why are you doing it? Yes, the filter has internal state that you don't see, but that's exactly the reason why you should not create a new clone every time.
- Finally, in the correct_filter function, you call likelihood and distance without the frame and correct with it. While the frame ('rectangular') is the default one, and you can remove it from the call to correct, you may want to make sure that all these methods have the same measurement parameters as inputs.
Categorías
Más información sobre Multi-Object Trackers en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!