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

조회 수: 1 (최근 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