-
-
Save watanabe-tsubasa/a71ff90b39eac912945120f2d43b1da5 to your computer and use it in GitHub Desktop.
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
import cv2 | |
# numpyは画像データの格納に必要です。 | |
import numpy as np | |
def camera(): | |
cap = cv2.VideoCapture(0) | |
isOpened = cap.isOpened() | |
if not isOpened: | |
return | |
while True: | |
result, frame = cap.read() | |
if not result: | |
return | |
# 画像表示 | |
cv2.imshow('camera', frame) | |
# キー入力受付 | |
key = cv2.waitKey(1) | |
# 終了キー(EnterかEscで終了) | |
if (key == 13) or (key == 27): | |
break | |
# カメラ終了 | |
cap.release() | |
cv2.destroyAllWindows() | |
camera() |
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
import cv2 | |
# VideoCapture オブジェクトを取得します | |
capture0 = cv2.VideoCapture(0) | |
capture1 = cv2.VideoCapture(1) | |
while(True): | |
ret1, frame0 = capture0.read() | |
ret2, frame1 = capture1.read() | |
cv2.imshow('frame0',frame0) | |
cv2.imshow('frame1',frame1) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
capture0.release() | |
capture1.release() | |
cv2.destroyAllWindows() |
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
import cv2 | |
i = 0 | |
flag = True | |
captures = [] | |
# VideoCapture オブジェクトを取得します | |
while( flag ): | |
capture = cv2.VideoCapture(i) | |
ret, frame = capture.read() | |
flag = ret | |
if flag: | |
i += 1 | |
captures.append( capture ) | |
while(True): | |
for i, capture in enumerate( captures ): | |
ret, frame = capture.read() | |
cv2.imshow( f'frame{i}', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
capture.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment