Esempio n. 1
0
def global_motion_estimate(flow, visualize_flow=False):
    # flow = fl2.read_flow(flow_path)
    # flow = np.load(flow_path).astype(np.float32)

    if visualize_flow:
        fl.visualize_flow(flow)

    max_rad = fl2.compute_maxrad(flow)
    # # 每一列的均值
    # horizen_mean = np.mean(flow[5:-5, 5:-5, 0], axis=0)
    # # 每一行的均值
    # vertical_mean = np.mean(flow[2:-2, 2:-2, 1], axis=1)

    # # 第一列
    # first_column = flow[5:-5, 5:6, 0]
    # m = outlier_filter(first_column)
    # # 最后一列
    # last_column = flow[5:-5, -6:-5, 0]

    # # 第一列的均值
    # x1 = horizen_mean[0]
    # # 最后一列的均值
    # x2 = horizen_mean[-1]
    # # 最后一列的均值
    # y1 = vertical_mean[0]
    # # 最后一列的均值
    # y2 = vertical_mean[-1]

    start = time.time()
    # 第一列的均值
    x1 = float(outlier_filter(flow[5:-5, 5:6, 0]))
    # 最后一列的均值
    x2 = float(outlier_filter(flow[5:-5, -6:-5, 0]))
    # 第一行的均值
    y1 = float(outlier_filter(flow[5:6, 5:-5, 1]))
    # 最后一行的均值
    y2 = float(outlier_filter(flow[-6:-5, 5:-5, 1]))
    end = time.time()
    print('time:{}'.format(end - start))

    # 初始化一个和光流图一样size的空矩阵
    flow_global = np.zeros((flow.shape[0], flow.shape[1], 2))

    # 基于x1~xw 线性插值生成一行
    x_direction = np.linspace(x1, x2, flow.shape[1]).reshape(1, -1)
    # x_direction = np.arange(x1, x2, (x2 - x1) / flow.shape[1]).reshape(1, -1)[:, 0:flow.shape[1]]
    # 基于y1~yh 线性插值生成一列
    # y_direction = np.arange(y1, y2, (y2 - y1) / flow.shape[0]).reshape(-1, 1)[0:flow.shape[0], :]
    y_direction = np.linspace(y1, y2, flow.shape[0]).reshape(-1, 1)

    # x方向幅值行向量纵向复制h次
    x_mat = np.repeat(x_direction, flow.shape[0], axis=0)
    # y方向幅值列向量横向复制w次
    y_mat = np.repeat(y_direction, flow.shape[1], axis=1)
    flow_global[:, :, 0] = x_mat
    flow_global[:, :, 1] = y_mat

    return flow_global, max_rad
                        data_org[1])
    print('epe: {}'.format(epe))

    local_motion = data_org - global_motion

    local_motion_outlier = local_motion * outlier_set

    flo_global_color = fl2.flow_to_image(global_motion, maxrad)
    flo_local_color = fl2.flow_to_image(local_motion, maxrad)

    local_motion_outlier_rad = np.sqrt(local_motion_outlier[:, :, 0]**2 +
                                       local_motion_outlier[:, :, 1]**2)
    local_motion_outlier_mask = np.where(
        np.abs(local_motion_outlier_rad) > 1.0, 1, 0)

    local_motion_outlier[:, :, 0] *= local_motion_outlier_mask
    local_motion_outlier[:, :, 1] *= local_motion_outlier_mask

    flo_local_outlier_color = fl2.flow_to_image(local_motion_outlier, maxrad)

    fl.visualize_flow(data_org)

    plt.imshow(flo_global_color)
    plt.show()

    plt.imshow(flo_local_color)
    plt.show()

    plt.imshow(flo_local_outlier_color)
    plt.show()
Esempio n. 3
0
#! /usr/bin/python
# Author: Ruoteng Li
# Date: 6th Aug 2016
"""
Demo.py
This file demonstrates how to use kittitool module to read
 and visualize flow file saved in kitti format .png
"""
from lib import flowlib as fl

# read kitti format optical flow file (.png)
print("Visualizing KITTI flow example ...")
flow_file_KITTI = 'data/example/KITTI/flow_gt.png'
flow_KITTI = fl.read_flow(flow_file_KITTI)
fl.visualize_flow(flow_KITTI)

