libpng – Changing compression level when writing PNG Image

This took me a bit of time to find, but I have been experimenting with libpng for writing software to save 16bit grayscale images and wanted to switch off compression to see if libpng would save the images out any faster than it normally does. When you call png_set_IHDR() you have to set the compression type to PNG_COMPRESSION_TYPE_DEFAULT, there is no alternative (e.g. there is no value like PNG_COMPRESSION_TYPE_NONE), this threw me for a bit…

Anyway after a spell of RTFMing, I eventually found out that you can alter then compression level, and indeed switch it off via a call to:

Setting a value of 0 in your code switches off compression, while setting it to 9 causes the lib to use maximum compression. Quick testing revealed that the time taken to save a PNG does decrease as you reduce this value towards 0 (and the saved image size increases!).

PNG is a good file format option for saving 16bit images, it is lossless and faithfully represents grayscale rather than fudging it into an RGB structure, and as it turns out, supports adjustable compression levels. As more cameras natively support higher bit-depth images, formats and software tools that support the greater precision will become more important so that Computer Vision and Machine Vision software can take full advantage.

PS Viewing 16bit grayscale images is harder than you might think, most software tools seem to down-sample them to 8bit grayscale, So far, I have found that good options are a.) ImageJ b.) Gimp 2.9 (not yet released, have to use a development build). These tools allow you to view the images and properly sample the 16bit pixel values etc…

Raspberry Pi and GPS for Testing Camera Image Timestamps with NTP and PPS

raspberry_pi_gps_pps_time_image_timestamp

An image time-stamp will tell you when an image was acquired by its camera, they are typically donated in Coordinated Universal Time (UTC) – accurate time-stamps are very often important in Computer Vision Applications especially those that involve observing or analyzing change over time.

Implementing such time-stamp functionality on a camera is very hard and typically involves both hardware and software support – testing the functionality to make sure that the time-stamps are accurate is nearly even harder!

A time-stamp’s accuracy is partly dependent on how well the camera’s time is synchronized, if it’s time is well synchronized by the Network Time Protocol (NTP) then an accuracy of a few milliseconds can be expected, if full pulse-per-second (PPS) synchronization is used then (with care) an accuracy of tens of microseconds can be achieved.

In order to test time-stamp accuracy it is necessary to have an accurate time source to act as a test base-line for comparison purposes, multiple cameras can the then be synchronized to this via their acquisition triggers and NTP or PPS and their images and image time-stamps can be compared.

To this end we have been prototyping a Stratum 1 time source built using a Raspberry Pi with a GPS shield. This will take its time reference from GPS and provide the following for testing cameras:

+ NTP time server (stratum 1) – Raspberry Pi & NTP syncs its time to GPS time via PPS signal and time packets (ZDA packets), the cameras’ NTP clients can use this for synchronizing their clocks (purley software based synchronization).

+ Electrical PPS output – Can be used by camera for syncing it’s time via PPS and for triggering acquisition on second boundaries

+ Re-transmit PPS time packets (ZDA) via UDP – Can be used by cameras for syncing their time via PPS (software & hardware synchronization)

To build the time source we are following this excellent article which explains the various steps involved:

http://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html

Many thanks to David Taylor, it is a rather complex subject with lots of software setup on the Pi, it hurts our heads but we are making progress, and the initial prototype has already been very helpful in characterizing camera triggering and time-stamping behavior. We expect great things.

In terms of hardware we are using:

Uptronics Raspberry Pi+ GPS Expansion Board – with the GPS Timing Antenna

Raspberry Pi 3

Image Processing with Intel’s SSE SIMD instructions for 12-bit images

Over the last few days I have been working on implementing some low-level 12-bit image processing functions using Intel’s SIMD instruction set – SSE. The aim here is to increase processing time performance as much as possible – initial results are very encouraging, those 128bit register really get things to scream along!

