コード例 #1
0
ファイル: ucf101_flo.py プロジェクト: wzmsltw/P3D-CTN
  def clip_reader(self, video_prefix):
    """Load frames in the clip.

    Using openCV to load the clip frame by frame.
    If specify the cropped size (crop_size > 0), randomly crop the clip.

      Args:
        index: Index of a video in the dataset.

      Returns:
        clip: A matrix (channel x depth x height x width) saves the pixels.
      """
    clip = []
    r1 = 0
    framepath = os.path.join('/data/wjc/caffe_act1/data/UCF101', 'Flownet2_flow', video_prefix)
    num_frames = len(glob.glob(framepath + '/*.flo'))
    for i in xrange(num_frames):
      filename = os.path.join(
          '/data/wjc/caffe_act1/data/UCF101', 'Flownet2_flow', video_prefix,
          '%05d.flo' % (i + 1))
#      print (filename)

      im = fl.read_flow(filename)
      im[:,:,0]=(im[:,:,0]-np.min(im[:,:,0]))/(np.max(im[:,:,0])-np.min(im[:,:,0]))
      im[:,:,1]=(im[:,:,1]-np.min(im[:,:,1]))/(np.max(im[:,:,1])-np.min(im[:,:,1]))
      im = im * 255
#      im = cv2.imread(filename)
      if r1 == 0:
        r1 = self._height / im.shape[0]
        r2 = self._width / im.shape[1]
 #     im = cv2.resize(im, None, None, fx=r2, fy=r1,
 #                     interpolation=cv2.INTER_LINEAR)
      clip.append(im)
    return [r1, r2], np.asarray(clip, dtype=np.uint8)
コード例 #2
0
gt_number = count_text_lines(gt_flow_txt)
gt_paths = read_path(gt_flow_txt)

pred_number = count_text_lines(pred_flow_txt)
pred_paths = read_path(pred_flow_txt)

print(gt_number)
print(pred_number)

sum_AEE = []
count = 0
for i in range(gt_number):


    pred_flow = fl.read_flow(pred_paths[i])

    gt_flow = fl.read_flow(gt_paths[i])

    res = fl.evaluate_flow(gt_flow, pred_flow)

    # sum_AEE.append(res)
    # count += 1

    if res < 50:
        sum_AEE.append(res)
        count += 1

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

AEE = np.mean(sum_AEE)
コード例 #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)
コード例 #4
0
ファイル: demo.py プロジェクト: Mehuli-Ruh11/Flownet_v1
#! /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)
コード例 #5
0
if not os.path.exists(output_dir):
    os.mkdir(output_dir)
img1_input = f1.readlines()
img2_input = f2.readlines()
flow_input = f.readlines()

# Generate
for i in range(length):
    x_locations = np.random.randint(0, canvas_width - patch_width, size=10)
    y_locations = np.random.randint(0, canvas_height - patch_height, size=10)
    img1 = Image.open(img1_input[i].strip())
    img2 = Image.open(img2_input[i].strip())
    if flow_input[i].strip().find('.png') != -1:
        flow = kittitool.flow_read(flow_input[i].strip())
    else:
        flow = fl.read_flow(flow_input[i].strip())
    for (x, y) in zip(x_locations, y_locations):
        patch_img1 = img1.crop((x, y, x+patch_width, y+patch_height))
        patch_img2 = img2.crop((x, y, x+patch_width, y+patch_height))
        patch_flow = flow[y:y+patch_height, x:x+patch_width]
        filename = str.format('%05d_' % i) + str(x) + '_' + str(y)
        path1 = os.path.join(output_dir, filename + '_img1.png')
        path2 = os.path.join(output_dir, filename + '_img2.png')
        flow_path = os.path.join(output_dir, filename + '.flo')
        patch_img1.save(path1)
        patch_img2.save(path2)
        fl.write_flow(patch_flow, flow_path)
        g1.write(path1 + '\n')
        g2.write(path2 + '\n')
        g.write(flow_path + '\n')
コード例 #6
0
if not args.flow_format:
    args.flow_format = '.flo'
file_list = []
in_dir = os.path.abspath(args.input_dir)
out_dir = os.path.abspath(args.output_dir)
flow_count = 0
image_count = 0
for root, dirs, files in os.walk(in_dir):
    if files:
        for filename in files:
            file_path = os.path.join(in_dir, root + '/' + filename)
            if filename.find(args.flow_format) != -1:
                # this is flow file
                image_count += 1
                print 'image count: ', image_count
                flow = fl.read_flow(file_path)
                new_flow = flow[args.y - 1:args.y + args.h - 1,
                                args.x - 1:args.x - 1 + args.w, :]
                out_path = os.path.join(out_dir,
                                        root[root.find('drive/') + 6:])
                if not os.path.exists(out_path):
                    os.makedirs(out_path)
                fl.write_flow(new_flow, os.path.join(out_path, filename))
            elif filename.find(args.image_format) != -1:
                # this is an image file
                flow_count += 1
                print 'flow count: ', flow_count
                img = Image.open(file_path)
                new_img = img.crop((args.x - 1, args.y - 1,
                                    args.x + args.h - 1, args.y + args.w - 1))
                out_path = os.path.join(out_dir,
コード例 #7
0
# 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

import cv2
import numpy as np

# read kitti format optical flow file (.png)
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]
コード例 #8
0
gt_file_path = 'gt_kitti_2015_flow.txt'
pred_file_path = 'pred_kitti_flow_EPIC.txt'

num_sample = count_text_lines(gt_file_path)
gt_paths = read_path(gt_file_path)
pred_path = read_path(pred_file_path)

print(num_sample)

sum_AEE = []
count = 0