# read Middlebury format optical flow file (.flo)
print("Visualizing Middlebury flow example ...")
flow_file_Middlebury = 'data/example/Middlebury/flow_gt.flo'
flow_Middlebury = fl.read_flow(flow_file_Middlebury)
fl.visualize_flow(flow_Middlebury)
Esempio n. 4
0
#! /usr/bin/python
# Author: Ruoteng Li
# Date: 6th Aug 2016
"""
Demo.py
This file demonstrates how to use kittitool module to read
 and visualize flow file saved in kitti format .png
"""
from lib import flowlib as fl

for i in range(4999, 5000):
    # read Middlebury format optical flow file (.flo)
    print "Visualizing Middlebury flow example ..."
    flow_file_Middlebury = ('./data/ChairsSDHom/data/train1/flow/00003.flo')
    flow_Middlebury = fl.read_flow(flow_file_Middlebury)
    fl.visualize_flow(flow_Middlebury)

    print "Visualizing Middlebury flow example ..."
    flow_file_Middlebury1 = ('flownetc-pred-000%d.flo' % i)
    flow_Middlebury1 = fl.read_flow(flow_file_Middlebury1)
    fl.visualize_flow(flow_Middlebury1)
Esempio n. 5
0
    # local motion further refinement (optional) stage_1
    local_motion_outlier[:, :, 0] *= local_motion_outlier_mask
    local_motion_outlier[:, :, 1] *= local_motion_outlier_mask

    # logo area suppress stage_2
    frame = 0
    window = 10
    temporal_threshold = 2.0                    # 2.0
    # data_path = r'E:/project/capstone/main/shoudong_keyframe/keyframe_data/flo_data/nba/3-pointer-failure/5/'
    data_path = r'D:/code/OpticalFlow/data_ncaa/3d6tdmTyfhQ/layup-failure/2722569.786'
    data_list_stg2 = glob.glob(data_path + '/*.npy')[0: window]
    logo_mat = np.zeros((data_org.shape[0], data_org.shape[1]))
    for data_stg2_path in data_list_stg2:
        frame += 1
        mix_data_stg2 = np.load(data_stg2_path).astype(np.float32)
        fl.visualize_flow(mix_data_stg2)
        mix_motion_rad = np.sqrt(mix_data_stg2[:, :, 0] ** 2 + mix_data_stg2[:, :, 1] ** 2)
        logo_mat += mix_motion_rad
    logo_mat /= frame
    logo_outlier_mask = np.where(np.abs(logo_mat) > temporal_threshold, 1, 0)

    # local motion further refinement (optional) stage_2
    local_motion_outlier[:, :, 0] *= logo_outlier_mask
    local_motion_outlier[:, :, 1] *= logo_outlier_mask

    flo_local_outlier_color = fl2.flow_to_image(local_motion_outlier, maxrad)

    # fl.visualize_flow(data_org)

    # plt.imshow(flo_global_color)
    # plt.show()
Esempio n. 6
0
#! /usr/bin/python
# Author: Ruoteng Li
# Date: 6th Aug 2016
"""
Demo.py
This file demonstrates how to use kittitool module to read
 and visualize flow file saved in kitti format .png
"""
from lib import flowlib as fl

flow_file = 'data/example/flow_gt.png'
flow = fl.read_flow_png(flow_file)
fl.visualize_flow(flow, 'RGB')
Esempio n. 7
0
print("Visualizing KITTI flow example ...")
flow_file_KITTI = './data/example/KITTI/flow-000000_10.flo'
flow_KITTI = fl.read_flow(flow_file_KITTI)

flow = cv2.imread(flow_file_KITTI)

#print(flow[:,:,2])

#
# invalid_idx = (flow[:, :, 0] == 0)
#
# flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
# flow[invalid_idx, 2] = 0
# flow[invalid_idx, 1] = 0
#
# img = np.zeros((256, 512, 2))
#
# img[:,:,0]=flow[:,:,2]
# img[:,:,1]=flow[:,:,1]
#
# print(flow.shape)
#
# #fl.visualize_flow(img)
fl.visualize_flow(flow_KITTI)

