PythonでWebカメラで撮った画像を保存
これを使うと、製品出荷時のエビデンスとして画像記録を保存する場合などに使えそう。
以下でタイムスタンプ付きで画像を保存する。
以下でタイムスタンプ付きで画像を保存する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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() |
コメント
コメントを投稿