みつきんのメモ

組み込みエンジニアです。Interface誌で「Yocto Projectではじめる 組み込みLinux開発入門」連載中

raspberrypi2 RaspiCamでhighgui

前回Qt5+EGLFS環境で動作するOpenCVのHighGuiが動くようになった。 opencv-sampleに収録されているデモアプリケーションの中には 以下のようにカメラを要求するものがある。

This program demonstrated the use of motion templates -- basically using the gradients
of thresholded layers of decaying frame differencing. New movements are stamped on top with floating system
time code and motions too old are thresholded away. This is the 'motion history file'. The program reads from the camera of your choice or from
a file. Gradients of motion history are used to detect direction of motoin etc
Usage :
./motempl [camera number 0-n or file name, default is camera 0]

RPi2でもRaspiCamが接続できるとのことなので試して見た。

rootfsイメージ

SDカードに書き込むイメージは前回作成したものから変更するところはない。

local.confに以下の内容が書き込まれていれば、 RaspiCamの有効化に必要な設定はなされている。

VIDEO_CAMERA = "1"

RaspiCamの使用準備

SDのrootfsに必要なファイルは組み込まれているためドライバの確認および組み込みを行う。

カメラドライバの確認

bcm2835-v4l2.ko というファイルがあれば、RaspiCamを利用することができる。 確認は以下のコマンドでできる。

$ find /lib/modules -name 'bcm2835-v4l2.ko'
/lib/modules/3.18.5/kernel/drivers/media/platform/bcm2835/bcm2835-v4l2.ko

カメラドライバの組み込み

$ modprobe bcm2835-v4l2
$ lsmod | grep v4l

lsmodの結果が以下のようになっていればカメラの準備は整っている。

bcm2835_v4l2           36786  0
videobuf2_vmalloc       2859  1 bcm2835_v4l2
videobuf2_core         34031  1 bcm2835_v4l2
v4l2_common             5210  2 bcm2835_v4l2,videobuf2_core
videodev              120512  3 bcm2835_v4l2,v4l2_common,videobuf2_core

これで必要な準備はできた。

RasbiCamの使用

opencv-sampleにある以下のアプリケーションで動作を試す。

$ adaptiveskindetector

実行中のRPi2

実行中のRPi2はこのようになっている。 カメラのLEDが点灯し、動作していることが確認できる。 f:id:mickey_happygolucky:20150221001436j:plain

実行画面

カメラでキャプチャされている様子がわかる。 f:id:mickey_happygolucky:20150221001544j:plain

ちなみに顔が隠れているのはアプリの実行結果によるもので、何かしたわけではない。