SUMMER-INTERN TASK 6

kundan singh
2 min readJun 21, 2021

Task Description 📄

❄️ Create a program that perform below mentioned task upon recognizing a particular face.

📌 When it recognize your face then -

👉 It send mail to your mail id by writing this is face of your name.

👉 Second it send WhatsApp message to your friend, it can be anything.

📌 When it recognize second face, it can be your friend or family members face.

👉 Create EC2 instance in the AWS using CLI.

👉 Create 5 GB EBS volume and attach it to the instance.

We proceed with simple concepts like whatever technique and library we will use to do this task we will discuss.

Some of python library we already discussed in my previous article , please read that first for better understanding.

Here we used Cascade Classifier which help to detect face

face_classifier = cv2.CascadeClassifier(cv2.data.haarcascades + ‘haarcascade_frontalface_default.xml’)

create model for faces .here we create model for two person’s face one is me and another is my friend.

import cv2
import numpy as np
from os import listdir
from os.path import isfile, join

# Get the training data we previously made
data_path = ‘./faces/user/face1/’
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))]

# Create arrays for training data and labels
Training_Data, Labels = [], []

# Open training images in our datapath
# Create a numpy array for training data
for i, files in enumerate(onlyfiles):
image_path = data_path + onlyfiles[i]
images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
Training_Data.append(np.asarray(images, dtype=np.uint8))
Labels.append(i)

# Create a numpy array for both training data and labels
Labels = np.asarray(Labels, dtype=np.int32)

# Initialize facial recognizer
# model = cv2.face.createLBPHFaceRecognizer()
# NOTE: For OpenCV 3.0 use cv2.face.createLBPHFaceRecognizer()
# pip install opencv-contrib-python
# model = cv2.createLBPHFaceRecognizer()

face1_model = cv2.face_LBPHFaceRecognizer.create()
# Let’s train our model
face1_model.train(np.asarray(Training_Data), np.asarray(Labels))
print(“Model trained sucessefully”)

Now we create the fuctions for sending mail ,sms, and for create EC2 instances

MAIL:

MAIL:def mail():
Sender_Email = "ksp220798@gmail.com"
Reciever_Email = "ksp220798@gmail.com"
Password = "#######"
newMessage = EmailMessage()
newMessage['Subject'] = "Check out the new logo"
newMessage['From'] = Sender_Email
newMessage['To'] = Reciever_Email
newMessage.set_content('This is your face kundan!')
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(Sender_Email, Password)
smtp.send_message(newMessage)

SMS:

def sms():
driver = webdriver.Chrome('C:/Users/1398a/Downloads/chromedriver_win32/chromedriver.exe')
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)
target = '"Rohit"'
string = "Message sent using Python!!!"
x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located(( By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//div[@class="input"][@dir="auto"][@data-tab="1"]'
input_box = wait.until(EC.presence_of_element_located((
By.XPATH, inp_xpath)))
for i in range(100):
input_box.send_keys(string + Keys.ENTER)
time.sleep(1)

AWS+EC2+ATTACHMENT

y=subprocess.getoutput("aws ec2 run-instances --image-id ami-0ad704c126371a549 --instance-type t2.micro --key-name MyKeyPair --count 1")
y=json.loads(y)
instance_id=y['Instances'][0]['InstanceId']
z=subprocess.getoutput("aws ec2 create-volume --volume-type gp2 --availability-zone ap-south-1a --size 1")
z=json.loads(z)
volume_id=z['VolumeId']
print(instance_id)
print(volume_id)
time.sleep(120)
cmd="aws ec2 attach-volume --device /dev/xvdg --instance-id {} --volume-id {}".format(instance_id,volume_id)
print(cmd)
t=subprocess.getoutput(cmd)
print(t)

Thank you

--

--