for i in range(200):

    gt_flow1 = fl.read_flow(gt_paths[i])

    pre_flow1 = fl.read_flow(pred_path[i])

    res = fl.evaluate_flow(gt_flow1, pre_flow1)

    if res < 50:
        sum_AEE.append(res)
        count += 1

    #sum_AEE.append(res)

    print('running {}/{} file, aee is {}'.format(i + 1, num_sample, res))

AEE = np.mean(sum_AEE)
コード例 #9
0
if not os.path.exists(output_dir):
    os.mkdir(output_dir)
img1_input = f1.readlines()
img2_input = f2.readlines()
flow_input = f.readlines()

# Generate
for i in range(length):
    x_locations = np.random.randint(0, canvas_width - patch_width, size=10)
    y_locations = np.random.randint(0, canvas_height - patch_height, size=10)
    img1 = Image.open(img1_input[i].strip())
    img2 = Image.open(img2_input[i].strip())
    if flow_input[i].strip().find('.png') != -1:
        flow = kittitool.flow_read(flow_input[i].strip())
    else:
        flow = fl.read_flow(flow_input[i].strip())
    for (x, y) in zip(x_locations, y_locations):
        patch_img1 = img1.crop((x, y, x+patch_width, y+patch_height))
        patch_img2 = img2.crop((x, y, x+patch_width, y+patch_height))
        patch_flow = flow[y:y+patch_height, x:x+patch_width]
        filename = str.format('%05d_' % i) + str(x) + '_' + str(y)
        path1 = os.path.join(output_dir, filename + '_img1.png')
        path2 = os.path.join(output_dir, filename + '_img2.png')
        flow_path = os.path.join(output_dir, filename + '.flo')
        patch_img1.save(path1)
        patch_img2.save(path2)
        fl.write_flow(patch_flow, flow_path)
        g1.write(path1 + '\n')
        g2.write(path2 + '\n')
        g.write(flow_path + '\n')
コード例 #10
0
segment_flow.py
This file convert flow file (.flo) into into flow class file according to the direction of the flow
Author: Li Ruoteng
Date: 16 Oct 2016
"""

import os
import argparse
import numpy as np
from PIL import Image
from lib import flowlib as fl

parser = argparse.ArgumentParser(description='Segment optical flow by orientation')
parser.add_argument('flow_format', type=str, help="The format of the files you want to search for")
parser.add_argument('input_dir', type=str, help="The directory to search for flow files")
parser.add_argument('--output_dir', type=str, help='the output directory')
args = parser.parse_args()

if args.output_dir:
    args.output_dir = './segment_flow/'

if not os.path.exists(args.output_dir):
    os.mkdir(args.output_dir)

for file_name in os.listdir(args.input_dir):
    if file_name.find(args.flow_format) != -1:
        flow = fl.read_flow(os.path.join(args.input_dir, file_name))
        seg = fl.flow_to_segment(flow)
        seg_img = Image.fromarray(seg.astype(np.uint8))
        seg_img.save(os.path.join(args.output_dir, file_name[0:file_name.find(args.flow_format)] + '.png'))
コード例 #11
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)
コード例 #12
0
ファイル: demo.py プロジェクト: mingyip/OpticalFlowToolkit
#! /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)
コード例 #13
0
if not args.flow_format:
    args.flow_format = '.flo'
file_list = []
in_dir = os.path.abspath(args.input_dir)
out_dir = os.path.abspath(args.output_dir)
flow_count = 0
image_count = 0
for root, dirs, files in os.walk(in_dir):
    if files:
        for filename in files:
            file_path = os.path.join(in_dir, root + '/' + filename)
            if filename.find(args.flow_format) != -1:
                # this is flow file
                image_count += 1
                print 'image count: ', image_count
                flow = fl.read_flow(file_path)
                new_flow = flow[args.y-1:args.y+args.h-1, args.x-1:args.x-1+args.w, :]
                out_path = os.path.join(out_dir, root[root.find('drive/')+6:])
                if not os.path.exists(out_path):
                    os.makedirs(out_path)
                fl.write_flow(new_flow, os.path.join(out_path, filename))
            elif filename.find(args.image_format) != -1:
                # this is an image file
                flow_count += 1
                print 'flow count: ', flow_count
                img = Image.open(file_path)
                new_img = img.crop((args.x-1, args.y-1, args.x+args.h-1, args.y+args.w-1))
                out_path = os.path.join(out_dir, root[root.find('drive/')+6:])
                if not os.path.exists(out_path):
                    os.makedirs(out_path)
                new_img.save(os.path.join(out_path, filename))
コード例 #14
0
segment_flow.py
This file convert flow file (.flo) into into flow class file according to the direction of the flow
Author: Li Ruoteng
Date: 16 Oct 2016
"""

import os
import argparse
import numpy as np
from PIL import Image
from lib import flowlib as fl

parser = argparse.ArgumentParser(description='Segment optical flow by orientation')
parser.add_argument('flow_format', type=str, help="The format of the files you want to search for")
parser.add_argument('input_dir', type=str, help="The directory to search for flow files")
parser.add_argument('--output_dir', type=str, help='the output directory')
args = parser.parse_args()

if args.output_dir:
    args.output_dir = './segment_flow/'

if not os.path.exists(args.output_dir):
    os.mkdir(args.output_dir)

for file_name in os.listdir(args.input_dir):
    if file_name.find(args.flow_format) != -1:
        flow = fl.read_flow(os.path.join(args.input_dir, file_name))
        seg = fl.segment_flow(flow)
        seg_img = Image.fromarray(seg.astype(np.uint8))
        seg_img.save(os.path.join(args.output_dir, file_name[0:file_name.find(args.flow_format)] + '.png'))