I am trying to find only spherical objects like ball … I wrote a code to track the "orange" colored ball but it is not showing anything so please tell me the mistake…….and also how to track object of different shape with with different colors..
vid=videoinput('winvideo',2,'I420_320x240'); set(vid,'FramesPerTrigger',Inf); set(vid,'ReturnedColorspace','rgb'); vid.FrameGrabInterval=2; framesneeded=300; start(vid) while(vid.FramesAcquired<=framesneeded) RGB=getsnapshot(vid); R=RGB(:,:,1); R=fliplr(R); G=RGB(:,:,2); G=fliplr(G); B=RGB(:,:,3); B=fliplr(B); RGB=cat(3,R,G,B); R=((R+G))-(B); bw=R>60; bw=medfilt2(bw,[3 3]); bw=bwareaopen(bw,20); bw=bwconncomp(bw,8); stats=regionprops(bw,'CENTROID','Eccentricity'); imshow(RGB) hold on if length(stats)>1 ecc= stats(1).Eccentricity; if(ecc<0.2) cent=stats(1).Centroid; plot(cent(1),cent(2),'+','MarkerfaceColor','g','markerSize',30); end end hold off flushdata(vid); end
Best Answer