9
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Raspberry pi とカメラモジュールを使った画像保存(とおまけに動画)

Last updated at Posted at 2017-10-21

(作成日 2017/10/20)
いつか機械学習に使う用に、Raspberry piとカメラモジュールを使って画像撮影をできるようにしたので、メモ保存用に。

#画像保存

camera.py
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (1024,768)
    camera.start_preview()
    time.sleep(5)
    camera.capture('picture.jpg')

MEMO --------------------------------------------------
1.解像度について
camera.resolution = (x,y)の値を変えても解像度が変更できそうだが、Picamera公式のPageよりcamera.capture('picture.jpg',resize=(300,300))も使用可能

2.OpenCVとの連携について
OpenCVを使用する場合は、どうやらOpenCV objectで保存してくれるようにできるらしいのでこれもPicameraを参考にする。

3.設定できる値について
ラズパイHPによると他にも以下の設定ができるらしい(ちなみに、以下の値がDefault Value)

camera.sharpness = 0
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.ISO = 0
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'none'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)

ラズパイHPより引用

#動画保存(ついでに)

camera.py
import time
import picamera

camera = picamera.PiCamera()
camera.resolution = (640,480)

camera.start_preview()
time.sleep(2)

camera.start_recording('video.h264')
camera.wait_recording(5)

camera.stop_recording()
camera.stop_preview()

MEMO --------------------------------------------------
動画はコードのみ。一応これで記録できそう。

9
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?