Search This Blog

Virtual Pen in MATLAB

clc

clear all

close all

warning off

centroids=[];

c=webcam;

while true

e=c.snapshot;

mkdir=createMask(e);

mkdir=imfill(mkdir,'holes');

mkdir=bwareaopen(mkdir,20);

BW = bwareafilt(mkdir, 1);

L = bwlabel(BW);

s = regionprops(L, 'centroid');

centroids =[centroids;cat(1, s.Centroid)];

if(~isempty(centroids))

    subplot(1,2,1);

    imshow(e);

    subplot(1,2,2);

    imshow(e);

    hold on

plot(centroids(:,1), centroids(:,2),'r-','linewidth',3);

else

    subplot(1,2,1);

    imshow(e);

    subplot(1,2,2);

    imshow(e);

end

drawnow;

hold off

end

 


Join us on Telegram: https://t.me/matlabcastor

1 comment:

  1. Undefined function 'createMask' for input arguments
    of type 'uint8'.

    Error in labproject (line 17)
    mkdir=createMask(e);


    This is the error I got when i run this code
    what should i do to rectify it?

    ReplyDelete

MATLAB