Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Camellia: Image processing from Ruby

By Peter Cooper / June 1, 2006

In this photo, a Ruby script has found the license plate and marked it with a red box (source below).

Camellia is a powerful 'computer vision' library you can use from Ruby. It's written in C, is cross platform, and offers lots of features like color conversion, warping, filtering, drawing, and labeling. Here's the source code to find the license plate in the photo above:

require 'rubygems'
require_gem 'camellia'
include Camellia

# load picture alfa156.bmp

# consider only the V plane (red)

# threshold and encode

# labeling
puts "#{blobs.nb_blobs} blobs detected"

# draw rectangle on all detected blobs 
blobs.each {|b| image.draw_rectangle(b.left,,b.left+b.width-1,,cam_rgb(255,0,0))}

# save the resulting picture

# find out the biggest blob
sorted=blobs.sort {|a,b| b.surface<=>a.surface}
puts "The bigger blob is at position (#{sorted[0].cx},#{sorted[0].cy}) and its surface is #{sorted[0].surface}"

Update - May 2007: Paul Battley has worked out how to get this all running on Mac OS X.

Technorati Tags: ,

Other Posts to Enjoy

Twitter Mentions