寻求分类3D移动数据的建议

时间:2017-09-06 16:20:44

标签: python numpy scipy accelerometer gyroscope

项目

我正在开展一个项目,他的最终目标是根据3D(加速度计和陀螺仪)运动的读数(位移,速度,加速度和加速度)对智能手机上的用户输入/行为进行分类)以及2D交互(速度,加速度,"触摸和#34等的数量)。我的分类器必须输出用户是否参与/沮丧/可能受到此paper影响的其他情绪。但是,这一步并非必要。

数据

智能手机会生成JSON文件,包括手机在x,y和z方面的位置以及时间戳。每隔20毫秒就有一个新的时间戳。

到目前为止,我已经完成了一些Python教程并在底部生成了代码。我被建议使用NumPy和SciPy让我的生活更轻松。除了明显的运动学,我需要包括一个过滤过程。谷歌推荐卡尔曼过滤器。

问题

如果有人有这方面的经验,他们是否可以推荐一种方法,也许你已经遇到过类似项目的方法很好。

import sqlalchemy
import json
import ReferenceFrame, get_motion_params, dynamicsymbols, symbols

con = sqlalchemy.create_engine('postgresql+psycopg2://postgres:@localhost/airlib')
meta = sqlalchemy.MetaData(bind=con, reflect=True)


dataObjects = []
dataAccObjects = []
dataGyroObjects = []

displacementChangeInX = []
displacementChangeInY = []
displacementChangeInZ = []


t = []  #time
v = []  #velocity
a = []  #acceleration
j = []  #jerk


results = meta.tables['rawmobiledata']


class DataEntry(object):
    item = 0
    time = 0
    x = 0
    y = 0
    z = 0

def __init__(self, item, time, x, y, z):
    self.item = item
    self.time = time
    self.x = x
    self.y = y
    self.z = z



def make_accelerometerEntry(item, time, x, y, z):
    dataAcc = DataEntry(item ,time, x, y, z)
    #print str(dataAccObjects)
    return dataAcc

def make_gyroEntry(item, time, x, y, z):
    dataGyro = DataEntry(item, time, x, y, z)
    #print str(dataGyroObjects)
    return dataGyro



for row in con.execute(results.select()):
        r = row[1]
        r = json.dumps(r)
        loaded_r = json.loads(r)
        #print(loaded_r)

        if loaded_r['sensor'] == 'accelerometer':
            for item in range(0, 250):
                time = loaded_r['data'][item]['time']
                x = loaded_r['data'][item]['x']
                y = loaded_r['data'][item]['y']
                z = loaded_r['data'][item]['z']
                dataAccObjects.append(make_accelerometerEntry(item, time, x, y, z))
                #print "this is an accelerometerObj"
        elif loaded_r['sensor'] == 'gyroscope':
            for item in range(0, 250):
                time = loaded_r['data'][item]['time']
                x = loaded_r['data'][item]['x']
                y = loaded_r['data'][item]['y']
                z = loaded_r['data'][item]['z']
                dataGyroObjects.append(make_gyroEntry(item, time, x, y, z))
                #print "gyroObj with time " + str(time) + ", reading " + str(item+1) + "/250, test#" + str((row[0]/2)+1)

for row in con.execute(results.select()):
        r = row[1]
        r = json.dumps(r)
        loaded_r = json.loads(r)
        if loaded_r['sensor'] == 'gyroscope':
            for item in range (0,250):
                #rate of change
                # ti = |t2-t1|
                t[item] = abs(int(dataGyroObjects[item].time) - int(dataGyroObjects[item+1].time))
                #calculate change in displacement over the 3 axes
                displacementChangeInX[item] = abs(int(dataGyroObjects[item].x) - int(dataGyroObjects[item+1].x))
                displacementChangeInY[item] = abs(int(dataGyroObjects[item].y) - int(dataGyroObjects[item+1].y))
                displacementChangeInZ[item] = abs(int(dataGyroObjects[item].z) - int(dataGyroObjects[item+1].z))
                # v = dx/dt
                v[item] = abs(t[item] - 0)

                #calculate acceleration
                # a = dv/dx

                #calculate jerk
                # j = da/dt

0 个答案:

没有答案