Ответ Дитриха правильный (+1).
Есть несколько предостережений. Ошибка, которую вы получаете (ожидаются такие параметры, как: image(PImage, float, float)) связана с variable затенение
Вероятно, вы пытаетесь визуализировать изображение hand
внутри цикла for, однако цикл использует локальную переменную с тем же именем (hand
), которая в данном случае является экземпляром Hand
LeapMotion, а не PImage
.
Переменная цикла for (экземпляр Hand
) затеняет глобальную переменную (переменная PImage
).
Ошибка возникает из-за того, что он пытается отрендерить LeapMotion Hand
вместо вашего PImage
.
Вы можете просто переименовать локальную переменную:
import de.voidplus.leapmotion.*;
LeapMotion leap;
//Assets
PImage hand;
//Colours
color ocean = color(50, 113, 250);
void setup() {
size(700, 700);
background(255);
leap = new LeapMotion(this);
hand = loadImage("images/hand.png");
imageMode(CENTER);
}
void draw() {
background (ocean);
int fps = leap.getFrameRate();
for (Hand leapHand : leap.getHands ()) {
Finger index = leapHand.getIndexFinger();
PVector hpos = leapHand.getPosition();
PVector ipos = index.getPosition();
image(hand, hpos.x, hpos.y);
}
}
Это будет отображать несколько изображений для каждой руки.
Если вы хотите отрендерить одно изображение для одной руки, вы можете сделать несколько вещей.
Вы можете извлечь позицию из цикла, что означает, что самая последняя рука будет контролировать позицию изображения:
import de.voidplus.leapmotion.*;
LeapMotion leap;
//Assets
PImage hand;
//Colours
color ocean = color(50, 113, 250);
PVector handPosition = new PVector();
void setup() {
size(700, 700);
background(255);
leap = new LeapMotion(this);
hand = loadImage("images/hand.png");
imageMode(CENTER);
}
void draw() {
background (ocean);
int fps = leap.getFrameRate();
// hand inside is the loop is a Leap Hand instance, shadowing the PImage
for (Hand hand : leap.getHands ()) {
Finger index = hand.getIndexFinger();
PVector hpos = hand.getPosition();
PVector ipos = index.getPosition();
handPosition.set(hand.getPosition());
}
// hand here is your PImage
image(hand, handPosition.x, handPosition.y);
}
или вы можете использовать первую руку, например:
import de.voidplus.leapmotion.*;
LeapMotion leap;
//Assets
PImage hand;
//Colours
color ocean = color(50, 113, 250);
PVector handPosition = new PVector();
void setup() {
size(700, 700);
background(255);
leap = new LeapMotion(this);
hand = loadImage("images/hand.png");
imageMode(CENTER);
}
void draw() {
background (ocean);
int fps = leap.getFrameRate();
// try to read first hand data
Hand firstHand = leap.getHand(0);
// check if there is actual data (at least one hand is present)
if(firstHand != null){
// read hand's position
PVector handPosition = hand.getPosition();
// render image to hand's position
image(hand, handPosition.x, handPosition.y);
}
}
Есть много способов сделать это, это зависит от того, что имеет смысл для пользовательского опыта вашего проекта.
person
George Profenza
schedule
07.10.2020