此方案為朋友LSJ提出並實現的,轉過來供學慣用,由於在測試時沒有架設WEB伺服器,也沒有做手機上的測試,僅通過PC測試了下,最完整解決方案請參考原出處《DIY手機監控系統》。
方法:
1 下載並安裝VideoCapture、PIL。
2.編碼,3s抓一個圖片並儲存
from VideoCapture import Deviceimport time, stringinterval = 2cam = Device(devnum=0, showVideoWindow=0)#cam.setResolution(648, 480)cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1, quality=75)i = 0quant = interval * .1starttime = time.time()while 1: lasttime = now = int((time.time() - starttime) / interval) print i cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1) i += 1 while now == lasttime: now = int((time.time() - starttime) / interval) time.sleep(quant)
3.寫個網頁,3s重新整理一次,如下:
<HTML><HEAD> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Web監視</title> <META http-equiv="refresh" content="3"> <META http-equiv="Expires" content="0"> <META http-equiv="Pragma" content="no-cache"> </HEAD> <body > <img src='image.jpg?mail=dyx1024@gmail.com' width="47%" height="381"/> </body></HTML>
4. 測試: