RaspiMower C++ RaspiCam Integration

I spent a bunch of time trying to convert the C code for RaspiStill to work in my project and I decided to abandon C as the language for the RaspiMower based on how messy it was getting (my fault really, I tend to use C++ at work). So I researched and found a c++ library for accessing the RaspiCamera at www.uco.es/investiga/grupos/ava/node/40.

I downloaded the zipped version 0.1.1 from sourceforge to my linux pc and unzipped it, then I copied it to my pi using the following commands.


ssh pi@192.168.1.52
mkdir ~/raspicam
cd ~/raspicam
scp -r [username]@192.168.1.170:/home/[username/raspicam-0.1.1/* .

sudo apt-get install cmake

mkdir ~/raspicam/build
cd ~/raspicam/build
cmake ..
make
sudo make install

Tested the compilation by running raspicam_test. It did not work! it could not find the library even though it exists in /usr/local/lib.
Had to do this to get it to run:

export LD_LIBRARY_PATH="/usr/local/lib"
raspicam_test
ls -al (should show 3 new files imagexx.ppm that are about 3MB each with a resolution of 1280 × 960 pixels)

This is not quite what I was hoping for. I want the full 5 Mega-Pixels available from the Camera.

I looked at the compiled code and edited /utils/raspicam_test.cpp to get the full resolution by default 2592*1944. Recompiled and now I get the full image size (15MB per file) I wanted without entering any parameters, however it is actually just giving the 1280*960 scaled up to 2592*1944! Looks like this will not work for the project currently, I guess I will need to dig into the c++ code to find out why it is not working…

A possible alternative to the C++ library is to use the c function calls from raspistillyuv.c, but to use it I need to compile a ton of stuff ie ‘userland’. The instructions to get and build the userland files can be found at this link compile-raspberry-pi-userland-raspivid. The instructions are simple and straightforward and worked for me on my first try, but I am not sure if this is the route I want to take as it adds a lot of code to my project instead of using a library.

28-Dec-2014
After reading up on the raspicam library and how it should be working properly (meaning I am probably doing something wrong), I decided to stick with it. I compiled the sample simpletest_raspicam.cpp and got it working, then I integrated it into my old c code, while renaming the raspiMower.c to raspiMower.cpp. As I work I will be cleaning and merging the old c functions into different C++ objects to make it easier to understand. For now I am going to use the default preview resolution because the Pi may not have the power to process the full 5 MegaPixel image as fast as I want, so I might as well start small and increase the resolution if needed.

The latest version of the code will capture an image once per second and overwrite the image.ppm file in the application directory. I ran this code with the image being saved to the sd card and without it being saved and timed the operation to see how it would affect the main program. I saw an upper time of about 180ms for the case where I saved the image and 78ms when I did not save it. I would eventually like to make a lower res image available on a web page, so it is important to get a feel for the CPU load. I thought about multi-threading this, but since the Pi has only 1 CPU I do not think a thread will help, maybe I am wrong?

The latest RaspiMower code can be found on BitBucket at https://bitbucket.org/ronostafichuk/raspimower.

To compile it you first need to download, compile and install the raspicam code mentioned above so that you have the raspicam library installed on your pi.
Then run the following command to compile the raspiMower.cpp file.


export LIBRARY_PATH=/opt/vc/lib
g++ raspiMower.cpp -o raspiMower -I/usr/local/include -L/opt/vc/lib -lraspicam -lmmal -lmmal_core -lmmal_util -lwiringPi -lrt

I have added a codeblock project file ‘raspiMower.cbp’ to the repo to make it easier to load, compile, and debug this project.

Next: Creating a web interface with high quality streaming video!