python定時采集攝像頭圖像上傳ftp服務器功能實現
來源:懂視網
責編:小采
時間:2020-11-27 14:29:56
python定時采集攝像頭圖像上傳ftp服務器功能實現
python定時采集攝像頭圖像上傳ftp服務器功能實現:首先是截圖,從攝像頭截取一幅圖像: 代碼如下:while 1: #測試攝像頭的存在 try: cam = Device() except: print no webcam found! continue break 然后是把圖像上傳到ftp服務器: 代碼如下:remote = ftplib.FTP('127.0.0
導讀python定時采集攝像頭圖像上傳ftp服務器功能實現:首先是截圖,從攝像頭截取一幅圖像: 代碼如下:while 1: #測試攝像頭的存在 try: cam = Device() except: print no webcam found! continue break 然后是把圖像上傳到ftp服務器: 代碼如下:remote = ftplib.FTP('127.0.0

首先是截圖,從攝像頭截取一幅圖像:
代碼如下:
while 1: #測試攝像頭的存在
try:
cam = Device()
except:
print "no webcam found!"
continue
break
然后是把圖像上傳到ftp服務器:
代碼如下:
remote = ftplib.FTP('127.0.0.1') #登陸服務器
remote.login()
file = open('%s.jpg'%cur_time,'rb') #用時間來命名圖片
remote.storbinary('STOR %s.jpg'%cur_time,file) #上傳圖片
file.close()
當然了,最后把圖片刪除
下面是每隔一秒鐘,把從攝像頭采集的圖片上傳到本機ftp的程序:
代碼如下:
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()
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
python定時采集攝像頭圖像上傳ftp服務器功能實現
python定時采集攝像頭圖像上傳ftp服務器功能實現:首先是截圖,從攝像頭截取一幅圖像: 代碼如下:while 1: #測試攝像頭的存在 try: cam = Device() except: print no webcam found! continue break 然后是把圖像上傳到ftp服務器: 代碼如下:remote = ftplib.FTP('127.0.0