All things Raspberry Pi and Time Lapse

Posts tagged ‘ImageMagick’

Hypnocube

I recently found the Hypnocube 4Cube, which is a grid of 64 RGB (Red/Green/Blue) LEDs laid out 4 LEDs wide, by 4 LEDs long, by 4 LEDs high. Pictures are at the bottom of this post. I wrote a little bit about in in my previous post here (bottom of the post). I decided to buy one and I am glad that I did! It was a very fun kit to build. It looks amazing at night with the lights off and the LEDs flashing different patterns and colors. I did a time lapse video as I built the cube and that is posted here (http://vimeo.com/59026344). The video is pretty long (10 minutes) but I think it is worth it to see some of the details in building. The pdf with building instructions is available from Hypnocube to download here (it is the 4Cube link – and the jig instructions are right below that).

I wrote a script (below) that used ImageMagick from the Linux command line added the date stamp onto the pictures. Basically it changed directories into the folder, then for each file it got the date and time from that picture, then put that stamp onto the picture. After this step I used an action in Photoshop to crop the images and do some basic image adjusting.

#!/bin/bash
var=$1
for x in $var
do
cd $x
for y in `ls`
do
name=`identify -format %[EXIF:DateTime] $y | cut -d “:” -f1-5`
convert $y -pointsize 50 -fill white -annotate +1000+1000 “$name” $y
done
cd ..
done

Their manual only includes instructions for Windows. But that wasn’t where I wanted to have it connected. After some searching around I figured out that the Hypnocube was located at /dev/ttyACM0 by running “dmesg | grep tty” and it was listed there. Then I installed the “screen” command and then typed in the command “screen /dev/ttyACM0 38400” and it works just like a putty session from Windows. Then to exit out of screen “CTRL+a+d” and it will exit. To return back to the session “screen -r” and it goes back to the session again. This works from a Fedora Linux desktop and also from a Debian based Linux distribution on a Raspberry Pi. This offers some really cool options like controlling the Hypnocube from my Android by using ConnectBot which is a ssh client for Android. So I can ssh into the Raspberry Pi or my desktop and then using the screen command I can “login” to the Hypnocube. Then using their commands I can switch to the next visualization or the previous one. I can lock it on the current one or pause it.

Pictures….

IMG_0009 IMG_0035IMG_0057IMG_0040IMG_5989IMG_5994IMG_5992IMG_9900IMG_9877

Advertisements

ImageMagick scripts

I found this post here about a guy who took all of his shots from a year and compiled them into a single image. This sounded like a cool idea, but I could never find the code for how this was accomplished. But I figured that it shouldn’t be too hard so I set about doing it for myself. I have 21 images so far and I compiled them into these two images. One from right to left. And the other from bottom to top.

Once I have more images it should look better as each section will be considerably smaller. I achieved these results using a command line program called ImageMagick on Linux. It was a very simple install ‘yum install ImageMagick’ (notice the capital letters) since I am using Fedora and that was all. Debian based distros may be something like ‘sudo apt-get install ImageMagick’ but I have not tried it. The weird thing though was that I was actually using the command line tool ‘convert’ from the command line instead of ‘ImageMagick’. Great documentation available at their site about the usage here. And documentation specifically about the cropping here. The command line usage looks like this:

convert input_file XxY+X+Y output_file

The program uses the X and Y axis for where to crop. The top left corner of the image is 0x0. The +X+Y is offset from that initial 0x0. Check out the scripts below for actual usage in the script. I did the math before I ran the script and that is where the 92 and 73 come from. I took the dimension of the image and divided by the number of images that I had. So the first image is 2048 wide and I had 21 images. Then I rounded that number down to get the 92 that was used in the script.

This first script is for the top image cutting columns of the image.

#!/bin/bash
# jamesmiller
# get list of files in current directory
files=`ls | grep “^rasplapse*”`
# set the initial crop point
x_factor=0
# for each file in the current directory
for x in $files
do
# ImageMagick convert program to crop the image
convert $x -crop 92×0+$x_factor+0 column_$x
# add to the initial crop point so the next image
# is not the same strip as the previous image
x_factor=$((x_factor + 92))
# add a border of white
#convert column_$x -border 1x column_$x
done
# get the list of newly created images
column_files=`ls | grep “^column*”`
# add all of the strips of images into one image
convert $column_files +append column_file.jpg

This script is for the bottom image cutting rows of the image.

#!/bin/bash
# jamesmiller
# get list of files in current directory
files=`ls -r | grep “^rasplapse*”`
# set the initial crop point
x_factor=0
# for each file in the current directory
for x in $files
do
# ImageMagick convert program to crop the image
convert $x -crop 0x73+0+$x_factor row_$x
# add to the initial crop point so the next image
# is not the same strip as the previous image
x_factor=$((x_factor + 73))
done
# get the list of newly created images
row_files=`ls -r | grep “^row*”`
# add all of the strips of images into one image
convert $row_files -append row_file.jpg

The very last line of each script is what compiles all of the strips of images into one image. NOTE: these scripts are meant to be executed in the folder containing the images. And they may need to be modified to suit other uses depending on the file naming structure and so forth.

I also tried these scripts using the pictures that were taken every 2 minutes. But even separating them out into three different pictures it didn’t turn out that neat. There was very little change across the picture because not that much moved in a single day.

Looking forward to using this technique on more pictures like the pictures shown above once I have more images!

Tag Cloud