歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Python:通過攝像頭實現的監控功能

Python:通過攝像頭實現的監控功能

日期:2017/3/1 10:32:31   编辑:Linux編程
此方案為朋友LSJ提出並實現的,轉過來供學習用,由於在測試時沒有架設WEB服務器,也沒有做手機上的測試,僅通過PC測試了下,最完整解決方案請參考原出處《DIY手機監控系統》見 http://www.linuxidc.com/Linux/2012-02/54205.htm。

方法:

1 下載並安裝VideoCapture、PIL。

2.編碼,3s抓一個圖片並保存

[python]
  1. from VideoCapture import Device
  2. import time, string
  3. interval = 2
  4. cam = Device(devnum=0, showVideoWindow=0)
  5. #cam.setResolution(648, 480)
  6. cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1, quality=75)
  7. i = 0
  8. quant = interval * .1
  9. starttime = time.time()
  10. while 1:
  11. lasttime = now = int((time.time() - starttime) / interval)
  12. print i
  13. cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1)
  14. i += 1
  15. while now == lasttime:
  16. now = int((time.time() - starttime) / interval)
  17. time.sleep(quant)

3.寫個網頁,3s刷新一次,如下:

[html]
  1. <HTML>
  2. <HEAD>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. <title>Web監視</title>
  5. <META http-equiv="refresh" content="3">
  6. <META http-equiv="Expires" content="0">
  7. <META http-equiv="Pragma" content="no-cache">
  8. </HEAD>
  9. <body >
  10. <img src='[email protected]' width="47%" height="381"/>
  11. </body>
  12. </HTML>
4. 測試:

Copyright © Linux教程網 All Rights Reserved