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

2 次查看(过去 30 天)
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 个评论
Stefan Raab
Stefan Raab 2016-2-1
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

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2016-2-1
编辑:Walter Roberson 2016-2-1
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by