我有一个程序可以检测人脸并将其保存到文件夹中。我想把这些图片发送到一个电子邮件id,但我不知道怎么做。你知道吗
以下是保存图像的代码:
import cv2
#import the cascade for face detection
FaceClassifier =cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# access the webcam (every webcam has
capture = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = capture.read()
if not capture:
print ("Error opening webcam device")
sys.exit(1)
# to detect faces in video
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = FaceClassifier.detectMultiScale(gray, 1.3, 5)
# Resize Image
minisize = (frame.shape[1],frame.shape[0])
miniframe = cv2.resize(frame, minisize)
# Store detected frames in variable name faces
faces = FaceClassifier.detectMultiScale(miniframe)
# Draw rectangle
for f in faces:
x, y, w, h = [ v for v in f ]
cv2.rectangle(frame, (x,y), (x+w,y+h), (255,255,255))
#Save just the rectangle faces in SubRecFaces
sub_face = frame[y:y+h, x:x+w]
FaceFileName = "faces/face_" + str(y) + ".jpg"
cv2.imwrite(FaceFileName, sub_face)
#Display the image
cv2.imshow('Result',frame)
cv2.waitKey(180)
break
# When everything is done, release the capture
img.release()
cv2.destroyAllWindows()
我不知道如何将保存的图像发送到电子邮件id。请帮助!你知道吗
@Arpit说一定是smtp。使用smtplib有一个简单的方法:
从这里开始: SMTPLIB
我们用SendGrid来做这个。它是一个基于web的服务,并且有一个python模块与之接口。你知道吗
SendGrid
SendGrid Python Module
下面是一些附加PDF的示例代码,因此基本上您只需将FileType调用更改为图像的任何内容,并将FileName调用更改为图像。你知道吗
相关问题 更多 >
编程相关推荐