GPU Connected Component Labelling on Raspberry Pi 2


As part of a project I’m currently working on, I’m trying to figure out how to implement connected component labelling (i.e. blob detection) on a Raspberry Pi 2 so I can implement ball tracking on a soccer robot. I’ve experimented extensively with OpenCV and got something to work, except for the fact that running OpenCV on the Raspberry Pi 2 only yields framerates of ~3fps at 640x480. As a result I’ve decided to try implementing blob detection on the GPU. So far I haven’t actually implemented blob detection, but I have managed to filter based on hue so everything but the ball can be filtered out, and this appears to be far more promising (the GPU is running at over 60 frames/second at 720p with almost no latency.) The part I’m having trouble with is actually doing the connected component labelling. I have found some code (the GPUCL project, located at, however I’m having great difficulty porting it over to openFrameworks (I must admit my knowledge of OpenGL is somewhat limited.)

My question is, does anyone know of any pre-existing code for openFrameworks to do blob detection, or has anyone done this before and knows how to do it? Your assistance would be greatly appreciated, I’m currently tearing my hair out!


opencvExample (examples/addons/opencvExample) will do blob detection but probably will need some finessing to work on the RPi

A more modern version is available in ofxCv

But yeah - both of these versions are still CPU bound so likely slow.

The GPUCL project is interesting. One thing to know about working/porting OpenGL to the RPi is that you are restricted to whatever OpenGL ES 2 supports. This can get more complicated when shaders are involved (GPUCL has a few)

The way I would approach it is

  • port the GPUCL example to a desktop version of OF
  • Seeing if anything needs translated to work with the OF pipeline
  • Once compiling/running put it on the RPi and translate to OpenGL ES2


did this go anywhere? -
i’m looking for basically the same thing: fast blob-detection on a raspberry-pi

what would be a state-of-the-art method to do “connected component labeling” on the gpu which would run with OpenGL ES 2?
(is there any? i just found projects using CUDA)


found a paper on it: