LoginSignup
19
21

More than 5 years have passed since last update.

Raspberry PiにOpenCVを導入してキャプチャするまでと、トラブルシューティング

Posted at

Raspberry piにOpenCVを導入した時のメモ...

環境

  • Raspberry Pi B
  • Rasbian
  • Logicoolのwebカメラ

準備

※ある程度の環境構築は終わっているものとする...
pythonのnumpyなどの計算ライブラリを入れておく

$ sudo apt-get install python python-dev
$ sudo apt-get install python-numpy python-scipy python-matplotlib

OpenCVの導入

ビルドするのは面倒だし、時間がかかるのでapt-getで
この辺を参考にした
Raspberry Pi B+にOpenCV-Python環境を構築する
Install OpenCV and Python on your Raspberry Pi 2 and B+

$ sudo apt-get install libopencv-dev

Pythonのパッケージをapt-get

$ sudo apt-get install python-opencv

5分くらいで終わると思います。

キャプチャのソース

このソースで試した。

capture.py
#coding:utf-8
import cv2
color = (0, 2, 2)

def capture_camera(mirror=True, size=None):
    cap = cv2.VideoCapture(1)
    while True:
        ret, frame = cap.read()

        if mirror is True:
            frame = frame[:,::-1]

        if size is not None and len(size) == 2:
            frame = cv2.resize(frame, size)

        cv2.imshow('camera capture', frame)
        k = cv2.waitKey(1)
        if k == 27:
            break
        elif k== 'q':
            break

    cap.release()

    cv2.destroyAllWindows()

capture_camera()

さて動かそう

と思ったら

GdkGLExt-WARNING **: Window system doesn't support OpenGL.

のエラーメッセージ!
vncが原因かと思ったら違うらしい。

Fix

とりあえずこれで解決した。

sudo apt-get install libgl1-mesa-dri

そして

sudo reboot

無事動きました。
vnc上でも動作しました。

最後に

この辺を参考にしました。
RaspberryPiのカメラやOpenCVのトラブルについて
Troubleshooting

19
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
21