PythonでWebカメラで撮った画像を保存

これを使うと、製品出荷時のエビデンスとして画像記録を保存する場合などに使えそう。
以下でタイムスタンプ付きで画像を保存する。
import numpy as np
import cv2
import datetime

cap = cv2.VideoCapture(0)
print("width:" + str(cap.get(3)) + " height:" + str(cap.get(4)) )

# Capture frame-by-frame
ret, frame = cap.read()

## Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame',gray)
cv2.imwrite("img" + datetime.datetime.now().strftime('%Y%m%d%H%M%S')+'.png',frame)    #画像を保存

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

コメント

このブログの人気の投稿

VB.net Dictionaryクラスの初期化

VB.NET 実行中のクラス名とメソッド名を取得

フルパスファイル名と日付をサブディレクトリ込みで取得する方法