Tuesday, December 23, 2014

Installing libgroove and nodejs groove module in Raspbian

As we are working on small internal hobby project turning the Raspberry PI into a music box, I came across the need for building the nodejs groove module which requires a pretty big amount of effort. I'm going to provide you with the instruction for building from source.

UPDATE: If using testing/unstable repo is not a problem for you, an alternative method is available and is much faster by using binary packages. Jump to the "Install using testing/unstable binary packages"  section.

Install from source

This is the shorten version of the build script for Raspbian Wheezy that I think it may be useful for other ones struggling with a similar task.

Note: this is the simplified version of a great guide created by Andrew Kelly: Turn Your Raspberry Pi Into a Music Player Server

# install tools and libs
sudo apt-get install cmake git screen
sudo apt-get install libchromaprint-dev libspeexdsp-dev libasound2-dev libmp3lame-dev libvorbis-dev

# install libebur128 from source
cd
git clone https://github.com/jiixyj/libebur128
cd libebur128/
mkdir build
cd build/
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
sudo make install
sudo mv /usr/local/lib/arm-linux-gnueabihf/* /usr/local/lib/
sudo rmdir /usr/local/lib/arm-linux-gnueabihf
sudo ldconfig

# install SDL2 from source
cd
wget https://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar xvf SDL2-2.0.3.tar.gz
cd SDL2-2.0.3/
./configure --enable-audio --disable-video --disable-render --disable-events --disable-joystick --disable-haptic --disable-power --disable-file --disable-timers --disable-loadso --disable-cpuinfo
make
sudo make install

# install libav from source, will takes about 9hrs (!), consider using 'screen'
cd
wget http://www.libav.org/releases/libav-10.1.tar.gz
tar xvf libav-10.1.tar.gz
cd libav-10.1/
./configure --enable-shared --enable-debug --disable-static --enable-gpl --enable-libmp3lame --enable-libvorbis
make
sudo make install
sudo ldconfig

# install libgroove from source
cd
git clone https://github.com/andrewrk/libgroove
cd ~/libgroove/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
sudo make install
sudo ldconfig
ls /usr/local/lib/

#install newer nodejs ARM, this is optional
get https://github.com/needforspeed/Nodejs-ARM-builder/raw/master/v0.10.33/nodejs_0.10.33-armv6_armhf.deb
sudo dpkg -i nodejs_0.10.33-armv6_armhf.deb
which node


#install nodejs groove
npm install groove -g

Install from testing/unstable binary packages

At the time of writing, the testing repository of Raspbian contains a usable set of binary packages that are sufficient for installing node groove module.

Step 1: switch to testing

Edit the /etc/apt/sources.list to replace wheezy with testing, so that the first line of the file reads:

deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi

Step 2: update and install the libraries

sudo apt-get update
sudo apt-get install libgroove4 libgroove-dev libgroovefingerprinter4 libgroovefingerprinter-dev libgrooveloudness4 libgrooveloudness-dev libgrooveplayer-dev libgrooveplayer4

Step 3: install node groove module

npm install groove -g


Thursday, February 20, 2014

Make your camera DICOM-able with a Raspberry PI

As I'm working on a medical product which includes almost all aspects of medical services, working with DICOM is one of my primary items. I came accross a requirement for integrating standard photo cameras into the system so that photos taken from those cameras can be easily imported into medical results. This initially came from an international clinic where physicians use high resolution EOS cameras to take patient's skin photos.

Our medical solution has a built-in feature that accepts images sent from DICOM compliant devices like ultrasound machines so my primary path for the intergration is to make the cameras DICOM-able. There are however several constraints for the solution:
  • There will be a large set of camera models that we need to support, ranging from low-end ones like the Canon IXUS to something like the 7D series.
  • The solution needs to be independent from the user workstation operation system as the users of our medical product can use different types of OS including Windows, OS X or GNU/Linux.
  • User operation needs to be as simple as possible as we want to avoid any redundant step in manually selecting the files and sending them.
My solution for this was to use a Raspberry PI, loaded with Pidora and custom scripts to work with the camera and send captured photos via the network to the DICOM storage server.

To support different camera models, I used the gphoto2 command line tools to watch camera activities and download photos to the Rasperry PI. The connection between the Raspberry PI and the camera is a USB cable. Downloaded photos will be then converted into DICOM files and sent to the server using the dcmtk command line tools. The following steps provide you with the details on how to get it done:

Step #0:
Prepare your Raspberry PI with Pidora. Connect it to the camera using a USB cable and to the local network using an ethernet cable.

Step #1:
Install necessary tools:

# yum -y install gphoto2 dcmtk

Step #2:
Make a main script that invoke gphoto2 and watch for captured photos

$ nano capture.sh
#!/bin/sh

while :
do
    export CAMERA=`gphoto2 --summary --quiet 2>&1 | grep "Model: " | sed "s/Model: //"`
    if [ "x$CAMERA" = "x" ]; then
        sleep 1
        continue
    fi
    gphoto2 --quiet --capture-tethered --hook-script=camhook.sh
done


Step #3:
Make the script that handles the downloaded photo and send it via DICOM

$ nano camhook.sh
#!/bin/sh

if [ "x$ACTION" = "xdownload" ]; then
    echo "Converting to DICOM..."
    img2dcm -k "PatientName=$ARGUMENT" $ARGUMENT $ARGUMENT.dcm
    echo "Sending to storage..."
    storescu -aet "$CAMERA" --propose-jpeg8 192.168.100.51 9104 "$ARGUMENT.dcm"
    echo "Done."
    rm $ARGUMENT.dcm
fi



After having all the setup done, starting the capture.sh will make your camera now DICOM-able.