3D手势识别(二)左右、上下滑动判断

场景:前装摄像头。

检测目标:检测手左右滑动状态,手沿x方向滑动,z轴为深度方向,y、z方向相对稳定。

                    手上下滑动类似。

步骤:

一、图像识别检测手,左右滑取最上点/上下滑取得手的最前点;

二、数据处理:中值滤波、平滑处理和卡尔曼滤波;

三、判断x方向角速度/速度是否超过阈值范围,检测移动方向;

四、判断y方向移动速度是否超过阈值。


部分算法如下:

检测某方向速度是否超过阈值范围,判断移动方向

/************************************
 Description: 用时间1的位置1与时间0的位置0得到速度与阈值比较
 Method:    CheckLeftRight
 FullName:  CheckLeftRight
 Access:    private
 Parameter: 时间1:const TimeStamp &t1
 Parameter: 位置1:float f1
 Parameter: 时间0:const TimeStamp &t0
 Parameter: 位置0:float f0
 Parameter: 速度阈值:thresh
 Parameter: 标签名:输出日志用 const std::string &label_name
 Returns:   int 0表示小于阈值,1/-1表示方向
 Author:    
 Date:      2018/08/30
 History:
************************************/
int CheckLeftRight(const TimeStamp &t1, float f1, const TimeStamp &t0,
                                            float f0, float thresh, const std::string &label_name) {
        float vt = ComputeVelocity(t1, f1, t0, f0);      
        int sliding_state = CheckVelocity(vt, -thresh, thresh);      
        return sliding_state;
    }
//计算速度
float ComputeVelocity(const TimeStamp &t1, float f1, const TimeStamp &t0, float f0) {
    double dt = (t1 - t0).toSec();
    double delta_f = f1 - f0;
    double v = delta_f / dt;
    return static_cast<float>(v);
}
//判断
int CheckVelocity(double v, float thresh_low, float thresh_high) {
    if (v > thresh_high) {
        return 1;
    }
    if (v < thresh_low) {
        return -1;
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章