Brigadoon - An Occasional Corner on the Internet
Sky Camera Image Capture Software
Designed by Mark Little
With the Raspberry Pi camera installed and enabled, it is time to take a still image. This can be easily done by enter the following command on the command line:
sudo raspistill -o skyimage.jpg
This command will take a picture from the camera and save it into an image called "skyimage.jpg" in the directory in which the program was run. Once you have run this program, look at the image to see whether it is the right way up. If it is upside down due to the orientation of the camera, alter the command to:
sudo raspistill -vf -hf -o skyimage.jpg
The "-vf" option will flip the image vertically and the "-hf" option will flip the image horizontally. The next effect of these to flips is the rotate the image by 180°.
Now that we have the camera capturing images, it is time to combine the timing set up using "cron" with the image capture provided by "raspistill".
To do this,we need to create a script file "/sbin/skycamera.sh" so that out crontab entry will cause the image to be captured every five (5) minutes.
Using your favourite text editor create the file "/sbin/skycamera.sh" with a command like below (assuming that "nano" is your favourite text editor:
sudo nano /usr/local/sbin/skycamera.sh
The "sudo" command means that editor should be run with same privileges as root. If this does not work, you can "su root" and then just use "nano /usr/local/sbin/skycamera.sh". When you are in the editor, enter the following text as shown (add "-vf -hf" to "raspistill" if required):
# Script to capture images from a Raspiberry Pi Camera,
# scale and upload to a web server.
# Capture the Image from the Camera
raspistill -o /tmp/skyimage.jpg
# End of Script
Once you have saved this script, the script needs to be set to allow it to execute. This can be done by entering the following command:
sudo chmod 755 /usr/local/sbin/skycamera.sh
Now, it should simply be a matter of waiting at least five (5) minutes and then looking into the "/tmp" directory. In there, there should be a file called "skyimage.jpg". View the image to confirm that it is a picture from your camera. Wait another five (5) minutes and you should see that the image has updated. You have now completed the second requirement of capturing an image from the camera.
The size of the image will be about 2500 x 1950 pixels and 2.5 Mbytes. The next requirement is to reduce the size of the image to be compatible with the requirements of the web server to which the image will be uploaded.