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

4 ビュー (過去 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 Center および File ExchangeRecognition, Object Detection, and Semantic Segmentation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by