计算连续帧中两个2d坐标之间的实际速度

问题描述 投票:1回答:1

我正在尝试基于从2D坐标的两个点的像素偏移来计算帧之间的实际速度。

co_ordinates[frame_number][pixel_index][pixel_value_x][pixel_value_y]的方式存储坐标>

例如,这是frame_number=1时显示pixel_index=1co_ordinates[0][0]的方式>

array([[113.        , 231.        ],
       [112.83630458, 230.73530376]])

这里是尝试

import math

def calc(image_dim , real_Dim , Point):
    return (Point[0] * real_Dim[0]/image_dim[0], Point[1] * real_Dim[1]/image_dim[1])

image_dim = (320,240) # dimension of image (width x height)
real_Dim = (1,0.9) # real dimension of image in mm (width x height)

number_of_frames = 120 # Total number of frames
number_of_points =58 # Number of co-ordinates where readings are taken in an image
video_speed = []

for frame_number in range(0,number_of_frames): # loop over all frames
    frame_speed = []

    for point_number in range(0, number_of_points): # calculate speed per pixel_index per frame

        Point_one = calc(image_dim, real_Dim, (co_ordinates[frame_number][point_number][0][0], 
                                               co_ordinates[frame_number][point_number][1][0]))

        Point_two = calc(image_dim, real_Dim, (co_ordinates[frame_number][point_number][0][1], 
                                               co_ordinates[frame_number][point_number][1][1]))

        distance = math.sqrt((Point_one[0]-Point_two[0])**2 + (Point_one[1]-Point_two[1])**2)
        time = 0.05 # Time between frames


        frame_speed.append(distance / time)

    video_speed.append(np.mean(frame_speed)) # calculate mean speed of frame

如何正确计算mm/s中各帧之间的实际速度?

如果正确,是否有进一步优化的方法?

EXTRAS:

出于测试目的,这是来自坐标的6帧的输出

[array([[[ 50.        ,  50.        ],
        [ 49.89107906,  50.01721625]],

       [[150.        ,  50.        ],
        [149.98240056,  50.01998935]],

       [[250.        ,  50.        ],
        [249.64290327,  51.01493382]],

       [[ 50.        , 150.        ],
        [ 49.92744978, 150.02948231]],

       [[150.        , 150.        ],
        [149.64272794, 149.82678588]],

       [[250.        , 150.        ],
        [250.00543924, 150.0026971 ]]]), 

array([[[ 50.        ,  50.        ],
            [ 50.03984383,  49.97097593]],

       [[150.        ,  50.        ],
        [150.01179785,  49.99240989]],

       [[250.        ,  50.        ],
        [250.23686095,  48.90773654]],

       [[ 50.        , 150.        ],
        [ 50.10918073, 151.85269225]],

       [[150.        , 150.        ],
        [150.19248188, 149.56399652]],

       [[250.        , 150.        ],
        [249.99657853, 150.00377174]]]), 

array([[[ 50.        ,  50.        ],
            [ 50.02103496,  50.0230453 ]],

       [[150.        ,  50.        ],
        [149.9971778 ,  50.00171494]],

       [[250.        ,  50.        ],
        [249.97102118,  49.13421589]],

       [[ 50.        , 150.        ],
        [ 50.00297619, 148.87509906]],

       [[150.        , 150.        ],
        [150.31536585, 148.69849575]],

       [[250.        , 150.        ],
        [249.99691853, 149.99868659]]]), 

array([[[ 50.        ,  50.        ],
            [ 50.00037101,  50.00599535]],

       [[150.        ,  50.        ],
        [149.99339349,  50.00473171]],

       [[250.        ,  50.        ],
        [249.67023763,  50.2115393 ]],

       [[ 50.        , 150.        ],
        [ 49.95433414, 150.75595504]],

       [[150.        , 150.        ],
        [149.54204383, 146.9134376 ]],

       [[250.        , 150.        ],
        [250.00658676, 150.00301765]]]), 

array([[[ 50.        ,  50.        ],
            [ 50.00842951,  49.97589724]],

       [[150.        ,  50.        ],
        [149.9824532 ,  50.00823016]],

       [[250.        ,  50.        ],
        [250.59972095,  50.823488  ]],

       [[ 50.        , 150.        ],
        [ 49.94134316, 148.85299742]],

       [[150.        , 150.        ],
        [150.69609386, 155.63426733]],

       [[250.        , 150.        ],
        [249.99170064, 150.00060952]]])]

我正在尝试基于从2D坐标的两个点的像素偏移来计算帧之间的实际速度。以以下方式存储坐标:co_ordinates [frame_number] [...

python image math image-processing
1个回答
0
投票

您的代码应按原样工作。您可能需要首先计算帧点云重心的坐标,然后从that

推断帧速度。这样更快,并具有稍微减少错误传播的优点:
© www.soinside.com 2019 - 2024. All rights reserved.