-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ultrasonic_Capture_Image_Mail_Face_detect.py
108 lines (86 loc) · 3.11 KB
/
Ultrasonic_Capture_Image_Mail_Face_detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import cv2
import time
import numpy as np
import time
import smtplib
import os
import imghdr
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import pygame
from pygame import mixer
TIMER = int(3)
date_string = time.strftime("%Y-%m-%d-%H:%M")
i = 0
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
capture = cv2.VideoCapture(0)
result = True
while (result):
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
net.setInput(blob)
detections = net.forward()
cv2.imshow('Capturing Photo', frame)
#cv2.imwrite("pics/at_{}.jpg".format(current_time),frame)
k = cv2.waitKey(100)
if len(detections)>0:
prev = time.time()
while TIMER >= 0:
ret, frame = capture.read()
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(frame, str(TIMER),
(200, 250), font,
7, (0, 255, 255),
4, cv2.LINE_AA)
cv2.imshow('Capturing Photo', frame)
cv2.waitKey(125)
cur = time.time()
# Update and keep track of Countdown
# if time elapsed is one second
# than decrese the counter
if cur-prev >= 1:
prev = cur
TIMER = TIMER-1
else:
ret, frame = capture.read()
# Display the clicked frame for 2
# sec.You can increase time in
# waitKey also
cv2.imshow('Capturing Photo', frame)
# time for which image displayed
cv2.waitKey(2000)
Timer = int(3)
# Save the frame
image_cap = "Robot_image" + date_string + ".jpg".format(i)
cv2.imwrite(image_cap, frame)
i+=1
msg = MIMEMultipart()
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
msg['Subject'] = 'Python Mail'
body = 'Automated mail, image captured from the webcam'
msg.attach(MIMEText(body, 'plain'))
filename = "Robot_image" + date_string + ".jpg".format(i)
attachment = open(filename, 'rb')
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename=" +filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("[email protected]", "Stumbleupon01")
server.sendmail("[email protected]", "[email protected]", text)
server.quit()
elif k == 27:
break
capture.release()
cv2.destroyAllWindows()
os.remove("Robot_image" + date_string + ".jpg".format(i))