Skip to content

OpenCV+Python環境構築とUSBカメラ動作サンプルプログラム

PythonでOpenCV環境を構築するのは非常に簡単にできます。

USBカメラの映像を表示するプログラムもシンプルでした。

PythonでのOpenCV環境構築

pip install opencv-python
pip install opencv-contrib-python

もしくは

sudo apt-get install python-opencv

USBカメラの映像を表示するサンプルプログラム

import cv2

capture = cv2.VideoCapture(0)

while(True):
    ret, img = capture.read()
    cv2.imshow('img',img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

capture.release()
cv2.destroyAllWindows()

以上です。