最近一到办公室就会发现少点东西,每天少亿点,于是我下班了没关电脑,回家后用python控制电脑拍照后发现,这个背影怎么怎么像老板呢?
卧槽,每天趁我们下班了,晚上溜回公司抠我们的Alt键.... 这是抖音看多了吗?
话说这么晚才来公司,怕不是偷偷的背着老板娘洗jio去了才出来吧。
唉,太不地道了,洗jio不带我~
兄弟们,这个是正经的教程,不要拿来乱用,可以自己用自己的电脑或者手机试,但是别搞别人,懂的都懂!
针对不太会的兄弟,我特地录了视频,一步步的详细讲解,可以跟着视频操作~
视频地址:用python控制手机/电脑自动拍照并发送邮箱
模块导入
import time import cv2 from email.mime.image import MIMEImage # 用来构造邮件内容的库 from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import smtplib # 发送邮件 # Python学习交流群:924040232
授权码(最好写自己的)
pwd = "******"
服务器接口
host = 'smtp.163.com' port = 25 sender = '******@163.com' # 最好写自己的 receiver = '******@qq.com' # 最好写自己的
拍照保存图像
def GetPicture(): """ :return: """ # 创建一个窗口 cv2.namedWindow('camera', 1) # 调用摄像头 IP摄像头APP video = "http://admin:admin@192.168.3.32:8081/video" cap = cv2.VideoCapture(video) while True: success, img = cap.read() cv2.imshow("camera", img) # 按键处理 key = cv2.waitKey(10) if key == 27: # esc break if key == 32: # 空格 fileaname = 'frames.jpg' cv2.imwrite(fileaname, img) # 释放摄像头 cap.release() # 关闭窗口 cv2.destroyWindow("camera")
邮件格式设置
def SetMsg(): """ :return: """ msg = MIMEMultipart('mixed') # 标题 msg['Subject'] = '小姐姐照片' msg['From'] = sender # 发送方邮箱 msg['To'] = receiver # 接收方邮箱 # 邮件正文 text = '你要的小姐姐照片到了,请接收' text_plain = MIMEText(text, 'plain', 'utf-8') # 正文转码 msg.attach(text_plain) # 图片附件 SendImageFile = open('D:/控制摄像头拍照并发送邮件/frames.jpg', 'rb').read() image = MIMEImage(SendImageFile) # 将收件人看见的附件照片名称改为people.png. image['Content-Disposition'] = 'attachment; filename = "people.png"' msg.attach(image) return msg.as_string()
发送邮件
def SendEmail(msg): """ :param msg:邮件内容 :return: """ smtp = smtplib.SMTP() smtp.connect(host,port=25) smtp.login(sender, pwd) smtp.sendmail(sender, receiver, msg) time.sleep(2) smtp.quit() if __name__ == '__main__': # 1.拍照保存 GetPicture() # 2.设置邮件格式 msg = SetMsg() # 3.发送邮件 SendEmail(msg)
全部代码
import time import cv2 # pip install opencv-python -i 镜像源网址 from email.mime.image import MIMEImage # 用来构造邮件内容的库 from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import smtplib # 发送邮件 # 授权码 pwd = "******" # 最好写自己的 # 服务器接口 host = 'smtp.163.com' port = 25 sender = '******@163.com' # 最好写自己的 receiver = '****@qq.com' # 最好写自己的 def GetPicture(): # 创建一个窗口 cv2.namedWindow('camera', 1) # 调用摄像头 IP摄像头APP video = "http://admin:admin@192.168.3.32:8081/video" cap = cv2.VideoCapture(video) while True: success, img = cap.read() cv2.imshow("camera", img) # 按键处理 key = cv2.waitKey(10) if key == 27: # esc break if key == 32: # 空格 fileaname = 'frames.jpg' cv2.imwrite(fileaname, img) # 释放摄像头 cap.release() # 关闭窗口 cv2.destroyWindow("camera") def SetMsg(): msg = MIMEMultipart('mixed') # 标题 msg['Subject'] = '小姐姐照片' msg['From'] = sender # 发送方邮箱 msg['To'] = receiver # 接收方邮箱 # 邮件正文 text = '你要的小姐姐照片到了,请接收' text_plain = MIMEText(text, 'plain', 'utf-8') # 正文转码 msg.attach(text_plain) # 图片附件 SendImageFile = open('D:/控制摄像头拍照并发送邮件/frames.jpg', 'rb').read() image = MIMEImage(SendImageFile) # 将收件人看见的附件照片名称改为people.png. image['Content-Disposition'] = 'attachment; filename = "people.png"' msg.attach(image) return msg.as_string() def SendEmail(msg): smtp = smtplib.SMTP() smtp.connect(host,port=25) smtp.login(sender, pwd) smtp.sendmail(sender, receiver, msg) time.sleep(2) smtp.quit() if __name__ == '__main__': # 1.拍照保存 GetPicture() # 2.设置邮件格式 msg = SetMsg() # 3.发送邮件 SendEmail(msg)
兄弟们快去试试吧,想要资料教程电子书都在下方了…