如何调用摄像头_监控摄像头安装步骤

如何调用摄像头_监控摄像头安装步骤,第1张

如何调用摄像头_监控摄像头安装步骤 思路1、通过opencv调用摄像头拍照保存图像到本地2、用email库构造邮件内容,保存图片以附件形式插入邮件内容3、用smtplib库发送邮件到指定邮箱4、生成 .exe 文件5、设置开机自启(每次开机自动运行,启动相机,拍下照片发送到指定邮箱)导入工具import cv2 # pip install opencv-python -i {指定镜像源} 控制摄像头from email.mime.image imort MIMEImage #用来构造邮件内容的库from email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib #发送邮件编译环境系统:Windows10软件:Miniconda3-latest-Windows-x86_64模块:opencv-python smtplib numpy email pyinstaller生成exe文件pyinstaller -F -w path/camera.py设置开机自启1.右击exe 创建快捷方式2.win+r 输入以下命令 shell:startup 点击确定打开一个文件夹3.将生成的快捷文件复制到打开的文件中,下次开机exe程序就会自动启动python代码实现调用摄像头,并拍照发送邮件主要代码camera.pyimport cv2from email.mime.image import MIMEImagefrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipart# import smtplib #发送邮件import smtplibfrom smtplib import SMTPimport timehost = ‘smtp.qq.com’ #邮箱的接口port = ’25’ #端口pwd = ‘neelrhh88******ch’ #授权码sender = ‘邮箱地址’ #发送方receiver = “邮箱地址” #接收方path = r’./’ #图像保存路径images = time.strftime(“%Y-%m-%d-%H_%M_%S”,time.localtime())def GetPicture():“””拍照保存图像“””#创建一个窗口cameracv2.namedWindow(‘camera’,1) #’1′ 表示窗口不能随意拖动#调用摄像头cap = cv2.VideoCapture(0)ret,frame = cap.read() #读取摄像头内容cv2.imwrite(path+images+”.jpg”,frame) #保存到磁盘#释放摄像头cap.release()#关闭窗口cv2.destroyWindow(“camera”)def SetMsg():”’设置邮件格式:return:”’msg = MIMEMultipart(‘mixed’)#标题msg[‘Subject’] = ‘电脑已开机’msg[‘From’] = sendermsg[‘To’] = receiver#邮件正文内容text = ‘电脑已开机,请查收图片确认是否为本人’text_plain = MIMEText(text,’plain’,’utf-8′) #正文转码msg.attach(text_plain)#图片SendImageFile = open(path+images+’.jpg’,’rb’).read()image = MIMEImage(SendImageFile)image[‘Content-Disposition’] = ‘attachment;filename=”people.jpg”‘msg.attach(image)return msg.as_string()def SendEmail(msg):”’发送邮件:msg :邮件内容:return”’try:smtp = smtplib.SMTP_SSL(host,port) #创建一个邮件服务# smtp.connect(host)smtp.login(sender,pwd)smtp.sendmail(sender,receiver,msg)time.sleep(3)smtp.quit() #退出邮件服务except smtplib.SMTPException as e:print(“e”)#实现开机自启动#打包实现启动 例:exeif __name__ == ‘__main__’:# 1.拍照保存GetPicture()# 2. 设置邮件格式msg = SetMsg()# 3. 发送邮件SendEmail(msg)以上就是python实现调用摄像头并拍照发邮箱的详细内容啦

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/655946.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-18
下一篇2022-04-18

发表评论

登录后才能评论

评论列表(0条)

    保存