此方案為朋友LSJ提出並實現的,轉過來供學習用,由於在測試時沒有架設WEB服務器,也沒有做手機上的測試,僅通過PC測試了下,最完整解決方案請參考原出處《DIY手機監控系統》見 http://www.linuxidc.com/Linux/2012-02/54205.htm。
方法:
1 下載並安裝VideoCapture、PIL。
2.編碼,3s抓一個圖片並保存
[python]
- from VideoCapture import Device
- import time, string
- interval = 2
-
- cam = Device(devnum=0, showVideoWindow=0)
-
- #cam.setResolution(648, 480)
- cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1, quality=75)
-
- i = 0
- quant = interval * .1
- starttime = 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]
- <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='[email protected]' width="47%" height="381"/>
- </body>
- </HTML>
4. 測試: