17
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker上でWebカメラ(UVC)を使う方法

Posted at

Docker上でWebカメラを使って開発したいなーを実現します。
メモ程度です。

Docker上でGUIを起動する方法についてはこちらの記事を参照してください。
DockerでポータブルなLinux開発環境(GUI付き)を構築する

Dockerfile
# 前略
# webcam 確認用 GUI必要です。
RUN apt-get update && apt-get install -y \
  uvccapture \
  guvcview \
  cheese
launch.sh
function launch_docker() {
  local image_tag=$1
  # GUI不要の場合、--deviceのみでOK
  # GUI用にすべてのX接続を受け入れる
  xhost +
  docker run --privileged -it \
  -e DISPLAY=$DISPLAY \ # Xの宛先をホストと同一に
  -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ # Xソケットを共有
  --device /dev/video0:/dev/video0:mwr \ # カメラデバイスを共有
  --device /dev/video1:/dev/video1:mwr \ # 複数指定も可能
  ${image_tag} /bin/bash
  }
launch_docker image_tag

後はdocker内で cheese などを実行するとホストと同じようにカメラ映像を確認できます。

17
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
17
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?