Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python control the mobile phone camera to take pictures and send them to the mailbox automatically?

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "Python how to control the mobile phone camera to take pictures and automatically send them to the mailbox". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to control the mobile phone camera to take pictures and automatically send them to the mailbox" can help you solve your doubts.

The idea is to use opencv to call the camera to take photos and save images and locally use email library to construct email content. The saved image is inserted as an attachment to email content. Send email to the specified mailbox using smtplib library to start code tool import import timeimport cv2 # pip install opencv-python-I mirror source URL from email.mime.image import MIMEImage # A library used to construct email content from email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib # send email call camera Save pictures

To take pictures, we use the camera of the mobile phone, and the software uses the IP camera (Android), because when you open APP in the same LAN, the URL that appears is the address of the camera.

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")

Run the code, and the effect will appear.

Create a function to set up the contents of my email

Def SetMsg (): "" email format setting: return: "msg = MIMEMultipart ('mixed') # title msg [' Subject'] = 'Little Sister Photo' msg ['From'] = sender # sender mailbox msg [' To'] = receiver # receiver mailbox # email body text = 'here's your little sister photo. 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 () Mail Port Settings

The authorization code can be obtained here.

# Authorization code pwd = "*" # it's best to write your own # server interface host = 'smtp.163.com'port = 25sender =' XXXX@163.com' # you'd better write your own receiver = 'XXXX@qq.com' # you'd better write your own email sending function def SendEmail (msg): "send email: 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 () encapsulate if _ _ name__ ='_ main__': # 1. GetPicture () # 2. Set the message format msg = SetMsg () # 3. Send email SendEmail (msg) to run the code to demonstrate the effect

Take a picture first.

Sent to the mailbox.

After reading this, the article "how to control the mobile phone camera to take pictures and send them to the mailbox automatically" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, please follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report