# read Middlebury format optical flow file (.flo)
#print ("Visualizing Middlebury flow example ...")
# flow_file_Middlebury = 'data/example/Middlebury/flow_gt.flo'
# flow_Middlebury = fl.read_flow(flow_file_Middlebury)
# fl.visualize_flow(flow_Middlebury)
Esempio n. 8
0
    # net = NetB(64, 128, 128, 64)

    # 训练好的模型路径
    net.load_state_dict(torch.load(r'D:/code/yz_job/code/model/netA_modelB.pkl'))
    net.eval()
    net.to(device)

    loss_list = []
    path = r'D:\code\yz_job\code\optical_flow\6.npy'

    data_flow = np.load(path).astype(np.float32)
    u = data_flow[:, :, 0]
    v = data_flow[:, :, 1]
    rad = np.sqrt(u ** 2 + v ** 2)  # 光流场方向
    maxrad = max(-1, np.max(rad))
    fl.visualize_flow(data_flow)
    data_flow = cv2.resize(data_flow, dsize=(64, 64), interpolation=cv2.INTER_LINEAR)

    flow_x = data_flow[:, :, 0].squeeze()
    flow_y = data_flow[:, :, 1].squeeze()

    flow_x_vis = cv2.resize(vis_RGB(flow_x, np.min(flow_x), np.max(flow_x)), dsize=(300, 200), interpolation=cv2.INTER_LINEAR)
    flow_y_vis = cv2.resize(vis_RGB(flow_y, np.min(flow_y), np.max(flow_y)), dsize=(300, 200),
                            interpolation=cv2.INTER_LINEAR)

    # cv2.imshow("name", flow_x_vis)
    # cv2.waitKey(0)
    #
    # cv2.imshow("name", flow_y_vis)
    # cv2.waitKey(0)
Esempio n. 9
0
    name = name.split('.')[0]

    pred_flow_names.append(name)

sum_AEE = []
count = 0
for pred_name in pred_flow_names:

    for gt_path in gt_paths:

        if (pred_name in gt_path) and (pred_name != 'Venus'):

            count += 1
            print(pred_name)

            pred_flow = fl.read_flow(pred_flow_dir + '_' + pred_name + '.flo')
            gt_flow = fl.read_flow(gt_path)

            fl.visualize_flow(pred_flow)
            fl.visualize_flow(gt_flow)

            res = fl.evaluate_flow(gt_flow, pred_flow)
            sum_AEE.append(res)

            print('running file, aee is {}'.format(res))

AEE = np.mean(sum_AEE)

print('the averge error is {}'.format(AEE))
print(count)
Esempio n. 10
0
#! /usr/bin/python
# Author: Ruoteng Li
# Date: 6th Aug 2016
"""
Demo.py
This file demonstrates how to use kittitool module to read
 and visualize flow file saved in kitti format .png
"""
from lib import flowlib as fl

# read kitti format optical flow file (.png)
print "Visualizing KITTI flow example ..."
flow_file_KITTI = 'data/example/KITTI/flow_gt.png'
flow_KITTI = fl.read_flow_png(flow_file_KITTI)
fl.visualize_flow(flow_KITTI, 'Y')  # 'RGB' for Ycbcr color mode

# read Middlebury format optical flow file (.flo)
print "Visualizing Middlebury flow example ..."
flow_file_Middlebury = 'data/example/Middlebury/flow_gt.flo'
flow_Middlebury = fl.read_flow(flow_file_Middlebury)
fl.visualize_flow(flow_Middlebury)
Esempio n. 11
0
#! /usr/bin/python
# Author: Ruoteng Li
# Date: 6th Aug 2016
"""
Demo.py
This file demonstrates how to use kittitool module to read
 and visualize flow file saved in kitti format .png
"""
from lib import flowlib as fl

print("Visualizing driving dataset ...")
flow_file_drive = 'data/example/driving/0401.pfm'
flow_file_drive = fl.read_flow(flow_file_drive)
fl.visualize_flow(flow_file_drive)

# # read kitti format optical flow file (.png)
# print("Visualizing KITTI flow example ...")
# flow_file_KITTI = 'data/example/KITTI/flow_gt.png'
# flow_KITTI = fl.read_flow(flow_file_KITTI)
# fl.visualize_flow(flow_KITTI)

# # read Middlebury format optical flow file (.flo)
# print("Visualizing Middlebury flow example ...")
# flow_file_Middlebury = 'data/example/Middlebury/flow_gt.flo'
# flow_Middlebury = fl.read_flow(flow_file_Middlebury)
# fl.visualize_flow(flow_Middlebury)