can't understand the cause of this error, trying to crop multi blobs in one image

2 visualizzazioni (ultimi 30 giorni)
hello, i'm working with video motion, here it can be the case where we found many object mobile, i used blobAnalysis to delimited them, i calcul for each one it variance, i used this code but an error appeared, can anyone help me please:
foregroundDetector = vision.ForegroundDetector(*....);
videoReader = vision.VideoFileReader('*.avi',...
'VideoOutputDataType','uint8');
J=0;
i=0;
while ~isDone(videoReader);
J=J+1
frameRGB = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frameRGB);
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 1700,'MaximumCount',2);
bbox = step(blobAnalysis, foreground);
result = insertShape(frameRGB, 'Rectangle', bbox, 'Color', 'green');
num = size(bbox,1);
if J>=1;
if num>1
for i=1: num
croppedImage = frameRGB(bbox(i, 2):bbox(i, 2)+bbox(i, 4), bbox(i, 1):bbox(i, 1)+bbox(i, 3), :);
blobVariance(i) = var(double(croppedImage(:)))
end
result = insertShape(frameRGB, 'Rectangle', bbox, 'Color', 'red');
result = insertText(result, [10 10], numperso, 'BoxOpacity', 1, ...
'FontSize', 14);
figure(1); imshow(result);
blobVariance=[];
croppedImage=[];
end
end
end
end and the error is:
Index exceeds matrix dimensions.
Error in MaxvariancecorriG (line *)
croppedImage = frameRGB(bbox(i, 2):bbox(i, 2)+bbox(i, 4), bbox(i, 1):bbox(i, 1)+bbox(i, 3),
:);
  1 Commento
Stefan Raab
Stefan Raab il 1 Feb 2016
Hey bay rem,
I am not familiar with the "step(videoPlayer)" function, but I suppose it results the frame as a matrix? Your error says, that you try to address an index which does not exist. Does "step" return a two dimensional array? Then you have too much indices in the "croppedImage = ..." command.
Kind regards, Stefan

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 1 Feb 2016
Modificato: Walter Roberson il 1 Feb 2016
croppedImage = frameRGB(bbox(i, 2):bbox(i, 2)+bbox(i, 4)-1, bbox(i, 1):bbox(i, 1)+bbox(i, 3)-1,:);
Remember, a width of 1 would mean that you should end at the same pixel, so your endpoint would be 0 further on from where you are. A width of 2 would mean you would end at the next pixel, so your endpoint would be 1 further on from where you are. And so on: a width of N requires a last index of N-1 beyond where you are.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by