Monthly Archives: June 2012

RealBasic: Robot A.I. – Part 1

The next series of articles will give a brief initiation in Robotic Artificial Intelligence. We’ll build a simulation of a robot with sensors. At first it will have no intelligence at all. But in the upcomming weeks we’ll learn it some tricks like finding the shortest path within a maze or house, handle closed passage ways and recalculate a new path to its destination. In another article we’ll learn the robot to find its location within a known map when it is dropped at an unknown location. Some exciting stuff!

But we’ll have to start at the beginning: building our robot Robby 🙂

Robby will have a couple of depth sensors (in reality these can be e.g. Kinect Depth cameras). They are placed on Robby so the robot can ‘feel’ everywhere around itself. They also have a limited range so Robby can only ‘see’ a limited distance. Robby is not a superhero, he cannot see through walls.
Robby changes to a red color when he is close to a wall, and colors green when he is at a safe distance.

Example of Robby:

You can see the robot, its sensors and a circle showing the range of the sensors.

In our first program, Robby is just like remote driven toy. We can go forward, turn left and turn right (with the cursor keys).

A framework will be build so we can later expand this program and even create other types of robots, sensors, etc…

Here is the layout of the framework:

ABSpace: This will hold our entry point to the world of robotics. It will describe the real world: what is the space Robby is walking in, where are the robots, etc…
Sensors: A simulation of sensors that can be attached to a robot. They can do measurements that the Robot A.I. can use.
Robots: A simulation of different types of robots that.
Global: Some classes we’ll need like Points, Maps, etc…

ABSpace is build like a movie with several frames. The steps we take are:

1. Initalize our space (give it a map, initialize our robot
2. Calculate a step (let all the sensors do measurements, calculate the new postition of the robot, let the Robot A.I. do it’s stuff)
3. Draw it so we’ll see the progress of our robots and what they have measured
4. Check if we’ll given some input to our robot (move, turn, etc)
5. Repeat from step 2

Here is a video to show what Robby Version 1 can do:

You can download the full source code at:

In the next part we’ll let Robby find the shortest path to a point on our map.

Happy programming!

Click here to Donation if you like my work

RealBasic: Computer Vision -> FAST Corner Detection

As promised, here is the FAST (Features from Accelerated Segment Test) implementation in RealBasic! And as you’ll notice, this is extremely fast!


AST is an acronym standing for Accelerated Segment Test. This test is a relaxed version of the SUSAN corner criterion. Instead of evaluating the circular disc only the pixels in a Bresenham circle of radius r around the candidate point are considered. If n contiguous pixels are all brighter than the nucleus by at least t or all darker than the nucleus by t, then the pixel under the nucleus is considered to be a feature. This test is reported to produce very stable features.[17] The choice of the order in which the pixels are tested is a so called Twenty Questions problem. Building short decision trees for this problem results in the most computationally efficient feature detectors available.

The first corner detection algorithm based on the AST is FAST (Features from Accelerated Segment Test). Although r can in principle take any value, FAST uses only a value of 3 (corresponding to a circle of 16 pixels circumference), and tests show that the best results are achieved with n being 9. This value of n is the lowest one at which edges are not detected. The order in which pixels are tested is determined by the ID3 algorithm from a training set of images. Confusingly, the name of the detector is somewhat similar to the name of the paper describing Trajkovic and Hedley’s detector.

It is the RealBasic translation of the nonmaximal FAST-9 written by Edward Rosten
With this library you can find Corners very fast within a picture.

and it can do this under e.g. different light intensities:

Again, the RealBasic engine has a simple interface so you can focus on the fun stuff!

    dim FCD as new ABFastCornerDetector
  dim tmpXYTraining(-1) as ABXY
  dim i as integer
  dim j as integer
  dim pic as Picture
  dim tmpPic as Picture
  dim DownSample as integer
  dim build2Dim as Boolean = true
  Dim f as FolderItem
  dim ft1 as new filetype = "picture"
  ft1.Extensions = ".png;.bmp;.jpg;.jpeg"
  dim dlg as OpenDialog
  dlg = new OpenDialog
  dlg.Title = "Pick picture"
  dlg.PromptText = "Pick a picture to compare"
  if dlg.InitialDirectory = nil then
    dlg.InitialDirectory = GetFolderItem("")
  end if
  f = dlg.ShowModal
  if f <> nil then
    if f.Exists then
      pic = f.OpenAsPicture
    end if
  end if
  ' these are then numbers you can play with
  FCD.threshold_detection = 20
  FCD.threshold_scoring = 0
  DownSample = 2
  ' do the FAST detection
  tmpXYTraining = FCD.detectFASTCornerFeatures(pic,DownSample, build2Dim)
  tmpPic = NewPicture(pic.Width, pic.Height, 32)
  tmpPic.Graphics.DrawPicture pic,0,0
  tmpPic.Graphics.ForeColor = &cFF0000
  ' and draw them
  for i = 0 to UBound(tmpXYTraining)
    tmpPic.Graphics.DrawLine tmpXYTraining(i).x*DownSample - 3, tmpXYTraining(i).y*DownSample, tmpXYTraining(i).x*DownSample + 3, tmpXYTraining(i).y*DownSample
    tmpPic.Graphics.DrawLine tmpXYTraining(i).x*DownSample, tmpXYTraining(i).y*DownSample-3, tmpXYTraining(i).x*DownSample, tmpXYTraining(i).y*DownSample+3
  Canvas1.Graphics.FillRect 0,0, 640,480
  Canvas1.Graphics.DrawPicture tmpPic,0,0

You can download the FAST engine from:

Until the next post!

Click here to Donation if you like my work

%d bloggers like this: