Help needed with Leap Motion and live capture


#1

Hi all!

Can someone help me with this code? I’m trying to use the Leap Motion control the movement of the “scan beam” on the screen. It works when I use the mouseX as a input, but now I want it to use te X position from my hand coming from the Leap Motion.

Hope you can help me! I’m just starting with coding :slight_smile:

import processing.video.*;
Capture video;

import processing.serial.*;
Serial myPort;

import de.voidplus.leapmotion.*;
LeapMotion leap;

boolean tekenRondje;

ArrayList<PVector> points;
PVector fp;
float handPositieX; 
int newHandPositieX = int(handPositieX);


float interactionWidth = 200; // left-right from user
float interactionDepth = 150; // away-and-toward user
float fingerDot = 10;

void setup() {
  size(800, 500, P3D);
  

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  leap = new LeapMotion(this);
  delay(3000);
 
  video = new Capture(this, 320, 240);
  video.start();
}

void draw() {
  background(255);
  int fps = leap.getFrameRate();
  frameRate(fps);


  for (Hand hand : leap.getHands ()) {
//    for (Finger finger : hand.getFingers()) {
      fp = hand.getIndexFinger().getRawPositionOfJointTip();

    float   handTime     = hand.getTimeVisible();
    PVector thumbTip     = hand.getThumb().getRawPositionOfJointTip();
    PVector indexTip     = hand.getIndexFinger().getRawPositionOfJointTip();
    PVector ringTip      = hand.getRingFinger().getRawPositionOfJointTip();
    PVector middleTip    = hand.getMiddleFinger().getRawPositionOfJointTip();
    PVector pinkyTip     = hand.getPinkyFinger().getRawPositionOfJointTip();
    PVector handPosition = hand.getPosition();
   if(handPosition.y >= 200){
    handPositieX = handPosition.x;
//    tekenRondje = true;
   } else {
     handPositieX = 0;
//     tekenRondje = false;
   }
    

    handleFinger(thumbTip);
    handleFinger(indexTip);
    handleFinger(middleTip);
    handleFinger(ringTip);
    handleFinger(pinkyTip);
    }

//hand.draw();
myPort.write('1');
println(handPositieX);

int w = video.width;
  int h = video.height;
 
  copy(video, newHandPositieX/2, 0, 20, h, newHandPositieX, 0, 20, h);
  

//  positieHand = newHandPositieX;

}

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

void handleFinger(PVector pos) {


  float x = map(pos.x, -interactionWidth,
  interactionWidth, 0, width);
  float y = map(pos.z, -interactionDepth,
  interactionDepth, 0, height);

  fill(0,0,255);
  noStroke();
  if (tekenRondje){
  ellipse(x, y, fingerDot, fingerDot);
  }

}

Help needed with simple live capture