歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Nginx+Python 下DIY手機監控系統

Nginx+Python 下DIY手機監控系統

日期:2017/3/1 10:32:32   编辑:Linux編程
寶寶長大了,喜歡動來動去,為了更好的看護寶寶,想用PC攝像頭弄一個Web監控,手機上也能顯示,這樣在廚房做飯帶著手機也能看著她。 為了解決這個需求,先上網google了半天,沒找到免費又穩定的軟件。想想自已寫一個算了,遂上sourceforge、codeproject、google'code 狂搜一通源代碼,找到幾個試了,各有利弊。經過幾個晚上的研究,目前發現的最好的解決方案是這樣的:

網絡:wifi Web服務器: nginx 1.0.11 攝像頭抓圖: python2.7 + PIL 1.1.7 + VideoCapture 0.9-4
經測試,本方案在S60手機浏覽器、Android手機浏覽器、PC上的 Chrome\IE 均可正常監視。把路由器nat 機器的80端口到互聯網,也能正常訪問。
監控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="100%"/> </body> </HTML>
截圖python代碼: from VideoCapture import Device import time, string interval = 2
cam = Device(devnum=0, showVideoWindow=0)

cam.setResolution(320, 240)
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)

show一下運行截圖:

Copyright © Linux教程網 All Rights Reserved