13
7

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 5 years have passed since last update.

Raspberry Pi カメラ画像をS3へアッロード

Posted at

##モチベーション
AWSへ繋ぐ目的で購入したラズパイをようやくAWSに繋ぐ。
まずは単純にカメラで静止画撮影してS3にあげる

##前提環境

  • RaspberryPi3B+
  • Raspbian 9.8
  • Python 2.7.13/Python 3.5.3
  • picamera 1.13

##追加環境

  • boto3

##事前準備
「クラウドへの複数ファイル一括アップロード」にて以下の準備を済ませています。

  • AWS IAM ユーザーの作成→AWS_Admin
  • AWS CLI インストールおよび設定(Configure)
  • S3 Bucketの作成→atsmaru-bucket

##pythonにて写真撮影+S3へのアップロード

以下のコードを実行させることで、日付+時刻.jpgの画像をpicameraから取得し、s3にuploadすることができるようになりました。

takePicToS3.py
# coding: utf-8
import picamera
import boto3
import time
from datetime import datetime

def take_pic_from_picamera(filename):
    print("take_pic_from_picamera:"+filename)
    with picamera.PiCamera() as camera:
 #    camera.resolution = (1024, 768)
     camera.resolution = (500, 500)
     camera.start_preview()
     camera.led = False
     #camera warm-up time
     time.sleep(2)
     camera.capture(filename)
     print("done")
    
def upload_to_S3(filename):
    print("upload_to_S3:"+filename)
    bucket_name = "atsmaru-bucket"
    s3 = boto3.resource('s3')
    s3.Bucket(bucket_name).upload_file('/home/pi/'+filename, filename)
    print("done")

# main
timestr = datetime.now().strftime('%Y%m%d%H%M%S')
filename=timestr+'.jpg'
take_pic_from_picamera(filename)
upload_to_S3(filename)
13
7
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
13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?