Raspberry PI Cameras Set-Ups

Posts: 5
Joined: Thu Apr 16, 2020 1:19 pm

Raspberry PI Cameras Set-Ups

Post »

Hi,

What software configs do folks use to set up cameras on a Pi?

I found Motion a little unreliable, and now tend to use ImageMagick and shell script.

Jon.

Posts: 51
Joined: Tue Aug 14, 2018 1:54 pm

Re: Raspberry PI Cameras Set-Ups

Post »

Hey Jon! Great question. I typically just use the official Raspberry Pi camera and enable it under Raspberry Pi Config > Interfaces on Raspbian, then use the command line to control it. But I'm pretty partial to CLI.

Which camera and Raspberry Pi OS are you using, and what are you using your Pi cam for?

Posts: 35
Joined: Wed Oct 18, 2017 10:21 am

Re: Raspberry PI Cameras Set-Ups

Post »

I've been using ImageMagick and shell scripts to render time-lapses of my 3D prints, however, when I upgraded the camera I had to render them on my laptop as the Pi 3 B+ couldn't handle the huge files!

Posts: 11
Joined: Thu Apr 11, 2019 7:43 am

Re: Raspberry PI Cameras Set-Ups

Post »

If you're using a camera and Raspberry Pi for 3D printing, many budget webcams work really well with OcroPrint like the Microsoft LifeCam HD-3000, or the Logitech C920.

Posts: 5
Joined: Thu Apr 16, 2020 1:19 pm

Re: Raspberry PI Cameras Set-Ups

Post »

moe-long wrote:
Thu Apr 16, 2020 1:43 pm
Hey Jon! Great question. I typically just use the official Raspberry Pi camera and enable it under Raspberry Pi Config > Interfaces on Raspbian, then use the command line to control it. But I'm pretty partial to CLI.

Which camera and Raspberry Pi OS are you using, and what are you using your Pi cam for?
Hey Moe, I did some digging and found this article informative on compression with ImageMagick (link).

I put it in a shell script which then measured how long it took to run, allowing me to take a photo every 30 seconds. The script took about 26 seconds to run (take photo, compress, watermark, and sleep (30 minus run-time)).

The PI is powered off, but if you want a copy of the script let me know.

(it is a PI zero, and should be the latest Raspbian)

Jon.

Posts: 5
Joined: Thu Apr 16, 2020 1:19 pm

Re: Raspberry PI Cameras Set-Ups

Post »

ArduinoKid wrote:
Mon Apr 20, 2020 5:40 pm
If you're using a camera and Raspberry Pi for 3D printing, many budget webcams work really well with OcroPrint like the Microsoft LifeCam HD-3000, or the Logitech C920.
I have seen OctoPi in action and it does look good, especially on printers where it integrates nicely for timelapse. Looks like a good choice!

Posts: 51
Joined: Tue Aug 14, 2018 1:54 pm

Re: Raspberry PI Cameras Set-Ups

Post »

Thanks for sharing Jon! Definitely looks neat, I'll try out that script for sure!

Posts: 5
Joined: Thu Apr 16, 2020 1:19 pm

Re: Raspberry PI Cameras Set-Ups

Post »

Here we go, nothing amazingly complex...

Notes:
  • As mentioned the mogrify command was taken from the link I posted above, I just reformatted it and added variables (I cannot take credit for that).
  • I may have gone overboard with the echo statements, but it lets me know whats happening (especially when testing)
  • The working directory variable is to ensure everything is where it should be, especially if using cron as processes do not inherit environment settings, and the directory the script is executed may not be the one expected.
  • The date and time will appear in the top left, and should be readable on both light and dark backdrops
 

Code: Select all

WDIR=/var/www/html/img # Working directory
TIMR=30 # Time between photo's, assuming each photo takes less than this value

