Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何计算一个物体的旋转次数,该物体从它开始作伪圆周运动';s坐标(t,X,Y)_Python_Algorithm_Periodicity - Fatal编程技术网

Python 如何计算一个物体的旋转次数,该物体从它开始作伪圆周运动';s坐标(t,X,Y)

Python 如何计算一个物体的旋转次数,该物体从它开始作伪圆周运动';s坐标(t,X,Y),python,algorithm,periodicity,Python,Algorithm,Periodicity,所以我有一个对象,它有一个伪圆环运动(编辑:具有一个非常数周期)。我用每秒30帧的相机拍摄,每3帧提取一次X和Y的位置。而且,这个圆周运动的中心在移动 输入数据: 框架,列表 X和Y,2个列表 对于帧[i],对象的位置是X[i]和Y[i] 如果您想看看它的样子(3000万视频): 此外,我的数据有“间隙”,有时,我可以从第600帧到第690帧,因为在我的视频中没有正确检测到对象。数据已经使用一阶低通滤波器进行了滤波(经过分段插值后) 我的问题是,在没有太多变化的情况下,我找不到一个好的算法

所以我有一个对象,它有一个伪圆环运动(编辑:具有一个非常数周期)。我用每秒30帧的相机拍摄,每3帧提取一次X和Y的位置。而且,这个圆周运动的中心在移动

输入数据:

  • 框架,列表
  • X和Y,2个列表
对于帧[i],对象的位置是X[i]和Y[i]

如果您想看看它的样子(3000万视频):

此外,我的数据有“间隙”,有时,我可以从第600帧到第690帧,因为在我的视频中没有正确检测到对象。数据已经使用一阶低通滤波器进行了滤波(经过分段插值后)

我的问题是,在没有太多变化的情况下,我找不到一个好的算法来计算旋转次数。

使用X和Y的伪周期的当前算法:

for length = 200, 400, 600, 800, 1000 and 1200 :
    I cut my data (X and Y) in segments of size : length.
    for each segments cutted :
        Mean_X = Mean value of X on the segment
        Mean_Y = Mean value of Y on the segment

        If I get above Mean_X, X_counter += 1, and then I skip the following points until I get under Mean_X.
        Same with Y_counter.

    I sum the counted number of rotation on each segments for the current length to get the number of rotation on the complete duration.

In 2 list, ResX and ResY, I store the counted number of rotation for every length. To resX[i] correspond the length i. 
For instance resX[2] give the number counted for length : 600.

But the results on X and Y are different, and have an high variability depending of the length chosen.
So how to choose the real number of rotation on the duration ? 

Calculation of the difference of counted number between X and Y for every length.

Then I choose the average of counted X and Y, where there is the smaller difference. 
在Python中:

    # Découpage en segment de 200 à 1200 de longueur avec un pas de 200
    Segments = range(200, 1400, 200)

    ResX, ResY = [], []

    for k in range(len(Segments)):
        if Segments[k] < len(X):
            X_calc, Y_calc = [], []
            length = len(X) // Segments[k]
            last = len(X) % Segments[k]

            for j in range(length):
                X_calc.append(X[j:j + Segments[k]])
                Y_calc.append(Y[j:j + Segments[k]])

            if last > Segments[k] //2:
                X_calc.append(X[len(X) - last:])
                Y_calc.append(Y[len(Y) - last:])

            else:
                X_calc[len(X_calc) - 1] = X_calc[len(X_calc) - 1] + X[len(X) - last:]
                Y_calc[len(Y_calc) - 1] = Y_calc[len(Y_calc) - 1] + Y[len(Y) - last:]

            # Initialisation of the counter
            Kx = 0
            Ky = 0

            for j in range(len(X_calc)):

                Counter = 0
                b = 0
                Moyenne = np.mean(X_calc[j])
                while b < len(X_calc[j]):
                    if X_calc[j][b] <= Moyenne + 10:
                        b += 1
                        continue
                    else:
                        Counter += 1
                        while X_calc[j][b] >= Moyenne + 10:
                            b += 1
                            try:
                                X_calc[j][b]
                            except:
                                break
                Kx += Counter

                Counter = 0
                b = 0
                Moyenne = np.mean(Y_calc[j])
                while b < len(Y_calc[j]):
                    if Y_calc[j][b] <= Moyenne + 10:
                        b += 1
                        continue
                    else:
                        Counter += 1
                        while Y_calc[j][b] >= Moyenne + 10:
                            b += 1
                            try:
                                Y_calc[j][b]
                            except:
                                break

                Ky += Counter

            ResX.append(Kx)
            ResY.append(Ky)

    # Maintenant on détermine le nombre de tour en comparant les résultats locaux en X et en Y
    Diff = []

    for j in range(len(ResX)):
        Diff.append(abs(ResX[j] - ResY[j]))

    ID = Diff.index(min(Diff))

    Res_F = int((ResX[ID] + ResY[ID]) /2)
#200至1200米长的路段与200米长的路段连接
分段=范围(200、1400、200)
ResX,ResY=[],[]
对于范围内的k(长度(段)):
如果段[k]Segments[k]//2:
X_计算附加(X[len(X)-last:]
Y_计算附加(Y[len(Y)-last:)
其他:
X_calc[len(X_calc)-1]=X_calc[len(X_calc)-1]+X[len(X)-last:]
Y_calc[len(Y_calc)-1]=Y_calc[len(Y_calc)-1]+Y[len(Y)-last:]
#计数器的初始化
Kx=0
Ky=0
对于范围内的j(len(X_计算)):
计数器=0
b=0
Moyenne=np.平均值(X_calc[j])
而b
此当前解决方案具有很高的可变性,具体取决于:

  • 长度
  • “高于数值的计数”:如果我取平均值(X)或平均值(X)+10,我会得到完全不同的结果
您知道如何减少这种变化吗?还是一个计算旋转的算法?还是在计数前将X和Y组合起来的方法?


因为(t=0,X=1,Y=0)的旋转可以用X=cos(t)和Y=sin(t)来描述,所以我认为有一种方法可以将X和Y相加或相乘,以便分析X和Y的线性组合。

研究X和Y的傅里叶表示,并尝试使公式适应非均匀时间步长,可能会有所帮助。如果计算这些值的DFT,周期应为局部最大im相空间。编辑:我所描述的被称为,但不管怎样,这假设你已经知道周期的倍数(两个不同的时间,当对象处于相同的旋转状态),我假设你不是这样。问题不是我找不到这个周期,而是它不是常数。我的“目标”是一只老鼠,当它决定休息一下时,没什么可做的。。。此外,这种药物诱导的成分试验是在40只小鼠上进行的,它们的反应方式不同。有些我们将以10 rpm的恒定周期旋转,有些甚至不会移动,我们可能会在2或3分钟内旋转一或两圈。我目前的解决方案似乎给出了更好的结果,就是计算X和Y的和的局部最大值(基本上与上面的算法相同,但使用和)。不完美,我希望有人能想出更好的主意。为什么不从
x,y
函数中减去滑动平均值呢。。。这将围绕实际旋转中心“居中”坐标。由此可以计算零角交叉(
x
接近最大值,
y
接近零)