Search code examples
processingwebcamvideo-tracking

Using color tracked object as a cursor?


I'm using the Blob Detection library (below) to track find and track an object based on its color. I'm wondering how to go about using this object as a cursor, so that if its tracked over a certain part of the screen, the object will mimic a mouse click on that part of the screen.

http://www.v3ga.net/processing/BlobDetection/

What's the best way to go about doing this? I see there's a cursor() method, but it looks like that uses images, and blob detection isn't using images here.


Solution

  • You can use the java.awt.Robot class to generate all sorts of mouse move-events, mouse click events or keypresses.

    just import the class in the beginning of the sketch

    import java.awt.Robot;
    

    and wherever you handle the tracked blobs you create an instance of the Robot class and use it to manipulate the cursor

     ...
     Robot robot = new Robot();
     robot.mouseMove(x,y);
     robot.mousePress( button );
     ...
    

    see the javadoc for more details here http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html