while [ 1 -eq 1 ]
do
stEPOC=`date +%s|cut -c4-` # EPOC time in seconds for easier maths.
echo `date`" : setting up"
shYEAR=`date +%Y`
shMNTH=`date +%m`
shDAYM=`date +%d`
shHOUR=`date +%H`
shMINT=`date +%M`
shSCND=`date +%S`

FILE1="current.jpg"
FILE2="img_${shYEAR}${shMNTH}${shDAYM}${shHOUR}${shMINT}${shSCND}.jpg"
FILE3="dated.jpg"
WIDTH=1024
OUTFILE="${WDIR}"
DATED="${shYEAR}-${shMNTH}-${shDAYM} ${shHOUR}:${shMINT}:${shSCND}" # Annotation for image


echo `date`" : housing (${shYEAR}/${shMNTH}/${shDAYM})"

mkdir -p ${shYEAR}/${shMNTH}/${shDAYM} # "-p" suppresses any errors if the directory exists

echo `date`" : snapping"
raspistill -o ${FILE1}
echo `date`" : shrinking"

mogrify -path ${OUTFILE} \
-filter Triangle \
-define filter:support=2 \
-thumbnail ${WIDTH} \
-unsharp 0.25x0.08+8.3+0.045 \
-dither None \
-posterize 136 \
-quality 82 \
-define jpeg:fancy-upsampling=off \
-define png:compression-filter=5 \
-define png:compression-level=9 \
-define png:compression-strategy=1 \
-define png:exclude-chunk=all \
-interlace none \
-colorspace sRGB \
${FILE1}


echo `date`" : annotating (${DATED})"
convert ${FILE1} \
-fill '#0008' -draw 'rectangle 5,10,130,30' \
-fill white -annotate +10+25 "${DATED}" \
${FILE2}

echo `date`" : re-homing"
cp ${FILE2} ${FILE3}
mv ${FILE2} ${shYEAR}/${shMNTH}/${shDAYM}


echo `date`" : done (${FILE2}/${FILE3})"
fnEPOC=`date +%s|cut -c4-`
TimeTaken=`expr ${fnEPOC} - ${stEPOC}`
echo `date`" : fin. (${TimeTaken} secs)"
echo "------------------------------------------"

SLEEPY=`expr ${TIMR} - ${TimeTaken}`
echo `date`" : sleeping (${SLEEPY})"
sleep ${SLEEPY}
done

# The End
Place the above script in a file (mine is called shooter.sh) and make it executable (chmod +x shooter.sh). Change the variables as needed (especially WDIR). Then it can be run as follows from the command line;

Code: Select all

$ nohup /var/www/html/img/shooter.sh >/var/www/html/img/shooter.log 2>&1 &
  • This will run the script in the background (the final ampersand (&)) and persists through a log out (nohup)
  • You will need to change the directories as needed
  • It will create a log file called shooter.log in your chosen directory
  • crontab could be used instead of my time calculations, but that only goes to minutes as the smallest unit.
Be warned this will run until you run out of storage, there is no housekeeping in my script for either the photos or the size of the log file!

The script will create a directory structure that will be made up of year/month/day, but also created two statically named files in the working directory called "current.jpg" (FILE1) and  "dated.jpg" (FILE3). I create these so all I need to do is hit refresh on a browser tab to get the latest (I have also used a static html file with some Javascript to refresh the page every 30 seconds).

Finally, I am assuming a certain familiarity with using the *nix command line so I have not gone into detail. Any questions about my script please let me know. But I am assuming you have a text editor of choice, and you have installed ImageMagick, plus Apache if you need it.

I am sure the script can be improved, but questions or suggestions let me know.

Jon.
 
 

Posts: 51
Joined: Tue Aug 14, 2018 1:54 pm

Re: Raspberry PI Cameras Set-Ups

Post »

As an update, there's a new Raspberry Pi 12-megapixel high-quality camera with interchangeable lenses! Pretty cool stuff. https://www.electromaker.io/blog/articl ... a-revealed