It has been a while since I have done such work on Intel devices (ARM and hence ARM NEON is more common on IoT projects), the last time was before MMX ‘Intrinsics’ were invented and involved hand coding MMX instructions with associated support assembly language. Intrinsics really make coding this stuff so much simpler!

Very often it doesn’t pay for a software engineer to hand-code and optimise image processing algorithms, but when maximum performance is required, huge speed gains can be made with some careful coding on standard hardware!

Cross compiling libEXIF for ARM on Ubutnu

libexif is a software library that allows you to add EXIF tags to JPEG images, for example when saving JPEG images via libJPEG.

The following is a log of the steps taken to cross compile libexif on ubuntu for an ARM IoT device, you will need the arm-linux-gnueabi tool-chain installed on your build machine:

1.) Download the latest libexif source code from:

http://sourceforge.net/projects/libexif/files/latest/download?source=files

2.) uzip & untar the software:

3.) Execute the following from bash or similar:

This should put the output files into /home/me/build_exif/_install ready for copying onto your ARM device.

Code to test u-blox Binary GPS Packet Checksum

Here’s something random for a Thursday, the following is some simple C++ code for checking the checksum of a u-blox binary GPS packet, for some reason we get quite a few packet data errors, so it turns out that it is important to check the checksum!

There must be an unwritten (or written?) software engineering rule which states that you should always check a checksum if one’s provided??!?

Note: Make sure to pass only complete packets to this function, it assumes it has everything to work with!

IEEE has C as top Programming Language in 2016

The IEEE reports here that C is the number 1 programming language in 2016. As usual, I am slightly dubious about a lot of these rankings, each one seems to yield a different order. Still you would hope that the IEEE would employ a little more rigour than most! Funny thing is I just don’t see many of these C programmers about… Mind you I know one C programmer who personally outputs about 10 times the amount of code as most…

Friday – Programming in pure unadulterated C Today

Today I have the pleasure in programming in pure & unadulterated C, there is something really refreshing about the clean and minimal elegance of the language and its associated design principles, especially considering the weight of baggage the software engineering discipline has gathered of late – not bad for a rainy Friday!

Accuracy of the various Windows software timers

This (admittedly quite old) article provides an interesting comparison of the accuracy of the various software timers available under windows, it looks like the Multimedia timers are still the best despite apparently being frowned upon my Microsoft.

http://omeg.pl/blog/2011/11/on-winapi-timers-and-their-resolution/

I plan to trial camera acquisition using a software trigger, and in order to obtain as accurate and reliable a trigger as possible I want to get as close to a timer interrupt handler as windows will allow, in the hopes that it will be ‘good enough’ for my computer vision application. For a really reliable trigger time-base I normally use a hardware trigger generated by a micro-controller or similar, but this time as the timing constraints aren’t as onerous I have decided to see if I can get away without one, so we will see…. I guess I will have to test the various options and see which is best and if any of them are (generally) within spec..

Good NTP Client Setup Description

As a software engineer (rather than an NTP guru), I find that configuring and debugging an NTP setup can be quite challenging, it is (by its nature) a difficult subject, and a lot of the info out there is quite dense and hard to parse, so I was presently surprised to come across this nice article, called ‘Real Life NTP’ which gives a good overview and describes the use of ntpq -p etc.

https://pthree.org/2013/11/05/real-life-ntp/

Thanks Aaron!

Nice Bootsrap / AngularJS based templates

I was browsing yesterday and came across some nice bootstrap based templates for web app development, especially this one:

http://wrapbootstrap.com/preview/WB04HF123

The nice this is that a version built on AngularJS is available, although I can’t vouch for its build quality not having seen the code…

Templates like these are a great starting point for software developers wishing to put together a web application that doesn’t necessarily look terrible – without the need of one of those GUI guys! Perfect for developing a HMI for an embedded device for example or for developing a cloud application, or even for developing a local app on your PC with Node.js!?