将方向存储到数组 - 并进行比较 [英] Store orientation to an array - and compare

查看:33
本文介绍了将方向存储到数组 - 并进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现以下目标:

我希望用户能够使用陀螺仪记录"iPhone 的运动.之后,用户应该能够复制相同的动作.我使用以下方法提取俯仰、滚转和偏航:

 [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]withHandler: ^(CMDeviceMotion *motion, NSError *error){CMAttitude *attitude = motion.attitude;NSLog(@"pitch:%f,roll:%f,yaw:%f]",attitude.pitch,attitude.roll,attitude.yaw);}];

我在想,如果用户处于记录模式,我可以将这些值存储到一个数组中.当用户尝试复制该运动时,我可以将复制的运动阵列与记录的运动阵列进行比较.问题是,我怎样才能巧妙地比较这两个数组?它们永远不会有完全相同的值,但它们可能有些相同.

我在这里的方向是否正确?

更新:我认为 Alis 关于使用 DTW 的回答可能是我在这里的正确方法.但我并不那么聪明(显然),所以如果有人能帮助我完成与数组比较的第一步,我会是一个快乐的人!

谢谢!

解决方案

尝试动态时间扭曲.这是一维数组的说明性示例.在数据库中,我们已经有以下 2 个数组:

数组 1:[5, 3, 1]
数组 2:[1, 3, 5, 8, 8]

我们测量了 [2, 4, 6, 7].哪个阵列与新测量的最相似?显然,第二个数组与新测量的相似,第一个则不是.

让我们根据,第 363 页,第 5 页.边界条件和第 364 页.上面链接的论文也有更多详细信息.

我刚刚注意到您使用了偏航、俯仰和滚转.简单地说:不要a> 和另一个不这样做的理由.您可以使用加速度计数据吗?加速度计是方向的直接测量"(来自 DCM 手稿)和是你所需要的.至于 tc 的问题,相对于北的方向重要吗?我想不会.

正如 tc 指出的那样,比较加速度向量比方向(欧拉角、旋转矩阵、四元数)容易得多.如果您使用加速度数据,则每个时间点都有 3 维向量,即 (x,y,z) 坐标.我会简单地计算

Dist(i,j)=SQRT((A[i][X]-B[j][X])^2+(A[i][Y]-B[j][Y]])^2+(A[i][Z]-B[j][Z])^2),

即两点之间的欧氏距离.

I want to achieve the following:

I want the user to be able to "record" the movement of the iPhone using the gyroscope. And after that, the user should be able to replicate the same movement. I extract the pitch, roll and yaw using:

 [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
                                       withHandler: ^(CMDeviceMotion *motion, NSError *error)
     {
         CMAttitude *attitude = motion.attitude;
         NSLog(@"pitch: %f, roll: %f, yaw: %f]", attitude.pitch, attitude.roll, attitude.yaw);
     }];

I'm thinking that I could store these values into an array, if the user is in record mode. And when the user tries to replicate that movement, I'm could compare the replicated movement array to the recorded one. The thing is, how can I compare the two arrays in a smart way? They will never have exactly the same values, but they can be somewhat the same.

Am I at all on the right track here?

UPDATE: I think that maybe Alis answer about using DTW could be the right way for me here. But I'm not that smart (apparently), so if anyone could help me out with the first steps with comparing to arrays I would be a happy man!

Thanks!

解决方案

Try dynamic time warping. Here is an illustrative example with 1D arrays. In the database we already have the following 2 arrays:

Array 1: [5, 3, 1]
Array 2: [1, 3, 5, 8, 8]

We measured [2, 4, 6, 7]. Which array is the most similar to the newly measured? Obviously, the second array is similar to the newly measured and the first is not.

Let's compute the cost matrices according to this paper, subsection 2.1:

D(i,j)=Dist(i,j)+MIN(D(i-1,j),D(i,j-1),D(i-1,j-1))

Here D(i,j) is the (i,j) element of the cost matrix, see below. Check Figure 3 of that paper to see this recurrence relation is applied. In short: columns are computed first, starting from D(1,1); D(0,*) and D(*,0) are left out in the MIN. If we are comparing arrays A and B then Dist(i,j) is the distance between A[i] and B[j]. I simply used ABS(A[i]-B[j]). The cost matrices for this example:

For Array 1 we have 13 as score, for Array 2 we have 5. The lower score wins, so the most similar array is Array 2. The best warping path is marked gray.

This is only a sketch of DTW. There are a number of issues you have to address in a real-world application. For example using offset instead of fixed ending points, or defining measures of fit: see this paper, page 363, 5. boundary conditions and page 364. The above linked paper has further details too.

I just noticed you are using yaw, pitch and roll. Simply put: don't and another reason not to. Can you use the accelerometer data instead? "An accelerometer is a direct measurement of orientation" (from the DCM manuscript) and that is what you need. And as for tc's question, does the orientation relative to North matter? I guess not.

It is far easier to compare the acceleration vectors than orientations (Euler angles, rotation matrices, quaternions) as tc pointed that out. If you are using acceleration data, you have 3 dimensional vectors at each time point, the (x,y,z) coordinates. I would simply compute

Dist(i,j)=SQRT((A[i][X]-B[j][X])^2+(A[i][Y]-B[j][Y])^2+(A[i][Z]-B[j][Z])^2),

that is the Eucledian distance between the two points.

这篇关于将方向存储到数组 - 并进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