current position:Home>Python controls its own mobile camera to take photos, and automatically sends the photos to the mailbox (for learning reference only)
Python controls its own mobile camera to take photos, and automatically sends the photos to the mailbox (for learning reference only)
2022-07-29 07:43:23【Panda aiqia rice】
Hey, everyone, good duck ! I'm a panda
Let's finish this simple case with you today ~
Want to complete today's case , Just remember one key point :
You need a camera
Don't talk much , Let's get started
what are you having? python I won't answer the related error report 、 Or source code information / Module installation /
Women's clothing bosses are proficient in skillsYou can come here :(https://jq.qq.com/?_wv=1027&k=2Q3YTfym) perhaps +V:python10010 Ask me
Start code
Tool import
import time
import cv2 # pip install opencv-python -i Mirror source URL
from email.mime.image import MIMEImage # A library for building mail content
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import smtplib # Send E-mail
Call the camera , Save the picture
Taking pictures , It's a camera with a mobile phone , The software uses :IP camera ( Android ), Because in the same LAN , open APP, The web address that appears inside is the address of the camera
def GetPicture():
""" Take pictures and save images :return: """
# Create a window
cv2.namedWindow('camera', 1)
# Call the camera IP camera APP
video = "http://admin:[email protected]:8081/video"
cap = cv2.VideoCapture(video)
while True:
success, img = cap.read()
cv2.imshow("camera", img)
# Press the key to handle
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 code , There will be an effect
Create a function , Set up my email content
def SetMsg():
""" Format mail :return: """
msg = MIMEMultipart('mixed')
# title
msg['Subject'] = ' Photos of little sister '
msg['From'] = sender # Sender's email
msg['To'] = receiver # Receiver's email
# Message body
text = ' Here comes the picture of your little sister , Please accept '
text_plain = MIMEText(text, 'plain', 'utf-8') # Text transcoding
msg.attach(text_plain)
# Picture attachment
SendImageFile = open('D:/ Control the camera to take pictures and send emails /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 = "******" # You'd better write your own
# Server interface
host = 'smtp.163.com'
port = 25
sender = '[email protected]' # You'd better write your own
receiver = '[email protected]' # You'd better write your own
Send mail function
def SendEmail(msg):
""" Send E-mail :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. Take photos and save
GetPicture()
# 2. Format the message
msg = SetMsg()
# 3. Send E-mail
SendEmail(msg)
Run code , Demonstration effect
Take a picture first
Sent to email
What about? , Is today's case very simple ?
I hope my article can be helpful to you who are learning by yourself ~
I'm a panda , See you in the next article (*◡‿◡)
copyright notice
author[Panda aiqia rice],Please bring the original link to reprint, thank you.
https://en.hqmana.com/2022/210/202207290738380114.html
The sidebar is recommended
- Today's sharing + daily summary
- Hydrologist
- Old apricot tree
- The girl eats the duck's head, and the girl thinks the duck's head is salty - 31 of Yi Lisheng's couplet
- Special day
- Deep cognition: how to make faster progress in writing?
- No one understands her
- When you fly to your mountain like a bird: we have all been hurt
- Qingpingle • green mountains like ancient times
- How is Gu Shaoqiang, who wrote the resignation letter "the world is so big, I want to see it"
guess what you like
Untitled
Hidden town - "Qingmuchuan"
Lovely students
The quickest way to raise a boy is to spoil him
Occasionally write a poem
As soon as I said something, all four people were surprised: I have a collection of nearly 10000 books
Art selection
Wake up
Continue to embroider
Beauty always comes quietly without notice
Random recommended
- A simple book in the eyes of science students (3) -- how hot can the articles of big guys be
- Untitled - draft
- The people and environment Photography Competition (exhibition) was selected into the general menu of the 2022 Shanghai citizens' Cultural Festival
- "Sweet moon dew of magic pet sweetheart"
- Talk less and do more
- Don't blame your subordinates
- Skip class k song
- Teacher Yang Zaichun talks about the key points of the early calligraphy
- At that time, our childhood was an idyllic poem!
- Dark struggle
- Oh, human
- Argument
- Listen to the voice of mother (long educational Documentary Series 004)
- Android uses cameraX to preview / take photos / record videos / analyze pictures / focus / switch cameras and other operations
- Uniformity of information
- Everything is settled.
- informal essay
- Tea garden girl
- Walk into Lishan
- In July, you are the sultry wind
- Meditation
- Raindrops on the window
- Why do women wear high heels
- Wu Tai
- Xichen
- Exquisite spiral spoon? Don't buy this kind of thing
- Children accompanied by mobile phones
- Luminous night
- Elegant and free
- "Quiet wind and smoke"
- Popular science ---- summer killer
- This society is fragile and untenable
- Wild flower fragrance (112)
- Guidong "three thousand Lake scenic spot"
- Travel in Dongguan, Shenzhen on weekends and take photos in the Japanese xiaoqingxin Park
- Delicate flowers
- Manual - silk screen flower
- Ancient roads and Tianchi
- fly a kite
- The wind blows the wheat waves