简体   繁体   中英

Counting issues during real-time tracking on Android

I am making an app using ML KIT. I am currently implementing counting while doing squats. The problem is that it counts when it goes down to a certain angle, but because it is a real-time tracking, it counts multiple times rather than once. In other words, practically when I do one squat, the counting is much more than that. So I tried solving the problem using a timer handler. But I failed. Here is my code What should I do?

     //going down
      if((rightKneeAngle<=90 && leftKneeAngle<=90) || (rightHipAngle<=135 && leftHipAngle<=135)){
        //Timer setting
        mTimer.schedule(new CustomTimer(), 2000);

    Log.d("PoseGraphic.class", "goingdown"+"rightKneeAngle : " + rightKneeAngle+ " leftKneeAngle : " + leftKneeAngle);
    Log.d("PoseGraphic.class","leftHip"+leftHipAngle+"RighHip"+rightHipAngle);
    Log.d("PoseGraphic.class", "cnt: " + cnt);


    //going up
    if((rightKneeAngle>170 && leftKneeAngle>90)|| (rightHipAngle>135 && leftHipAngle>135)){
      Log.d("PoseGraphic.class", "going up"+"rightKneeAngle : " + rightKneeAngle+ " leftKneeAngle : " + leftKneeAngle);
      Log.d("PoseGraphic.class","leftHip"+leftHipAngle+"RightHip"+rightHipAngle);

      if(cnt==12) {
        canvas.drawText("complete!", x, y, textPaint);
        //ExerciseCount.cnt = 0;
        cnt=0;
      }

    }

  }

//  TIMER handler class

    class CustomTimer extends TimerTask 
    @Override
    public void run() {
      cnt++;
    }

I cannot fully understand how you do it without seeing more code.

An suggestion would be: Instead of +1 to the count when the pose is in squat_down state, record the entering of that state with a boolean and +1 to the count only once the user exit squat_down and enter squat_up state. Then reset the state boolean. By doing this, you will only +1 when user finish an entire cycle from squat_down to up.

Actually, ML Kit just launched an example for squat and pushup classification and rep-counting. Here is the app you can try. If you want to classify some other poses, here is some guide and a Colab .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM