Last active
August 6, 2019 09:49
-
-
Save YuzuRyo61/2197edf86f597fb428d42121cec3c623 to your computer and use it in GitHub Desktop.
ウェブカメラの画像をキャプチャする簡易ウェブサーバー(Bottle.py、OpenCV使用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import cv2 | |
import os | |
from bottle import route, run, static_file, abort | |
@route('/') | |
def capture(): | |
cap = cv2.VideoCapture(0) | |
# 解像度は適宜変更してください | |
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1600) | |
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1200) | |
if cap.isOpened() is False: | |
abort(500, 'Camera cannot enabled.') | |
return | |
ret, frame = cap.read() | |
if ret == False: | |
abort(500, 'Camera could not capture an image.') | |
return | |
cv2.imwrite(os.path.join(os.getcwd(), '.captured.jpg'), frame) | |
cap.release() | |
return static_file('.captured.jpg', root=os.getcwd()) | |
if __name__ == "__main__": | |
run(host="0.0.0.0", port=4678) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment