Courtesy of the OpenCV 2.3 GPU code comes a neat snippet of code for using a template parameter for reading RGB or BGR ordered components when dealing with RGB triplets.

The Code

  1. template <int blueIndex>
  2. float rgb2grey(const float *src)
  3. {
  4.    return 0.114f*src[blueIndex^2] + 0.587f*src[1] + 0.299f*src[blueIndex];
  5. }

Then to use the function you simply supply the index where the blue value resides to take care of the RGB vs BGR ordering.

For RGB ordering:

float g = rgb2grey(src);

And for BGR ordering:

float g = rgb2grey(src);

This only works for swapping R and B around and won’t work for more weird and wonderful orderings

The original OpenCV code can be found in modules/gpu/src/opencv2/gpu/device/detail/color.hpp.

Templates and CUDA

For me the fact that you can use template meta-programming is a real plus point of CUDA. It allows for good code re-use and the template expansion gives good scope for the compiler to optimise. It can also allow you to remove conditionals from kernels in appropriate circumstances – more in a future post!

The KuroBox finally gave up the ghost and wouldn’t boot after a recent Debian update. I didn’t have the will to go through rebuilding it from scratch again, so invested in something a bit more modern. Something that has a GUI output even when you screw up a kernel upgrade! I’d had my eye on a Atom/ION system for a while and ended up getting a Zotac HD-ID11.

It was a very simple to get up and running with Ubuntu, XBMC and Mythtv.

NB – you could fry both your television and your PC doing any of this. Be careful, check, check and triple check everything before plugging it in. That said I haven’t had any problems for several months now, but check all your connections and soldering for shorts before plugging it all together.

Update 17/10/2012: some more details in a follow up post.

HDMI into SCART doesn’t go

Only having an old CRT TV means that connection options are pretty limited, with the only useful once being SCART. The TV does accept RGB, which makes life easier. You may think that the easy option would be to get a new TV, but that’s not nearly as much fun 😉

All the Atom/ION boxes have generally HDMI and DVI/VGA outputs. In the case of the HD-ID11, it has HDMI and DVI connections.
Continue reading

Displaying equations in webpages has always been a headache. The fallback of using images was always there, but in the age of blogs and other content creation tools editing, updating and maintaining images for equations is tedious.

MathML was an effort to standardise support in browsers, but the reality of it is that it only works out of the box in very few cases.

Whilst looking for a way to easily put equations into a WordPress blog, MathJax turned up. Have a look at some of the examples!

MathJax in WordPress

A quick search turns up a couple of WordPress plugins, of which I ended up using Latex for WordPress, which
allows me to easily put Latex syntax equations directly into posts.

$ $x = frac{-b pm sqrt{b^2 – 4ac}}{2a}$ $

$$x = \frac{-b \pm \sqrt{b^2 – 4ac}}{2a}$$

All in all excellent, 😉

Subversion is a bit lacking on the merging and branching front in comparison with some of the newer distributed version control systems, but it does make working with large projects easy. The single biggest reason for this is sparse checkouts.

At work we have a source tree that contains artwork, documentation, the source for all the third party libraries we use and compiled versions of these for multiple architectures and platforms (32bit, 64bit, windows, RHEL4, RHEL5 etc). This makes the full checkout rather large and there are many times when you only need a small fraction of all the files.

The problem with sparse checkouts is that it can become very laborious manually setting one up for anything beyond a few directories. For more details on the basics see here. As with many tedious tasks – computers can help!

I put together a little script for helping with this – get it here. I hope it’s useful and keep reading for more details on how it works.

In Action

The final version of the script makes doing a sparse checkout as simple as doing an standard checkout:
./checkout.rb svn://server/trunk

To checkout using a named subset of files:
./checkout.rb --map documentation svn://server/trunk

To checkout using a locally defined subset of files (rather than a subset stored on the sever):
./checkout.rb --map local.yaml svn://server/trunk

Continue reading

For 2.5 yrs work has made use of a Kolab server I set up, but recently it has been taking up too much of my time to maintain. Google Apps was chosen as the replacement, so the problem then became how to get 39GB of data uploaded to Google over a fairly slow ADSL link, whilst keeping everyone up and running as much as possible.

imapsync seemed to be the tool of choice for a lot of people doing migrations of IMAP users, and it has done a very good job here too. I used version 1.311 from source rather than the older package provided with Ubuntu at the time as it contained various fixes for Google’s IMAP servers.
Continue reading

At work we are getting a 64-bit version of our software up and running at the moment. Most of the usual culprits reared their head – assuming that a pointer and integer had the same size etc etc.

One more interesting one, which I’ve not come across before is related to using STL string::find and the special constant string::npos. This is not unique to our code base when you google for it and actually just boils down to data being truncated before a comparison. The nuances of the problem do lead on to a discussion about signed vs. unsigned integral types in C++ and the handling of comparisons between differently sized data types. I though it was worth looking at a bit further and definitely something to watch out for when doing code reviews.

It could also make for a particularly challenging interview question 😉

Continue reading


I have a Kurobox HG, that has been running Gentoo for a while now. After getting fed up with the waits for compiling packages I decided to switch over to Debian.

Only having SSH access to the box makes switching OS a slightly more tricky prospect than a standard OS switch or upgrade.

The basic plan is:

  • Disable swap
  • Install a very basic debian system onto the swap partition
  • Reboot into the basic debian system
  • From the basic debian system, install a debian system onto the main partition
  • Reboot into the basic debian system on the main partition
  • Reformat and enable the swap partition
  • Finish configuring the new system
    There were a few tricky steps along the way, so I’ve documented all the steps below.
    Continue reading

Well the Visual Editor mode doesn’t appear to get on very well with the [mediawiki-plugin] – it puts html tags all over the wiki text making updating pages very tedious and making the whole point of using the Wiki syntax a bit redundant.

There do appear to be a few pages on the web talking about having problems with more advanced page layouts when using the Visual Editor, so probably for the best to have it disabled.

There are a few plugins to disable the Visual Editor and Easy Disable Visual Editor appears to do the job with the latest WordPress.


MythTV is an exceptional linux based PVR. It has an interesting and very configurable split frontend/backend architecture.

One traditional use for this split architecture is to put all the mass storage and recording hardware in a box under the stairs and then have a lightweight (and silent) machine plugged into the TV. Encoding video in realtime requires either some pretty powerful CPUs or alternatively dedicated hardware.

Enter DVB-T and a USB dongle to capture DVB mpeg streams.
Continue reading