can't understand the cause of this error, trying to crop multi blobs in one image
Mostrar comentarios más antiguos
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 comentario
Stefan Raab
el 1 de Feb. de 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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Track Objects and Estimate Motion 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!