## 說明
借助python可以實現使用命令行完成調用電腦的攝像頭進行拍照,并將照片保存到制定文件夾,可以實現監控的目的!這部分的簡單demo如下所示: <br/>
```python
#!/usr/bin/env python3
import time
import datetime
import pygame
import pygame.camera
from pygame.locals import *
#初始化攝像頭
pygame.init()
pygame.camera.init()
camera = pygame.camera.Camera("/dev/video0",(640,480))
camera.start()
def mkdir(path):
# 引入模塊
import os
# 去除首位空格
path=path.strip()
# 去除尾部 / 符號
path=path.rstrip("/")
# 判斷路徑是否存在
# 存在 True
# 不存在 False
isExists=os.path.exists(path)
# 判斷結果
if not isExists:
# 如果不存在則創建目錄
# 創建目錄操作函數
os.makedirs(path)
print( path +' 創建成功')
return True
else:
# 如果目錄存在則不創建,并提示目錄已存在
print (path+' 目錄已存在')
return False
# 定義要創建的目錄
now_time=datetime.datetime.now().strftime('%Y%m%d%H%M%S')
mkpath="vpath-"+now_time
# 調用函數
mkdir(mkpath)
#獲取當前時間病格式化
frame=1
while frame < 10 :
now_time=datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
image = camera.get_image()
pygame.image.save(image,mkpath+"/videos-"+now_time+".png")
print(frame)
frame = frame + 1
time.sleep(30) #30分鐘拍攝一張
camera.stop()
```