LoginSignup
11
15

More than 5 years have passed since last update.

Webカメラ使ってreal timeにdetectionしてみる

Last updated at Posted at 2017-01-18

はじめに

最近、故あってdetectionしてるが、ついでにwebカメラ使ってリアルタイムに物体検出すると面白いだろうと思った。そこで簡易なシステムを組み立ててみる。

パソコン環境

OS:Ubuntu14.04
GPU:GTX1070
CUDA:8.0 RC
cuDNN:5.1
python2.7.6
など

使用するwebカメラ

Logicool HD c270
https://www.amazon.co.jp/LOGICOOL-%E3%82%A6%E3%82%A7%E3%83%96%E3%82%AB%E3%83%A0-HD%E7%94%BB%E8%B3%AA-120%E4%B8%87%E7%94%BB%E7%B4%A0-C270/dp/B003YUB660/ref=sr_1_1?s=books&ie=UTF8&qid=1484720653&sr=8-1&keywords=logicool+c270
41RhjwRYBAL.jpg
amazonだと1,000円くらいで売っている。しかし評価が高い。Ubuntuでも使えるみたい。

利用するdetectionモデル

YOLO v2
http://pjreddie.com/darknet/yolo/
論文はこちら
https://arxiv.org/pdf/1612.08242v1.pdf
v1のロジックに関しては私がこちらにまとめてます。
http://www.slideshare.net/ssuser07aa33/introduction-to-yolo-detection-model

webカメラのインストール

こちらのサイト
http://nort-wmli.blogspot.jp/2013/11/logicool-hd-webcam-c270.html
を参考にして進める。

まず買ってきたカメラをUbuntuパソコンに繋いでみる。当然反応なし。そこでmotionとやらをインストールする。

sudo apt-get install motion

うまくいったみたい。次に起動する。

sudo motion
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
......
......
......
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[1] Started stream webcam server in port 8081
[1] File of type 8 saved to: /tmp/motion/01-20170118154150.swf
[1] File of type 1 saved to: /tmp/motion/01-20170118154150-01.jpg
[1] File of type 1 saved to: /tmp/motion/01-20170118154151-00.jpg
[1] File of type 1 saved to: /tmp/motion/01-20170118154157-01.jpg

などと、/tmp/motion/下にめっちゃ写真が保存され始めた。動画もそのディレクトリにあるが、swfという変な形式なので確認できない。そこで以下のようにetc/motion/motion.confを変更する。

motion.conf
snapshot_interval 3000

yoloモデルでreal timeにdetectionする

webカメラをUSBにさした状態でyoloのディレクトリに行く。次に以下のコマンドでreal timeなdetectionを開始する。

cd <path to yolo_darknet directory>
./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights

cfgやweightsをいろいろ変えて試してみると面白い。

出力結果の例は以下。
https://youtu.be/aAP8osZB0Fs

11
15
2

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
11
15