若是一切顺利的话,就可使用命令控制摄像头了html
pi@raspberrypi:~ $ raspistill -o Desktop/image.jpg
增长参数,还能够更改图片大小python
pi@raspberrypi:~ $ raspistill -o Desktop/image-small.jpg -w 640 -h 480
输入raspistill直接回车可查询raspistill命令其余参数网络
pi@raspberrypi:~ $ raspivid -o Desktop/video.h264 -t 5000 -w 1024 -h 768
使用Python程序控制摄像头须要使用PiCamera库
打开Raspberry Pi自带的Thonny Python IDE,新建camera.py文件,文件命名不能用PiCamera.pyide
from picamera import PiCamera from time import sleep camera = PiCamera() # Rotate by 180 degrees when the camera is upside-down camera.rotation = 180 camera.start_preview(alpha=200) # Make the camera preview see-through by setting an alpha level from 0 to 255 sleep(5) camera.stop_preview()
上述代码实现打开摄像头预览5秒钟再关闭的功能。可是若是这个程序仅在Raspberry Pi接入了显示器才有效,SSH或是VNC访问是无效的。spa
from picamera import PiCamera from time import sleep camera = PiCamera() # Rotate by 180 degrees when the camera is upside-down camera.rotation = 180 camera.start_preview(alpha=200) # Make the camera preview see-through by setting an alpha level from 0 to 255 sleep(5) # Take a picture and save as /home/pi/Desktop/image.jpg' camera.capture('/home/pi/Desktop/image.jpg') # Take 5 pictures every 5 seconds and save as /home/pi/Desktop/image0.jpg' ... image4.jpg for i in range(5): sleep(5) camera.capture('/home/pi/Desktop/image%s.jpg' % i) camera.stop_preview()
在拍照前,最好让摄像头sleep至少2秒,使之可以感光
将capture()改为start_recording()和stop_recording()就可控制摄像头拍摄录像了code
from picamera import PiCamera, Color from time import sleep camera = PiCamera() camera.rotation = 180 camera.resolution = (1024, 768) camera.framerate = 15 camera.start_preview() camera.brightness = 70 camera.annotate_background = Color('blue') camera.annotate_foreground = Color('yellow') camera.annotate_text = "Hello world!" camera.annotate_text_size = 30 sleep(5) camera.capture('/home/pi/Camera/pic.jpg') camera.stop_preview() camera.start_preview() for i in range(5): camera.annotate_text = "Brightness: %s" % i camera.brightness = i*20 sleep(0.1) camera.capture('/home/pi/Camera/brightness%s.jpg' % i) camera.stop_preview() camera.start_preview() for i in range(5): camera.annotate_text = "Contrast: %s" % i camera.contrast = i*20 sleep(0.1) camera.capture('/home/pi/Camera/contrast%s.jpg' % i) camera.stop_preview()
$ sudo apt-get install vlc #Raspberry Pi系统自带了 $ #-o - 输出到stdout,-t 0不暂停当即获取流, 640x360,25帧/s,-rot 180画面旋转180度(用了支架摄像头画面倒过来了) $ sudo raspivid -o - -rot 180 -t 0 -w 480 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264
在与Raspberry Pi在同一局域网内的其余设备上,用vlc打开网络串流 http://Raspberry Pi的ip:8090
就播放看到摄像头的画面了,可是vlc的实施监控存在5s左右的延时,体验并非很好。htm