"C" library for camera on Raspberry
How to read raw RGB values in a "C" program on RaspberryFor an internal project we needed to read raw data from the RaspberryPi Zero camera, manipulate them and send them to an external display via SPI interface.
We did the first test with Python and the pycamera library. Everything works fine, except we coulnd’t go faster than 2 fps.
In our tests, piZero 1.3 cannot go, with Python, beyond 2.3fps. Consider that the data, read at a very lores (320x200) were then manipulated pixel by pixel. So for every pixel we needd a fair amount of calculations, and besides we then had to pack them for the SPI protocol.
As much as we love Python, and we use it for most of our projects, it was not the way to go. It was too slow.
We had to resort to C, but we couldn’t find a C library for Raspberry that allowed us to access directly the raw RGB data coming from the camera.
Our only hope was in two programs: raspistill
or raspividYUV
, distributed with Raspbian and with open source code.
So we modified the two programs (actually the YUV versions which allow access to RGB bytes) and wrote two “library” like pieces of software, called cameraci
and videoci
. They are named with ahorrible twiest after the “C” language, and are just a little more than a rewriting of raspistillYUV
and raspividYUV
that expose a simple “C” interface.
Using this interface any C program can access raw RGB data coming from a camerar, as a sequence of still images or as a faster sequence coming from a video.
This way, performance can now go up to 20fps on a PiZero. Not too high, but more than enough for our purpose.
You can see in the picture that we write with our beautiful font FS:20.05
(20.05 average Frame per Second)!