def estimateOpticalFlowTVL1(dataset_path, showResult, Backward): print 'Optical Flow computation with Farneback method' frames_list, gt_list, frames_path, gt_path = readDataset(dataset_path) nFrames = len(frames_list) for idx in range(0, nFrames, 2): print ' --> Analyzing sequence ',frames_list[idx],' and ',frames_list[idx+1],'...' # print 'Evaluating frame '+ pr_name frame_dir_0 = os.path.join(frames_path, frames_list[idx]) frame_dir_1 = os.path.join(frames_path, frames_list[idx+1]) if Backward: os.system('./IPOL_TVL1/tvl1flow ' + frame_dir_1 + ' ' + frame_dir_0 + ' IPOL_TVL1/flow.flo') #toExplore_img = cv2.imread(frame_dir_0, 0) curr_img = cv2.imread(frame_dir_1, 0) else: os.system('./IPOL_TVL1/tvl1flow ' + frame_dir_0 + ' ' + frame_dir_1 + ' IPOL_TVL1/flow.flo') curr_img = cv2.imread(frame_dir_0, 0) #toExplore_img = cv2.imread(frame_dir_1, 0) data2D = readFLO('./IPOL_TVL1/flow.flo') OF_image = np.zeros([data2D.shape[0], data2D.shape[1], 3]) OF_image[:,:,0:2] = data2D if showResult: showOpticalFlowArrows(OF_image, curr_img, frames_list[idx], saveResult = True ) showOpticalFlowHSVBlockMatching(OF_image, frames_list[idx], visualization='HS', saveResult=True) np.save('results/OpticalFlow/files/OF_'+frames_list[idx], OF_image) return
def estimateOpticalFlow(dataset_path, blockSize, areaOfSearch, Backward, showResult): print 'Optical Flow computation with BlockSize = ',blockSize, ' and AreaOfSearch = ',areaOfSearch frames_list, gt_list, frames_path, gt_path = readDataset(dataset_path) nFrames = len(frames_list) for idx in range(0, nFrames, 2): print ' --> Analyzing sequence ',frames_list[idx],' and ',frames_list[idx+1],'...' # print 'Evaluating frame '+ pr_name frame_dir_0 = os.path.join(frames_path, frames_list[idx]) frame_dir_1 = os.path.join(frames_path, frames_list[idx+1]) if Backward: toExplore_img = cv2.imread(frame_dir_0, 0) curr_img = cv2.imread(frame_dir_1, 0) else: curr_img = cv2.imread(frame_dir_0, 0) toExplore_img = cv2.imread(frame_dir_1, 0) OF_image = calcOpticalFlowBM(curr_img, toExplore_img, blockSize, areaOfSearch) if showResult: showOpticalFlowArrows(OF_image, curr_img, frames_list[idx], saveResult=True) showOpticalFlowHSVBlockMatching(OF_image, frames_list[idx], visualization='HS', saveResult=True) np.save('results/OpticalFlow/files/OF_'+frames_list[idx], OF_image) return
def estimateOpticalFlowFarneback(dataset_path, showResult, Backward): print 'Optical Flow computation with Farneback method' frames_list, gt_list, frames_path, gt_path = readDataset(dataset_path) nFrames = len(frames_list) for idx in range(0, nFrames, 2): print ' --> Analyzing sequence ',frames_list[idx],' and ',frames_list[idx+1],'...' # print 'Evaluating frame '+ pr_name frame_dir_0 = os.path.join(frames_path, frames_list[idx]) frame_dir_1 = os.path.join(frames_path, frames_list[idx+1]) if Backward: toExplore_img = cv2.imread(frame_dir_0, 0) curr_img = cv2.imread(frame_dir_1, 0) else: curr_img = cv2.imread(frame_dir_0, 0) toExplore_img = cv2.imread(frame_dir_1, 0) #OF_image = cv2.calcOpticalFlowFarneback(curr_img, toExplore_img, pyr_scale=0.5, levels=5, winsize=15, iterations=9, poly_n=7, poly_sigma=1.5, flags=0) #OF_image = cv2.calcOpticalFlowFarneback(curr_img, toExplore_img, pyr_scale=0.5, levels=3, winsize=15, iterations=3, poly_n=5, poly_sigma=1.2, flags=0) OF_image = cv2.calcOpticalFlowFarneback(curr_img, toExplore_img, pyr_scale=0.5, levels=5, winsize=20, iterations=10, poly_n=7, poly_sigma=1.1, flags=0) if showResult: showOpticalFlowArrows(OF_image, curr_img, frames_list[idx], saveResult = True ) showOpticalFlowHSVBlockMatching(OF_image, frames_list[idx], visualization='HS', saveResult=True) np.save('results/OpticalFlow/files/OF_'+frames_list[idx], OF_image) return