Kindly have a look at this code and help me out. I am doing something wrong with the Matlab line command. The code give warnings and then crashes. The error is in the 2nd last line.
while ~isDone(videoSource)
frame = readFrame(videoSource);
mask = detectObjects(frame,Fgdetector);
[areas, centroids, bboxes]= step(blobAnalyser,mask);
% tracing boundires around the detected obbjects
% BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(mask,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
%for star skeleton
x = boundary(:,2);
y = boundary(:,1);
indexes = convhull(x, y);
hold on;
% plot(x(indexes), y(indexes), 'm-', 'LineWidth', 2);
line([x(indexes(k)), centroids], [y(indexes(k)),centroids ], 'Color', 'r', 'LineWidth', 2);
end
What I suspect is happening is that
centroids
is a N x 2 array, or a 2 x N array and you are trying to concatenate a matrix with a single value to create another matrix. The sizes are inconsistent and so that's why you're getting that error. I don't know what shapecentroids
is (i.e. if it'sN x 2
or2 x N
) becausedetectObjects
is something you wrote, or a function that exists in a later version of MATLAB that I don't have access to, so one of these should work. When you useline
you need to provide thex
locations and endingy
locations for each segment of the line that you want.Assuming that the first row/column is the
x
coordinates and the second row/column is they
coordinates, do this:centroids - N x 2
centroids - 2 x N
As a minor note, the
x
andy
variables in theline
call look like they are coordinates for the convex hull of your shapes. You are trying to combine these with the centroids... which doesn't really make any sense. Stick with drawing one or the other. If you want to draw both, then make two separate line calls:Don't mix apples and oranges together.