How to setup remote camera system with Raspberry Pi and USB camera?


Reading Time: 2 minutes

This article shows

I have setup remote camera system with Raspberry Pi and USB camera

In this article I use Docker container to clean up after trial.

This is sample of image which you can see by this system.

You can see camera captured image by browser,

http://<IP address of Raspberry Pi>:50081

I use this camera which is not used now and put in closet in my home.
– Microsoft Lifecam Studio

Let’s see my Dockerfile.

FROM		debian:latest

RUN		\
		# Update to latest
		apt -y update && \
		apt -y upgrade && \
		# Install general packages
		apt -y install motion && \
		sed -i -E 's/^stream_port(.*)/stream_port 50081/' /etc/motion/motion.conf && \
		sed -i -E 's/^width(.*)/width 640/' /etc/motion/motion.conf && \
		sed -i -E 's/^height(.*)/height 480/' /etc/motion/motion.conf && \
		sed -i -E 's/^output_pictures(.*)/output_pictures on/' /etc/motion/motion.conf && \
		sed -i -E 's/^locate_motion_mode(.*)/locate_motion_mode on/' /etc/motion/motion.conf && \
		sed -i -E 's/^locate_motion_style(.*)/locate_motion_style redbox/' /etc/motion/motion.conf && \
		sed -i -E 's/^stream_localhost(.*)/stream_localhost off/' /etc/motion/motion.conf && \
		echo "Build complete." 


Parameter tuning is baseon on this article.
Japanese IT news site.

小さなマイクロコンピュータ「Raspberry Pi」(通称ラズパイ)で作る、自分だけのガジェット。ラズパイに接続したカメラで動体検知したときに、撮影した画像をLINEに送る方法を紹介します。

Briefly I explain each parameter.
motion has lots of parameters other than them, but I think they are enough to use normally.

  Port number to be accessed from outside.
  Image size.
  Select on/off whether you want to save picture files.
  Select on/off whether you want to see the point which moving object is detected.
  Select look/feel of marking when moving object is detected.
  Select on/off whether you want to limit access from localhost only.

Here you can download my Dockerfile.

GitHub - kurofuku/motion-container
Contribute to kurofuku/motion-container development by creating an account on GitHub.

To create image you can do it with Dockerfile the same directory.

sudo docker build -t motion-image .

Below is example of running container with camera device whose device file is /dev/video0.
–restart=always enables to restart automatically when container dies or system boot.
–device maps device file to container so that container inside you can use this device.
-p specified which port to be open.

sudo docker run -dit --restart=always --device=/dev/video0:/dev/video0 -p 50081:50081 motion-image


How was it?

This sample is very simple, so another function should be introduced!
– Post image to LINE chat.
– Upload cloud storage service.
– Etc.


Copied title and URL