dLife Vision Example

 

public class CokeCanTracker extends Controller {


    private BlobFilter blobs;

    private ImageSequenceCamera myCam;


    public void startUp(Robot myRobot) throws VideoSourceCreationFailedException {

        myCam = new ImageSequenceCamera();

        myRobot.addDevice(myCam);


        // Gaussian blur with width 7 pixels and standard deviation of 3

        GaussianFilter gf1 = new GaussianFilter(7, 3.0);

        myCam.addFilter(gf1);


        // Match the colors found in the Coke can and turn them yellow.

        MatchFilter mf2 = new MatchFilter(77, 186, 17, 79, 18, 83);

        myCam.addFilter(mf2);


        // Find at most 1 blob of at least 100 yellow pixels.

        blobs = new BlobFilter(new Color(255, 255, 0), 100, 1);

        myCam.addFilter(blobs);

    }


    public void step() {

        // Draw a cyan circle to indicate the location of the Coke can.

        Collection<Blob> blobCol = blobs.getBlobs();

        Iterator<Blob> it = blobCol.iterator();

        if (it.hasNext()) {

            Blob b = it.next();

            myCam.clearDrawing(Camera.RAW_VIDEO);

            myCam.drawCircle(Camera.RAW_VIDEO,

                             (int)b.getCenterOfMass().x,

                             (int)b.getCenterOfMass().y,

                             10, Color.CYAN, true);

        }

    }

}

The example below, for use with the ControlCenter, uses blurring, color matching and blobification to track the location of a Coke can in sequence of images.  In order to be used with the ControlCenter this class extends dlife.robot.Controller and provides two methods:

  1. startUp: This method is executed once when the ControlCenter’s Start Up button is clicked. It creates a camera and adds it to a robot.  It also creates the necessary filters and adds them to the camera.

  2. step: This method is executed repeatedly by the ControlCenter after the Run button is clicked.  It accesses data from the BlobFilter and draws a cyan circle to indicate the location of the Coke can.

Similar code could be used to perform image processing in a stand-alone Java program.