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
centroidsis 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 shapecentroidsis (i.e. if it'sN x 2or2 x N) becausedetectObjectsis 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 uselineyou need to provide thexlocations and endingylocations for each segment of the line that you want.Assuming that the first row/column is the
xcoordinates and the second row/column is theycoordinates, do this:centroids - N x 2centroids - 2 x NAs a minor note, the
xandyvariables in thelinecall 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.