树莓派之picamera开发2 -- picamera摄像头开启录像截图

上一篇 / 下一篇  2017-09-23 11:19:42 / 个人分类:树莓派

2、picamera库使用,开启,录像,截图,RGB格式转换
1)开启摄像头
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (320, 240)
    camera.start_preview()

    time.sleep(10)

    camera.stop_preview()
运行此程序就可以启动树莓派摄像头10s,支持单纯的启动摄像头
设置了摄像头的分辨率是320*240

(2)开启摄像头并且进行录像将其保存到名为“file.h264”的文件中
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (320, 240)
    camera.start_preview()
    camera.start_recording("file.h264")
    camera.wait_recording(10)
    camera.stop_recording()
    camera.stop_preview()

(3)开启摄像头,采集一张照片

#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (320, 240)
    camera.start_preview()
    time.sleep(2)
    camera.capture("face.jpg")#截图
    camera.stop_preview()
(4)开启摄像头,采集照片并在其上打印Exif标记
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (320, 240)
    camera.start_preview()
    time.sleep(2)
    camera.exif_tags['IFD0.Artist'] = 'Me!'
    camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2013 Me!'
    camera.capture("face.jpg")
    camera.stop_preview()
(5)开启摄像头,采集一张图像,并通过RGE格式进行解码,生成一个numpy的图像阵列

#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import picamera
import picamera.array

with picamera.PiCamera() as camera:
    with picamera.array.PiRGBArray(camera) as stream:
        camera.resolution = (320, 240)
        camera.start_preview()
        time.sleep(2)
        camera.capture(stream, 'rgb')
        print stream.array.shape
        camera.stop_preview()









TAG: picamera pip raspberry

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

我的栏目

日历

« 2017-10-21  
1234567
891011121314
15161718192021
22232425262728
293031    

数据统计

  • 访问量: 420
  • 日志数: 5
  • 建立时间: 2016-03-23
  • 更新时间: 2017-10-12

RSS订阅

Open Toolbar