issue with MATLAB Coder and cell arrays

조회 수: 2 (최근 30일)
Daniel Vieira
Daniel Vieira 2017년 4월 6일
답변: Tony Mohan Varghese 2018년 3월 22일
I wrote a code to track multiple faces, and I'm trying to put it on a raspberry pi. I solved every issue pointed by the Coder except one: "Unable to determine that every element of HT{:} is assigned before this line"
I read about this error, but as far as I can see there is no problem with the code. The (shortened) code is below. In the code, n is a loop counter, FT is a vision.CascadeObjectDetector, HTbase (and consequently every element of HT) is a vision.HistogramBasedTracker object, frame and hsvFrame are the image in rgb (all channels) and hsv (first channel) formats. Both HT and HTbase are declared as persistent. The idea is that once every 12 frames (first if) the code searches for faces with the actual face tracking object (slow but precise); using this result, in every other frame the code will just look for a matching hue too keep track (less precise but computationally faster). But in the line "hBox=HT{k}(hsvFrame);" the coder accuses that error and it doesn't make sense. The assignment of HT once every 12 frames already fills all cells, and in the others it should use its stored values (because they are persistent, right?).
so, any hints on what I'm missing?
if rem(n,12)==1
fBox=FT(frame);
if ~isempty(fBox)
HT=cell(size(fBox,1),1);
for k=1:size(fBox,1)
HT{k}=HTbase;
initializeObject(HT{k},hsvFrame,fBox(k,:));
end
end
end
if ~isempty(fBox)
for k=1:size(fBox,1)
if ~isempty(HT)
hBox=HT{k}(hsvFrame);
end
...
end
end

답변 (1개)

Tony Mohan Varghese
Tony Mohan Varghese 2018년 3월 22일
Solutions :
  • Use recognized pattern for assigning elements
  • Use repmat
  • Use coder.nullcopy

제품

Community Treasure Hunt

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

Start Hunting!

Translated by