Processing 使用Kinect/SimplePenni+;加工深度

Processing 使用Kinect/SimplePenni+;加工深度,processing,kinect,openni,Processing,Kinect,Openni,我正在使用带有简单OpenNI和处理的Kinect,我试图使用手的Z位置来模拟按钮按下。到目前为止,当我用一只手试的时候,效果非常好,然而,当我用另一只手试着让它工作时,只有一只手能工作。(我知道移动除了if语句的填充之外的所有内容会更有效,但我将它们保留在那里,以防我想更改大小或其他东西。) irz和ilz是onCreateHands首次识别手的初始Z位置,rz和lz是当前Z位置。到目前为止,一只手的代码工作正常,但另一只手要么保持按下状态,要么保持不按下状态。如果我将其中一个部分注释掉,它也

我正在使用带有简单OpenNI和处理的Kinect,我试图使用手的Z位置来模拟按钮按下。到目前为止,当我用一只手试的时候,效果非常好,然而,当我用另一只手试着让它工作时,只有一只手能工作。(我知道移动除了if语句的填充之外的所有内容会更有效,但我将它们保留在那里,以防我想更改大小或其他东西。)

irz和ilz是onCreateHands首次识别手的初始Z位置,rz和lz是当前Z位置。到目前为止,一只手的代码工作正常,但另一只手要么保持按下状态,要么保持不按下状态。如果我将其中一个部分注释掉,它也可以正常工作

if (rz - irz > 0) {
 pushStyle();
 fill(60);
 ellipse(rx, ry, 10, 10);
 popStyle();
 rpressed = true;
}
else {
 pushStyle();
 noFill();
 ellipse(rx, ry, 10, 10);
 popStyle();
 rpressed = false;
}

if (lz - ilz > 0) {
 pushStyle();
 fill(60);
 ellipse(lx, ly, 10, 10);
 popStyle();
 lpressed = true;
}
else {
 pushStyle();
 noFill();
 ellipse(lx, ly, 10, 10);
 popStyle();
 lpressed = false;
}
我试着输出rz-irz和lz-ilz的值,lz-ilz的数值范围从小的负值到小的正值(大约-8到8)。但是rz-irz根据每次运行的时间,输出8-30左右的数字,而且从来都不一致。另外,当我注释掉lz-ilz的代码时,rz-irz的值看起来很好,并且它按预期运行。跟踪两个Z位置是否有一个原因?有没有办法让它发挥作用


谢谢

