Changing starting point of mouse control by face tracking

edited October 2015 in Kinect

I am rather new at this, so my apologies if this has a simple solution. I have created a rudimentary mouse control sketch using face tracking (see below). However, the cursor appears and stays in the top left corner of the screen, not in the center of the screen. Is there a simple way to resolve this? Thank you in advance.

import gab.opencv.*;
import processing.video.*;
import java.awt.Rectangle;
import java.awt.AWTException;
import java.awt.Robot;

Capture video;
Robot robot;
OpenCV opencv;
Rectangle[] faces;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);         // open video stream
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  // load detection 

  video.start();

  try {                                       
    robot = new Robot();                       
  }                                            
  catch (AWTException e) {                   
    e.printStackTrace();                        
  }                                              
}

void draw() 

{
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    robot.mouseMove(faces[i].x, faces[i].y);           

  }
}

void captureEvent(Capture c) {
  c.read();
}

Answers

  • Hello, rpatton!

    You don't need to use Robot. Processing is much cleverer and easier =)

    mouseX = faces[i].x;
    mouseY = faces[i].y;
    

    Have a look here for the similar question.

Sign In or Register to comment.