Python regular collection of camera image upload FTP server function
- 2020-04-02 13:17:08
- OfStack
The first is a screenshot, which captures an image from the camera:
while 1: # Test the existence of the camera
try:
cam = Device()
except:
print "no webcam found!"
continue
break
Then upload the image to the FTP server:
remote = ftplib.FTP('127.0.0.1') # Login server
remote.login()
file = open('%s.jpg'%cur_time,'rb') # Name the picture by time
remote.storbinary('STOR %s.jpg'%cur_time,file) # To upload pictures
file.close()
Of course, delete the image at the end
Here's how to upload pictures from the camera to the local FTP every second:
<span style="font-family: Song typeface , Arial; line-height: 15px; background-color: rgb(245, 247, 248); "> </span><pre name="code" class="python">remote = ftplib.FTP('219.246.57.162')
remote.login()
while 1:
try:
remote.nlst("1.txt")
except:
print "not ready to start!"
continue
timex = time.localtime()
cur_time = "%4d%02d%02d%02d%02d%02d"%(timex[0],timex[1],timex[2],timex[3],timex[4],timex[5])
cam.saveSnapshot('%s.jpg'%cur_time)
#remote.dir()
file = open('%s.jpg'%cur_time,'rb')
remote.storbinary('STOR %s.jpg'%cur_time,file)
file.close()
os.system("del %s.jpg"%cur_time)
#print "upload ok!"
time.sleep(1)
remote.quit()</pre><br>
<pre></pre>
<p></p>
<pre></pre>
<p></p>