0
0

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

RaspberryPiのカメラでリアルタイムでゴニョゴニョするためのコード

Last updated at Posted at 2020-07-27

使いたいライブラリに合わせて適宜利用すればOK。
物体検知とかにどうぞ。

PILバージョン

PILバージョン
import os
from datetime import datetime
from PIL import Image
from picamera import PiCamera

camera = PiCamera()

while True:
    nowtime = datetime.now()
    filename = nowtime.strftime('%H%M%S') + '.png'
    camera.capture(filename)
    with Image.open(filename) as frame:
        pass # ここでゴニョゴニョする
    os.remove(filename)

cv2バージョン

cv2バージョン
import os
from datetime import datetime
import cv2

cam = cv2.VideoCapture(0)

while True:
    nowtime = datetime.now()
    filename = nowtime.strftime('%H%M%S') + '.png'

    is_success, frame = cap.read()
    pass # ここでゴニョゴニョする。is_successは上手く撮れているかどうかのフラグなので利用しなくてOK
    os.remove(filename)

cam.release()
cv2.destroyAllWindows()

カメラも付くケース

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?