Thursday, May 25, 2017

Camera Module Raspberry PI

One of the top uses of Rapi is to use it as a motion detector device by using camera module. It is not that complicated, it is really easy though.

I simplify the process into steps to make it easier to understand.

1) Update and upgrade package management system.

sudo apt-get update
sudo apt-get upgrade

2) Activate and enable camera module
 sudo raspi-config

It shows selection window, and we select Interfaces and then camera. After confirmation, it installs camera module. Now, we can capture still image or video if camera is properly installed.

3) Installation of camera

The camera is connected as shown above. The camera interface is located beside the network port. Note that the shiny part of the ribbon should always point outward from the network port. (See the pic above).

raspistill -o image.jpg
raspivid -o video.h264 -t 10000 

The time is in milliseconds. First command capture an image while second captures a 10 seconds video. 

4) Streaming and Motion Detection

Now, we go further and implement our Raspberry Pi device as a motion detector device. A very nice package is there called motion  which is highly recommended.

sudo apt-get install motion
sudo systemctl status motion.service
sudo systemctl start motion.service 

After completion, we have to modify some settings according to our requirements. We also need to enable video module for video device to work.

sudo modprobe bcm2835-v4l2

Everytime, to automaticlly enable video module, we put this command in /etc/rc.local(sudo is not needed there)

Again we need to enable motion daemon in
/etc/default/motion file.


Now, we carry out settings in /etc/motion/motion.conf. The file is really big, but we have to focus on a few things:

width 1200
height 800
framerate 20
target_dir /var/lib/motion
picture_filename %Y_%m_%d/%v-%Y%m%d%H%M%S-%q
movie_filename %Y_%m_%d/%v-%Y%m%d%H%M%S
stream_port 8081
stream_localhost off # stream connections to other systems
webcontrol_localhost off

The above mentioned parameters quite easy to understand. After change, we need to restart motion.

Now, we see the motion detected pictures stored in the directory /var/lib/motion and the define directory and file structure. And also we can access the live stream from the link:

Thats it!

It is interesting, is not it?

No comments:

Post a Comment