Skip to content

Instantly share code, notes, and snippets.

@astrophysik928
Last active October 23, 2018 06:37
Show Gist options
  • Save astrophysik928/3fde418b2bd30a451703377cb4f49299 to your computer and use it in GitHub Desktop.
Save astrophysik928/3fde418b2bd30a451703377cb4f49299 to your computer and use it in GitHub Desktop.
ノートPC内蔵カメラで写真撮影(python)
import cv2
import datetime
fileName = "photo_" + datetime.datetime.today().strftime('%Y%m%d_%H%M%S') + ".png"
# 内蔵カメラのデバイスIDは0、USBで接続したカメラは1以降。
capture = cv2.VideoCapture(0)
# 取得した画像データは変数imageに格納。retは取得成功変数。
ret, image = capture.read()
if ret == True:
# 取得した画像を出力。fileNameは出力する画像名。
cv2.imwrite(fileName, image)
print("taking picture is completed!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment