python定时采集摄像头图像上传ftp服务器功能实现

WBOY
풀어 주다: 2016-06-16 08:45:48
원래의
1695명이 탐색했습니다.

首先是截图,从摄像头截取一幅图像:

复制代码 代码如下:

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')<br>remote.login()<br>while 1:<br>    try:<br>        remote.nlst("1.txt")<br>    except:<br>        print "not ready to start!"<br>        continue<br>    timex = time.localtime()<br>    cur_time = "%4d%02d%02d%02d%02d%02d"%(timex[0],timex[1],timex[2],timex[3],timex[4],timex[5])<br>    cam.saveSnapshot('%s.jpg'%cur_time)  <br>    #remote.dir()<br>    file = open('%s.jpg'%cur_time,'rb')<br>    remote.storbinary('STOR %s.jpg'%cur_time,file)<br>    file.close()<br>    os.system("del %s.jpg"%cur_time)<br>    #print "upload ok!"<br>    time.sleep(1)<br>remote.quit()
로그인 후 복사


로그인 후 복사
로그인 후 복사


로그인 후 복사
로그인 후 복사


관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!