One of my initial ideas for using Raspberry Pi was to remotely view my sons activities when ever I was away from him. So as a start I checkout my old web cam (which is a Zebatronics Ecam 2009 model) it was working and finally followed the steps in the below link to setup the webcam in my raspberry pi.
https://www.raspberrypi.org/documentation/usage/webcams/
Here I will give a brief rundown of steps that I did to setup the Web Cam.
1. Check if your web cam is a USB Webcam and the make, mine was Zebatronics Ecam 2009 model
2. Connect it to the Raspberry Pi USB port and see if the lights of the Web Cam are glowing.
3. Check if the Web Cam is detected using lsusb For me it shows the below for the webcam:
pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 0c45:614a Microdia
Note: The trick to know that if webcam is connected is to lsusb before and after connecting the webcam if its detected an additional USB device will show. Additionally in /dev folder check if there any device like /dev/video0
pi@raspberrypi:~ $ ls /dev/video*/dev/video0
4. Install fswebcam and check if the webcam capture works sudo apt-get install fswebcam
pi@raspberrypi:~/webcam $ fswebcam image.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'image.jpg'.
5. Next I developed a script to capture the image and save to a folder /home/pi/webcam
Created a script webcam.sh
mkdir /home/pi/webcam
Created a script webcam.sh
#!/bin/bash DATE=$(date +"%Y-%m-%d_%H%M") fswebcam -r 1280x720 --no-banner /home/pi/webcam/$DATE.jpg
6. Then setup cron to capture images every minute:
crontab -e
Added this line in the editor:
* * * * * /home/pi/webcam.sh 2>&1
7. The output can be seen as below where the script runs every one minute:
pi@raspberrypi:~ $ ls ~/webcam
2016-08-18_1644.jpg 2016-08-18_1707.jpg 2016-08-18_1730.jpg
2016-08-18_1645.jpg 2016-08-18_1708.jpg 2016-08-18_1731.jpg
2016-08-18_1646.jpg 2016-08-18_1709.jpg 2016-08-18_1732.jpg
2016-08-18_1647.jpg 2016-08-18_1710.jpg 2016-08-18_1733.jpg
2016-08-18_1648.jpg 2016-08-18_1711.jpg 2016-08-18_1734.jpg
2016-08-18_1649.jpg 2016-08-18_1712.jpg 2016-08-18_1735.jpg
2016-08-18_1650.jpg 2016-08-18_1713.jpg 2016-08-18_1736.jpg
2016-08-18_1651.jpg 2016-08-18_1714.jpg 2016-08-18_1737.jpg
2016-08-18_1652.jpg 2016-08-18_1715.jpg 2016-08-18_1738.jpg
2016-08-18_1653.jpg 2016-08-18_1716.jpg 2016-08-18_1739.jpg
2016-08-18_1654.jpg 2016-08-18_1717.jpg 2016-08-18_1740.jpg
2016-08-18_1655.jpg 2016-08-18_1718.jpg 2016-08-18_1741.jpg
2016-08-18_1656.jpg 2016-08-18_1719.jpg 2016-08-18_1742.jpg
2016-08-18_1657.jpg 2016-08-18_1720.jpg 2016-08-18_1743.jpg
2016-08-18_1658.jpg 2016-08-18_1721.jpg 2016-08-18_1744.jpg
2016-08-18_1659.jpg 2016-08-18_1722.jpg 2016-08-18_1745.jpg
2016-08-18_1700.jpg 2016-08-18_1723.jpg 2016-08-18_1746.jpg
2016-08-18_1701.jpg 2016-08-18_1724.jpg 2016-08-18_1747.jpg
2016-08-18_1702.jpg 2016-08-18_1725.jpg 2016-08-18_1748.jpg
2016-08-18_1703.jpg 2016-08-18_1726.jpg 2016-08-18_1749.jpg
8. Finally I created a script to generate a time lapse video of these images, for this first we need to install avconv which is a fork of ffmpeg.
Then created a script conv2vid.sh to generate the time lapse video from the images and flush the images once the video is created:
pi@raspberrypi:~ $ sudo apt-get install avconv
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package avconv
#!/bin/bashPlease find the below video for the Time lapse video
DATE=$(date +"%Y-%m-%d_%H%M")
mv /home/pi/webcam/*.jpg /home/pi/webcam/video
cat /home/pi/webcam/video/*.jpg | avconv -r 10 -f image2pipe -codec:v mjpeg -i --pix_fmt yuvj420p -r 30 -c:v libx264 -vf scale=480:300 -y /home/pi/webcam/video/$DATE.mp4
rm /home/pi/webcam/video/*.jpg
No comments:
Post a Comment