Help us understand the problem. What is going on with this article?

Insta360 airとRaspberry Pi 3B+で全天球監視カメラを作る

概要

Insta360 airRaspberry Pi 3B+で全天球の監視カメラを作ります.
全天球といいつつも,魚眼が左右2つ出ていて全天球にするための処理はしてません.

RICHOのTHETAなどほかの全天球カメラでもできますが,比較的安価であること,USBツールニードルが付属していること,筐体がコンパクトでスマートに見えることからInsta360 airを選びました.(実際はMicroUSBのスマホからTypeCのスマホに機種変更したためスマホで気軽に使えなくなったから)

スペック

まずはラズパイのスペック

pi@rpi3bp:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

insta360 airの情報

$ v4l2-ctl -d /dev/video1 --info
Driver Info:
        Driver name      : uvcvideo
        Card type        : Insta360 Air: Video Control
        Bus info         : usb-3f980000.usb-1.1.3
        Driver version   : 4.19.66
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : uvcvideo
        Model            : Insta360 Air: Video Control
        Serial           :
        Bus info         : 1.1.3
        Media version    : 4.19.66
        Hardware revision: 0x00000100 (256)
        Driver version   : 4.19.66
Interface Info:
        ID               : 0x03000002
        Type             : V4L Video
Entity Info:
        ID               : 0x00000001 (1)
        Name             : Insta360 Air: Video Control
        Function         : V4L2 I/O
        Flags         : default
        Pad 0x01000007   : 0: Sink
          Link 0x02000016: from remote pad 0x100000a of entity 'Extension 2': Data, Enabled, Immutable
$ v4l2-ctl -d /dev/video1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [0]: 'MJPG' (Motion-JPEG, compressed)
                Size: Discrete 1472x736
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 2176x1088
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 3008x1504
                        Interval: Discrete 0.033s (30.000 fps)
        [1]: 'H264' (H.264, compressed)
                Size: Discrete 1920x960
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.042s (24.000 fps)
                        Interval: Discrete 0.050s (20.000 fps)
                Size: Discrete 2560x1280
                        Interval: Discrete 0.033s (30.000 fps)
                        Interval: Discrete 0.042s (24.000 fps)
                        Interval: Discrete 0.050s (20.000 fps)

MJPG-streamerの導入

MJPG-streamer(https://github.com/jacksonliam/mjpg-streamer )を入れる.
(motionでも試みたが撮影のフォーマット上,うまくいかなかった.)
GitHubのREADMEを読んでそのままコマンドを打っていく.

$ sudo apt install cmake libjpeg8-dev
$ sudo apt install gcc g++
$ sudo apt install git
$ git clone https://github.com/jacksonliam/mjpg-streamer.git
$ cd mjpg-streamer/mjpg-streamer-experimental
$ make
$ sudo make install
$ sudo cp -r www /var/www

起動スクリプトの作成

起動スクリプトを書く.

~/mjpg-streamer/mjpg-streamer-experimental/run-8081.sh
#!/bin/sh
mjpg_streamer -i "/home/pi/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so -f 5 -r 3008x1504 -d /dev/video0 -y -n" -o "/home/pi/mjpg-streamer/mjpg-streamer-experimental/output_http.so -w /home/pi/mjpg-streamer/mjpg-streamer-experimental/www -p 8081"

デバイス名(/dev/video0)と画像サイズ(3008x1504),ポート番号(8081)は,環境やどうしたいかに依るので要確認.
絶対パスで書いているけど,相対でもいいかもしれない.

デーモン化

ラズパイといえば電源をUSBからぶち抜く運用がほとんどなので,デーモン化しておいて電源投入で自動的に立ち上がるようにする.

$ sudo nano /etc/systemd/system/mjpg-streamer.service
/etc/systemd/system/mjpg-streamer.service
[Unit]
Description = mjpg-streamer

[Service]
ExecStart = /home/pi/workspace-git/mjpg-streamer/mjpg-streamer-experimental/run-8081.sh
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target
$ sudo systemctl enable mjpg-streamer.service
$ sudo systemctl start mjpg-streamer.service
$ sudo systemctl status mjpg-streamer.service

確認

http://(ラズパイのアドレス)/8081を参照すると動作していることがわかる.

おまけ

通常のカメラも同様にスクリプトとデーモンを作り動かしている.
nginxで両方を同時に見れるようにしている.

/var/www/html/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>監視カメラ画像</title>
</head>

<body>
        <p>image</p>
        <img src="http://192.168.1.1:8081/?action=stream" width="100%" style="transform: scale(-1, -1);">
        <img src="http://192.168.1.1:8082/?action=stream" width="100%">
</body>
</html>

完成図
IMG_20190923_230454.jpg

ダウンロード.jpg
モザイク入れるのがめんどくさかったので,布で覆ってますが,魚眼が2つ見えているものが出ます.

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away