0
0

CV2を使って写真画像にタイムスタンプを入れてみる

Posted at

はじめに

RaspberryPiカメラを使用して、定期的に写真を撮影しています。その写真にタイムスタンプを入れたいと思った。

環境

ハードウェア : RaspberryPi ZERO 2
OS : Raspbian OS (Debian GNU/Linux 12 (bookworm))
Python : Python 3.11.2
CV2 : opencv-python==4.9.0.80

コード

import cv2
import datetime

img = cv2.imread('タイムスタンプを入れたい画像ファイルのパス')

now = datetime.datetime.now()
timestamp = now.strftime('%Y/%m/%d %H:%M:%S')

# タイムスタンプの位置は第3引数で調整(30, 30)は画像の左上に表示されます
# タイムスタンプの色は第6引数で調整(0, 128, 255)はオレンジ色です。RGB形式ではなくBGR形式である点に注意
cv2.putText(img, timestamp, (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 128, 255), 2)

# imgと同じファイルパスとした場合上書きとなります
cv2.imwrite('出力先ファイルパス', img)
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