In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Python controls your mobile computer to take pictures and send mailboxes automatically. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The idea of this article
1. Use opencv to call the camera to take photos and save the image locally.
two。 The email content is constructed with email library, and the saved image is inserted into the email content as an attachment.
3. Use the smtplib library to send mail to the specified mailbox
Code part
Module import
Import timeimport cv2 from email.mime.image import MIMEImage # Library used to construct message content from email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib # send mail
Authorization code (preferably write your own)
Pwd = "*"
Server interface
Host = 'smtp.163.com'port = 25sender =' * @ 163.com'# it's best to write your own receiver ='* @ qq.com' # it's best to write your own
Take pictures and save images.
Def GetPicture (): "": return: "" # create a window cv2.namedWindow ('camera', 1) # call camera IP camera 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) # Keypress key = cv2.waitKey (10) if key = 27: # esc break if key = = 32: # Space fileaname = 'frames.jpg' cv2.imwrite (fileaname, img) # release camera cap.release () # close window cv2.destroyWindow ("camera")
Message formatting
Def SetMsg (): ": return:"msg = MIMEMultipart ('mixed') # title msg [' Subject'] = 'Sister photo' msg ['From'] = sender # sender mailbox msg [' To'] = receiver # receiver mailbox # email body text = 'here comes the photo of your sister, please receive' text_plain = MIMEText (text, 'plain') 'utf-8') # body transcoding msg.attach (text_plain) # Picture attachment SendImageFile = open (' read / control camera to take pictures and send email / frames.jpg', 'rb'). Read () image = MIMEImage (SendImageFile) # change the name of the attached photo seen by the recipient to people.png. Image ['Content-Disposition'] =' attachment; filename = "people.png" 'msg.attach (image) return msg.as_string ()
Send an email
Def SendEmail (msg): "": param msg: email content: 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. Set the message format msg = SetMsg () # 3. Send email SendEmail (msg)
All codes
Import timeimport cv2 # pip install opencv-python-I Mirror Source URL from email.mime.image import MIMEImage # Library used to construct email content from email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib # send email # Authorization Code pwd = "*" # it's best to write your own # server interface host = 'smtp.163.com'port = 25sender =' * @ 163.com'# Better write your own receiver ='* @ qq.com' # it's best to write your own def GetPicture (): # create a window cv2.namedWindow ('camera' 1) # call camera IP camera 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) # Keypress key = cv2.waitKey (10) if key = = 27: # esc break if key = = 32: # Space fileaname = 'frames.jpg' cv2.imwrite (fileaname) Img) # release camera cap.release () # close window cv2.destroyWindow ("camera") def SetMsg (): msg = MIMEMultipart ('mixed') # title msg [' Subject'] = 'little sister photo' msg ['From'] = sender # sender mailbox msg [' To'] = receiver # receiver mailbox # email body text The picture of your little sister has arrived Please receive 'text_plain = MIMEText (text,' plain', 'utf-8') # body transcoding msg.attach (text_plain) # Picture attachment SendImageFile = open (' read / control camera to take pictures and send email / frames.jpg', 'rb'). Read () image = MIMEImage (SendImageFile) # change the name of the attached photo seen by the recipient to 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. Set the message format msg = SetMsg () # 3. Send email SendEmail (msg) Thank you for your reading! This is the end of the article on "how to control the mobile computer to take photos and send email automatically". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.