what means this error , while trying to use vision.blobAnalysis to detect motions?
1 次查看(过去 30 天)
显示 更早的评论
what means this error , while trying to use vision.blobAnalysis to detect motions?
Error using coder.internal.errorIf (line 8)
The POSITION matrix must have four columns for shape Rectangle
Error in insertShape>errIf1 (line 796)
coder.internal.errorIf(condition, msgID, strArg);
Error in insertShape>crossCheckShapePosition (line 347)
errIf1(errCond, 'vision:insertShape:posColsNot4ForRect', shape);
Error in insertShape>crossCheckInputs (line 317)
crossCheckShapePosition(shape, position);
Error in insertShape>validateAndParseInputs (line 176)
crossCheckInputs(shape2, position, color);
Error in insertShape (line 103)
validateAndParseInputs(I, shape, position, varargin{:});
Error in btw (line 134)
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
回答(1 个)
Walter Roberson
2015-11-22
Check size(bbox) . The bbox that you are passing in must have 4 columns, such as a row vector of 4 elements.
12 个评论
syhem samti
2015-11-23
blob generation works well in my code, but when i try to extract MajorAxisLength, MinorAxisLength of each blob...this error appears
Walter Roberson
2015-11-23
编辑:Walter Roberson
2015-11-23
Please show your call to vision.BlobAnalysis and your step() command
Image Analyst
2015-11-23
This is not what you originally said. You said there was a problem with rectangle and bbox. Did you solve that problem and now have this new one???? Aren't MajorAxisLength and MinorAxisLength computed by regionprops()? You don't even show that code or even mention that in your original question. It's hard for people to answer questions about code that is not shown, don't you think?
Walter Roberson
2015-11-23
The blob analysis can be configured to output major and minor axis lengths, but the order of the outputs becomes positional according to the exact options you have enabled, rather than by structure. The order of the positional outputs is not well defined in the blobanalysis step() documentation, and would have to be presumed that any one further down the list would appear to the right of any one further up higher in the list.
Chances are that the poster is expecting the outputs in the wrong order and passing what they think should be the bbox output but is a different output.
Image Analyst
2015-11-23
I don't have that toolbox. I know the Computer Vision Toolbox requires the Image Processing Toolbox so I wouldn't be surprised if it called regionprops() internally.
The link you gave says "The order of the returned values when there are multiple outputs are in the order they are described below:"
It looks like if you call
[AREA,CENTROID,BBOX] = step(H,BW)
you get those 3 results. Then, if you want any others, you have to call them in a very specific order - the order listed in the help. It seems weird and inconvenient that you have to call
[___, someResult] = step(H,BW);
a bunch of times serially to get what you want rather than just asking for it directly like you can with regionprops(). Anyway, the next two after those 3 are MajorAxis and MinorAxis.
Again, the poster does not seem to show any of this code where MajorAxis is asked for.
Walter Roberson
2015-11-23
You do not call serially, it is
[AREA*, CENTROID*, BBOX*, MAJORAXIS*, MINORAXIS*, ORIENTATION*...] = step(H, BW)
where each * is intended to indicate here that the corresponding output might be omitted depending on which *OutputPort you configured. For example you might end up with
[CENTROID, MAJORAXIS] = step(H,BW)
if you turned off AreaOutputPort and BoundingBoxOutputPort and turned on MajorAxisLengthOutputPort .
Vision.BlobAnalysis works in the System Objects paradigm, with the ability to generate optimized code that reduces memory transfers. I doubt it calls into regionprops().
syhem samti
2015-11-23
编辑:syhem samti
2015-11-24
here the code is:
function videoAnalysis()
clear all;
close all;
clc;
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, 'NumTrainingFrames', 50);
videoReader = vision.VideoFileReader('video6.avi');
% fRate = videoReader.info.VideoFrameRate;
% disp(fRate);
for i = 1:50
frame = step(videoReader);
foreground = step(foregroundDetector, frame);
end
imwrite(foreground,'foreground1.jpg')
BW = imread('foreground1.jpg');
%Calculate the perimeters of objects in the image.
BWs = bwperim(BW,8);
%Display the original image and the perimeters side-by-side.
%imshowpair(BW,BWs,'montage')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
%The binary gradient mask is dilated using the vertical structuring element followed by the horizontal structuring element. The imdilate function dilates the image.
BWsdil = imdilate(BWs, [se90 se0]);
%figure, imshow(BWsdil), title('dilated gradient mask');
BWdfill = imfill(BWsdil, 'holes');
% figure, imshow(BWdfill);
% title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
%figure, imshow(BWnobord), title('cleared border image');
seD = strel('diamond',9);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
%figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = BW;
Segout(BWoutline) = 255;
%figure, imshow(Segout), title('outlined original image');
se = strel('square', 3);
fF = imopen(Segout, se)
se1 = strel('square', 5);%masque
ForF = imdilate(fF, se1);
%figure; imshow(ForF); title('finaal foreground ')
L = bwlabel(ForF);% connected component (seulement sur les images binaires
s = regionprops(L, 'Area');
s(1)
area_values = [s.Area]
idx3 = find((5500 <= area_values) & (area_values <= 1900000))
bw3 = ismember(L, idx3);
figure, imshow(bw3);title(' finaal foreground ')
se = strel('square', 3);
filteredForeground = imdilate(bw3, se)
figure, imshow(filteredForeground);
title('Fforeground')
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 350 , 'MaximumBlobArea', 15000, ...
'MajorAxisLengthOutputPort' , true, 'MaximumCount', 5);
[centroid, bbox] = step(blobAnalysis, filteredForeground)
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numPerso = size(bbox, 1);
result = insertText(result, [10 10], numPerso, 'BoxOpacity', 1, 'FontSize', 14);
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
videoPlayer.Position(3:4) = [650,400]; % window size: [width, height]
% se = strel('square', 3); % morphological filter for noise removal
i = 0;
while ~isDone(videoReader)
% if ( mode(i,10) == 0 )
% disp(i);
% end
% i = i + 1;
frame = step(videoReader); % read the next video frame
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, frame);
% Use morphological opening to remove noise in the foreground
% filteredForeground = imopen(foreground, se);
%%by me
se = strel('square', 3);
filteredForeground = imdilate(bw3, se)
%figure, imshow(filteredForeground);
%title('Fforeground')
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
% Draw bounding boxes around the detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'blue');
% imshow(result);
%
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
result = insertText(result, [10 10], numPerso, 'BoxOpacity', 1, 'FontSize', 14);
%if there is moving object
if numPerso == 0
result = insertText(result, [100 20], 'non motion detected', 'BoxOpacity', 1, 'FontSize', 14, 'BoxColor', 'green');
else
result = insertText(result, [100 20], 'motion detected', 'BoxOpacity', 1, 'FontSize', 14, 'BoxColor', 'red');
end
step(videoPlayer, result); % display
end
release(videoReader); % close
end
Walter Roberson
2015-11-24
Look at your code again:
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 350 , 'MaximumBlobArea', 15000, ...
'MajorAxisLengthOutputPort' , true, 'MaximumCount', 5);
[centroid, bbox] = step(blobAnalysis, filteredForeground)
You have 'CentroidOutputPort', false so the centroid output is not going to be produced. The bounding box is going to be the first output (and there is not going to be a second output)
bbox = step(blobAnalysis, filteredForeground);
Walter Roberson
2015-11-24
[bbox, MajorAxisLength] = step(blobAnalysis, filteredForeground);
I overlooked that you had that turned on as well.
syhem samti
2015-11-26
thank you for you answers...i tried this too but another error appears...anyway i just found another way to extract those attributes
NIHARIKA MITTAL
2017-11-12
Can you please share the other way. I am also stuck in this same situation
另请参阅
类别
在 Help Center 和 File 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!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)