我有几个想法:

  • 使用“点击”手势
  • 像现在一样使用手的z位置,但也要跟踪z移动的差异
  • SimplePenni似乎更喜欢一只手,而不是两只手的“咔嗒”等手势(拿起手后,您应该会看到打印的消息,然后向前和向后移动您的手)。 贝娄是一个简单的例子。请注意,我正在跟踪Z上的+/-差异,并使用阈值仅基于特定距离触发,例如,这可能是范围

    import SimpleOpenNI.*;
    SimpleOpenNI context;
    boolean      handsTrackFlag = false;
    PVector      handVec = new PVector();
    PVector      handVec2D  = new PVector();//just for drawing
    String       lastGesture = "";
    float        lastZ = 0;
    boolean      isPushing,wasPushing;
    float        yourClickThreshold = 20;//set this up as you see fit for your interaction
    
    void setup(){
      size(640,480);  
      context = new SimpleOpenNI(this);
      context.enableDepth();
      // enable hands + gesture generation
      context.enableGesture();
      context.enableHands();
      // add focus gestures  / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ?
      context.addGesture("Wave");
      context.addGesture("Click");
      context.addGesture("RaiseHand");
    
    }
    
    void draw()
    {
      context.update();
      image(context.depthImage(),0,0);
      // draw the tracked hand
      if(handsTrackFlag){
        context.convertRealWorldToProjective(handVec,handVec2D);
        float diff = (handVec.z-lastZ);
        isPushing = diff < 0;
        if(diff > yourClickThreshold){
          if(!wasPushing && isPushing) fill(255,0,0);
          if(wasPushing && !isPushing) fill(0,255,0);
        }else fill(255);
        lastZ = handVec.z;
        wasPushing = isPushing;
        ellipse(handVec2D.x,handVec2D.y,10,10);
      }
    
    }
    
    
    // -----------------------------------------------------------------
    // hand events
    
    void onCreateHands(int handId,PVector pos,float time){
      println("onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time);
    
      handsTrackFlag = true;
      handVec = pos;
    }
    
    void onUpdateHands(int handId,PVector pos,float time){
      //println("onUpdateHandsCb - handId: " + handId + ", pos: " + pos + ", time:" + time);
      handVec = pos;
    }
    
    void onDestroyHands(int handId,float time){
      println("onDestroyHandsCb - handId: " + handId + ", time:" + time);
      handsTrackFlag = false;
      context.addGesture(lastGesture);
    }
    
    // -----------------------------------------------------------------
    // gesture events
    
    void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition){
      if(strGesture == "Click") println("onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition);
    
      lastGesture = strGesture;
      context.removeGesture(strGesture); 
      context.startTrackingHands(endPosition);
    }
    
    void onProgressGesture(String strGesture, PVector position,float progress){
      //println("onProgressGesture - strGesture: " + strGesture + ", position: " + position + ", progress:" + progress);
    }
    
    导入SimplePenni.*;
    simplepenni语境;
    boolean handsTrackFlag=false;
    PVector handVec=新PVector();
    PVector handVec2D=新PVector()//只是为了画画
    字符串lastpostation=“”;
    浮动lastZ=0;
    布尔值是推,是推;
    浮动点击阈值=20//按照您认为适合您互动的方式设置此选项
    无效设置(){
    规模(640480);
    上下文=新的SimplePenni(此);
    enableDepth();
    //启用手+手势生成
    context.enablespirate();
    context.enableHands();
    //添加焦点手势/这里我确实在mac上遇到了一些问题,我只认识raiseHand?可能是cpu性能?
    上下文。添加手势(“波浪”);
    添加手势(“单击”);
    上下文。添加手势(“RaiseHand”);
    }
    作废提款()
    {
    update();
    图像(context.depthImage(),0,0);
    //画被跟踪的手
    if(手动跟踪标志){
    convertRealWorldTopProjective(handVec,handVec2D);
    float diff=(handVec.z-lastZ);
    isPushing=diff<0;
    如果(差异>点击阈值){
    如果(!wasPushing&&isPushing)填充(255,0,0);
    如果(正在推压和正在推压)填充(0255,0);
    }其他填充(255);
    lastZ=handVec.z;
    wasPushing=isPushing;
    椭圆(handVec2D.x,handVec2D.y,10,10);
    }
    }
    // -----------------------------------------------------------------
    //手工项目
    创建指针时无效(int handId、PVector pos、浮动时间){
    println(“onCreateHands-handId:+handId+”,pos:+pos+”,time:+time);
    handsTrackFlag=true;
    handVec=pos;
    }
    更新指针无效(内部指针ID、PVector位置、浮动时间){
    //println(“onUpdateHandsCb-handId:+handId+”,pos:+pos+”,time:+time);
    handVec=pos;
    }
    void onDestroyHands(int handId,浮动时间){
    println(“onDestroyHandsCb-handId:+handId+”,time:+time);
    handsTrackFlag=false;
    context.add手势(lastpostate);
    }
    // -----------------------------------------------------------------
    //手势事件
    void onrecognizesignature(字符串字符串字符串、PVector idPosition、PVector endPosition){
    如果(strGesture==“Click”)println(“onrecognizesignature-strGesture:+strGesture+”,idPosition:+idPosition+”,endPosition:+endPosition”);
    lastpershide=strGesture;
    语境。重构(strGesture);
    上下文。开始跟踪句柄(结束位置);
    }
    void onprogress手势(字符串字符串字符串、PVector位置、浮动进度){
    //println(“onprogress手势-strgestre:+strgestre+”,位置:+position+,进度:+progress”);
    }
    
    另一种获得双手的方法是在进行骨骼跟踪时使用
    SKEL_PROFILE_HEAD_hands
    ,但请注意,手的精度较低