How can I implement a multi-track imm tracker with Matlab Coder compatability

3 次查看(过去 30 天)
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 个评论
Stav Danino
Stav Danino 2021-9-13
BTW I tried reinitializing the IMM every call with all of the previous IMM's properties, but the performance ot the tracker is worse which indicates that initializing with all parameters does not equal to cloning. It means there are some hidden properties in the IMM tracker that are getting updated as it predicts and corrects using measurements.
If possible I would like to learn about those parameters and how they are changing through the tracking process.

请先登录,再进行评论。

回答(1 个)

Elad Kivelevitch
Elad Kivelevitch 2021-9-13
编辑:Elad Kivelevitch 2021-9-13
There might be several reasons why codegen will not work for this code.
  1. 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.
  2. Additionally, you may want to use trackers = repmat({trackingIMM()}, 1, max_id) instead of allocating an empty cell.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by