首先根据我之前的博客安装好摄像头需要的库。
然后代码如下:
import os
import sys
import re
import commands
a=commands.getoutput("fswebcam --no-banner -r 640x480 image3.jpg")
print a
运行结果如下
>>> print a
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'image3.jpg'.
同时在pi目录下会多一张名为image3.jpg的照片。
在python3中将import commands删除且将
a=commands.getoutput(“fswebcam --no-banner -r 640x480 image3.jpg”)
改为a=os.system(“fswebcam --no-banner -r 640x480 image3.jpg”)即可
因为commands在python3中被废弃了。