def main(f_p, f_n): net = caffe.Net('../models/test_1/deploy.prototxt', '../outputs/snapshot_iter_2000.caffemodel', caffe.TEST) im, im_p, im_n = fetch_flow_data('../data/training/final/'+f_p+'.png', '../data/training/final/'+f_n+'.png') net.blobs['data'].data.flat = im.flat net.forward() flow = net.blobs['flow_est'].data[0,...].transpose() flow_img = pyflow.flow_to_color(flow) gt = pyflow.read_flow_file('../data/training/flow/'+f_p+'.flo') gt_img = pyflow.flow_to_color(gt) f, axarr = plt.subplots(2, 2) axarr[0, 0].imshow(im_p) axarr[0, 0].set_title('frame_prev') axarr[0, 1].imshow(im_n) axarr[0, 1].set_title('frame_next') axarr[1, 0].imshow(flow_img) axarr[1, 0].set_title('result') axarr[1, 1].imshow(gt_img) axarr[1, 1].set_title('ground_truth') f1, axarr1 = plt.subplots(2, 2) axarr1[0, 0].imshow(flow[...,0], cmap=cm.gray_r) axarr1[0, 0].set_title('flow_u') axarr1[0, 1].imshow(gt[...,0], cmap=cm.gray_r) axarr1[0, 1].set_title('ground_truth_u') axarr1[1, 0].imshow(flow[...,1], cmap=cm.gray_r) axarr1[1, 0].set_title('flow_v') axarr1[1, 1].imshow(gt[...,1], cmap=cm.gray_r) axarr1[1, 1].set_title('ground_truth_v') plt.show()
def load_next_image(self): if self._cur == len(self.data_list): self._cur = 0 shuffle(self.data_list) datum = self.data_list[self._cur] self._cur += 1 im_p = np.asarray(Image.open(datum['im_p'])) im_n = np.asarray(Image.open(datum['im_n'])) #TODO Transformation image and flow here. im = np.dstack([im_p, im_n])/255.0 - 0.5 fl = np.asarray(pyflow.read_flow_file(datum['fl'])) return im.transpose(), fl.transpose()
def main(): net = caffe.Net('../models/test_1/deploy.prototxt', '../outputs/snapshot_iter_2000.caffemodel', caffe.TEST) sintel = MPISintel('../data/training') idx = 0 for frame in sintel.train_list: print frame['fl'] im, im_p, im_n = fetch_flow_data(frame['im_p'], frame['im_n']) net.blobs['data'].data.flat = im.flat net.forward() flow = net.blobs['flow_est'].data[0,...].transpose() flow_img = pyflow.flow_to_color(flow) gt = pyflow.read_flow_file(frame['fl']) gt = cv2.resize(gt, (256, 109)) gt_img = pyflow.flow_to_color(gt) err = pyflow.calc_epe_stat(flow, gt) print err
"""test module""" from __future__ import print_function if __name__ == "__main__": import sys sys.path.insert(0, '../../') from numpy.testing import assert_equal import cv2 import pylab import pyflow flow = pyflow.read_flow_file(r"flow10.flo") pyflow.write_flow_file("test.flo", flow) g = pyflow.read_flow_file(r"test.flo") assert_equal(flow, g) img = pyflow.flow_to_color(flow) pylab.imshow(img) pylab.show() pylab.imshow(pyflow.show_color_scheme()) pylab.show() prev_frame = cv2.imread("frame10.png") next_frame = cv2.imread("frame11.png") prev_gray = cv2.cvtColor(prev_frame, cv2.COLOR_BGR2GRAY) next_gray = cv2.cvtColor(next_frame, cv2.COLOR_BGR2GRAY) fbflow = cv2.calcOpticalFlowFarneback(prev_gray, next_gray, 0.5, 3, 15, 3, 5, 1.2, 0)