clear all; 
ir_Read = input('is there any person? (high/low): ','s');
if strcmp(ir_Read,'high');
cam=webcam('EasyCamera');
cam.Resolution='424x240';
video_Frame=snapshot(cam);
video_Player=vision.VideoPlayer('Position',[100 100 424 240]);
face_Detector=vision.CascadeObjectDetector();
point_Tracker=vision.PointTracker('MaxBidirectionalError',2);
run_loop=true;
number_of_points=0;
frame_Count=0;

while run_loop && frame_Count<40
     video_Frame=snapshot(cam);
    gray_Frame=rgb2gray(video_Frame);
    frame_Count=frame_Count+1;
    
    if number_of_points<10
        face_Rectangle = face_Detector.step(gray_Frame);
        if ~isempty(face_Rectangle)
            points=detectMinEigenFeatures(gray_Frame,'ROI',face_Rectangle(1,:));
            
            xy_Points = points.Location;
            number_of_Points = size(xy_Points,1);
            release(point_Tracker);
            initialize(point_Tracker,xy_Points,gray_Frame);
            
            previous_Points=xy_Points;
            
            rectangle = bbox2points(face_Rectangle(1, :));
            face_Polygon =reshape(rectangle',1 ,[]);
            video_Frame = insertShape(video_Frame,'polygon',face_Polygon,'LineWidth',3 );
            video_Frame = insertMarker(video_Frame,xy_Points,'color','white');
        end
    else
        [xy_Points,isFound]= step(point_Tracker,gray_Frame);
        new_Points = xy_Points(isFound,:);
        old_Points = previous_Points(isFound,:);
        
        number_of_Points =size(new_Points,1);
        if number_of_Points >= 10
            [xform,old_Points,new_Points]=estimateGeometricTransform(...
                old_Points,new_Points,'similarity','MaxDistance',4);
            
            rectangle= transformPointsForward(xform,rectangle);
            face_Polygon = reshape(rectangle',1,[]);
            video_Frame = insertShape(video_Frame,'polygon',face_Polygon,'LineWidth',3);
            video_Frame = insertMarker(video_Frame,new_points,'color','white');
            previous_Points=new_Points;
            setPoints(point_Tracker,previous_points);
        end
        end
step(video_Player,video_Frame);
run_loop = isOpen(video_Player);
    
    end
clear cam;
release(video_Player);
release(point_Tracker);
release(face_Detector);
flag=0;
s=input('temperature is ');
disp(s);
if (s < 92.5)
    disp('open right gate');
else 
    disp('open left  gate');
    flag=1;
end
if (flag == 1)
    disp("please show your id card near camera and wait upto thaknyou");
    flag=2;
end
pause(8);
if (flag == 2)
    
    cam=webcam('EasyCamera');
preview(cam);
pause(2);
img=snapshot(cam);
image(img);
disp('thankyou');
clear cam;
imwrite(img,'shashank.jpg');


gmail={'sk11rsvm@gmail.com','amit.pramanik21@gmail.com', ...
    'sunidhipriyadarshini@gmail.com','monimoy41@gmail.com'};
myaddress='shashankumar.saini@gmail.com';
mypassword='8797440009';
setpref('Internet','E_mail','myaddress');
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password',mypassword);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class',....,
    'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
sendmail(gmail,'information','suspect','shashank.jpg');
delete('shashank.jpg');
end
end