# How to acquire the points of the convex hull?

4 views (last 30 days)
Francisco Mendoza on 12 Dec 2014
I have this script that suppose have to detect an object (hand for example) and draw his contour using the convex hull information. Then, if i put my hand, i want to set points upon every vertex on it.
The code is:
_____________________________
function mano_move
vid = videoinput('macvideo', 1, 'YCbCr422_1280x720'); vid.ReturnedColorSpace = 'rgb'; preview(vid);
for n=1:100
A = getsnapshot(vid); I=imresize(A,0.5);
B=I;
r=I(:,:,1); b=I(:,:,3); g=I(:,:,2);
hand=r-b/2; I=hand>35; II=bwareaopen(I,2500); loc = regionprops(II , {'centroid' , 'area'});
if isempty(loc) imshow(B); drawnow;
else CH = bwconvhull(II); [n, m]=size(CH);
for i=1:n
for j=1:m-1
r=j-1;
if r>0
if ((CH(i,j)==0 && CH(i,j-1)==1) || (CH(i,j)==0 && CH(i,j+1)==1))
B(i,j,1)=255;
B(i,j+1,1)=255;
B(i,j-1,1)=255;
B(i,j,2)=0;
B(i,j+1,2)=0;
B(i,j-1,2)=0;
B(i,j,3)=0;
B(i,j+1,3)=0;
B(i,j-1,3)=0;
else
O=0;
end
else
o=0;
end
end
end
[~ , id] = max([loc.Area]);
m=loc(id).Centroid(1);
c=loc(id).Centroid(2);
imshow(B);
hold on; plot(m+50,c-50, '-m+');
x=m+50;
y=c-50;
rectangle('Position',[x-25,y-25,50,50],...
'Curvature',0.4,...
'LineWidth',2,...
'LineStyle','--')
daspect([1,1,1])
drawnow end end
closepreview(vid); close all clear all
end
__________________________
The output is like:
Then, in every vertex, show a point that indicates the end of a finger.
Also I need to erase the palm from the binary, leaving just the fingers and using the Regionprops function, count the total of areas in the frame, that correspond to the number of fingers, and display it.
I have another problem whit this and some others algorithms whit this same estructure: after few seconds, it gets very slowly and I don't know the reason.
I'll be grateful because your replies.