【问题标题】:Android Accelerometer - Dynamic Time WarpingAndroid Accelerometer - 动态时间规整
【发布时间】:2016-03-08 19:31:47
【问题描述】:

对于课堂项目,我需要使用加速度计识别手势。 我目前在 x、y 和 z 值上使用 if 语句的显式方法。

我读过动态时间包装是一种更有效的方法,因为它检查手势和先前存储的手势之间的匹配。

我将如何在 Android 中进行编码,因为我似乎无法在网上找到任何东西。

public void onSensorChanged(SensorEvent event) {

    final float alpha = (float) 0.8;

    // Isolate the force of gravity with the low-pass filter.
    gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
    gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
    gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

    // Remove the gravity contribution with the high-pass filter.
    linear_acceleration[0] = event.values[0] - gravity[0];
    linear_acceleration[1] = event.values[1] - gravity[1];
    linear_acceleration[2] = event.values[2] - gravity[2];

    float x1 =  linear_acceleration[0];
    float y1 =  linear_acceleration[1];
    float z1 =  linear_acceleration[2];

    x.setText("X: "+ x1);
    y.setText("Y: "+ y1);
    z.setText("Z: " + z1);

    if(y1 < -2 && z1 > 2)
    {
        action.setText("Phone Moved Forward!!");
        image.setVisibility(View.VISIBLE);
        image.setImageResource(R.drawable.forwardarrow);
    }
    else if(y1 < -2 && z1 < -2)
    {
        action.setText("Phone Moved Toward Face!!");
        image.setVisibility(View.VISIBLE);
        image.setImageResource(R.drawable.backarrow);
    }
    else if(y1 < -2 && x1 > 2)//y down, x up = left tilt
    {
        action.setText("Phone Titled Left!");
        image.setVisibility(View.VISIBLE);
        image.setImageResource(R.drawable.leftarrow);
    }
    else if(y1 < -2 && x1 < -2)//y down, x down = right tilt
    {
        action.setText("Phone Titled Right!");
        image.setVisibility(View.VISIBLE);
        image.setImageResource(R.drawable.rightarrow);
    }
    else
    {
        image.setVisibility(View.GONE);
        action.setText("Stable");
    }

}

【问题讨论】:

    标签: java android accelerometer android-sensors gesture-recognition


    【解决方案1】:

    我已将一个存储库上传到 GitHub,该存储库演示了加速度计数据的动态时间规整 an example;您可能会发现它很有用!

    【讨论】:

      【解决方案2】:

      动态时间扭曲计算两个时间序列之间的距离。您存储一个模板进行比较,并使用实际移动作为候选。如果您使用所有通道,您将拥有三个不同的时间序列和距离。如果累计距离低于特定阈值,则该移动将被标记为已识别。困难的部分是你有连续的时间序列。很难发现手势。尽管如此,该算法还是找到了两个时间序列之间的最佳对齐方式。

      onSensorChanged 方法为您提供时间序列的单个点。所以你必须建立一个先进先出(FIFO)数据结构(例如一个队列)来存储最后一秒的所有变化。

      也许 FastDTW 库有帮助:https://code.google.com/archive/p/fastdtw/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-07
        • 2020-01-31
        • 2013-09-24
        • 2013-02-01
        • 2021-06-14
        • 2022-12-29
        相关资源
        最近更新 更多