def disparity_minus_mean(): down_factor = 2 # index = 1 test=False n_disp = 128 differences = [] border = 10 for index in range(2): print(index) source = KittiMultiViewSource(index, test=test, n_frames=0) average_disparity = source.get_average_disparity() # frame = load_pair(index, test, frame=i, multiview=True) frame = source.frame_ten gt_frame = calc_ground_truth(frame, n_disp, down_factor=down_factor, iters=50) d = gt_frame.astype('int') - average_disparity.astype('int') d = d[border:-border,border:-border] differences.append(d.flatten()) # plt.subplot(211) # plt.imshow(gt_frame) # plt.colorbar() # plt.subplot(212) # plt.imshow(average_disparity) # plt.colorbar() # plt.show() foo = np.array(differences) print() print(np.array(differences).shape)
def disparity_minus_mean(): down_factor = 2 # index = 1 test = False n_disp = 128 differences = [] border = 10 for index in range(2): print(index) source = KittiMultiViewSource(index, test=test, n_frames=0) average_disparity = source.get_average_disparity() # frame = load_pair(index, test, frame=i, multiview=True) frame = source.frame_ten gt_frame = calc_ground_truth(frame, n_disp, down_factor=down_factor, iters=50) d = gt_frame.astype('int') - average_disparity.astype('int') d = d[border:-border, border:-border] differences.append(d.flatten()) # plt.subplot(211) # plt.imshow(gt_frame) # plt.colorbar() # plt.subplot(212) # plt.imshow(average_disparity) # plt.colorbar() # plt.show() foo = np.array(differences) print() print(np.array(differences).shape)
def foveation_sequence(): frame_down_factor = 1 mem_down_factor = 2 # relative to the frame down factor coarse_down_factor = 2 # for the coarse comparison fs = 80 fovea_shape = (fs, fs) full_values = 128 values = full_values / 2**frame_down_factor index = 15 n_frames = 10 source = KittiMultiViewSource(index, test=False, n_frames=n_frames) full_shape = source.frame_ten[0].shape frame_ten = [downsample(source.frame_ten[0], frame_down_factor), downsample(source.frame_ten[1], frame_down_factor)] frame_shape = frame_ten[0].shape average_disp = source.get_average_disparity() average_disp = cv2.pyrUp(average_disp)[:frame_shape[0],:frame_shape[1]-values] filter = Filter(average_disp, frame_down_factor, mem_down_factor, fovea_shape, frame_shape, values, verbose=False, memory_length=0) plt.figure() import matplotlib.cm as cm for i in range(0, 10, 2): frame = [downsample(source.frame_sequence[i][0], frame_down_factor), downsample(source.frame_sequence[i][1], frame_down_factor)] filter_disp, fovea_corner = filter.process_frame(None, frame) edge = 5 plt.subplot(5,1,i/2+1) # plt.subplot(5,2,i+1) plt.imshow(trim(frame[0], values, edge), cmap = cm.Greys_r) # remove_axes() # plt.subplot(5,2,i+2) # plt.imshow(trim(filter_disp, values, edge), vmin=0, vmax=full_values) fovea_corner = fovea_corner[0] # plot_edges(fovea_ij, (fs, fs)) fi, fj = fovea_corner fm = fs fn = fs plt.plot([fj, fj+fn, fj+fn, fj, fj], [fi, fi, fi+fm, fi+fm, fi], 'white') # plt.scatter(fovea_corner[1]-values+fs/2, fovea_corner[0]-edge+fs/2, s=100, c='green', marker='+', linewidths=2) # plt.scatter(fovea_corner[1]-values, fovea_corner[0]-edge, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values+fs, fovea_corner[0]-edge+fs, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values, fovea_corner[0]-edge+fs, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values+fs, fovea_corner[0]-edge, s=9, c='green', marker='+', linewidths=3) remove_axes() plt.tight_layout(-1) plt.show()
def objective(args): # args['ksize'] = int(args['ksize']) costs = [] # for index in range(3): # for index in range(10): for index in range(194): if index in [31, 82, 114]: # missing frames continue source = KittiMultiViewSource(index, test=False, n_frames=0) full_shape = source.frame_ten[0].shape frame_ten = [downsample(source.frame_ten[0], frame_down_factor), downsample(source.frame_ten[1], frame_down_factor)] frame_shape = frame_ten[0].shape true_points = source.get_ground_truth_points(occluded=False) # determine fovea shape fovea_pixels = np.ceil(fovea_fraction * frame_shape[0] * (frame_shape[1] - values)) if fovea_pixels > 0: fovea_height = np.minimum(frame_shape[0], np.ceil(fovea_pixels ** .5)) fovea_width = np.minimum(frame_shape[1], np.ceil(fovea_pixels / fovea_height)) fovea_shape = fovea_height, fovea_width else: fovea_shape = (0, 0) # average disparity try: average_disp = source.get_average_disparity() except IOError: # likely does not have a full 20 frames print("Skipping index %d (lacks frames)" % index) continue average_disp = upsample_average_disp( average_disp, frame_down_factor, frame_shape, values) # run the filter foveal = Foveal(average_disp, frame_down_factor, mem_down_factor, fovea_shape, frame_shape, values, iters=iters, fovea_levels=fovea_levels, **args) disp, _ = foveal.process_frame(frame_ten) # cost = cost_on_points(disp[:,values:], true_points, full_shape=full_shape) cost = cost_on_points(disp[:,values:], true_points, average_disp, full_shape=full_shape, clip=error_clip) costs.append(cost) error = np.mean(costs) errors[arg_key(args)] = error args_s = "{%s}" % ', '.join("%r: %s" % (k, args[k]) for k in sorted(space)) print("%s: %s" % (error, args_s)) return error
#plt.show(block=True) area = 93 * 275 fovea_area = 0.4 * area height = np.floor(np.sqrt(fovea_area)) width = np.floor(fovea_area / height) fovea_shape = (height, width) print(np.floor(np.sqrt(area))) n_frames = 194 best_nums = [] for index in range(n_frames): print(index) source = KittiMultiViewSource(index) average_disparity = source.get_average_disparity() uc = UnusuallyClose(average_disparity) gt = calc_ground_truth(source.frame_ten, 128, down_factor=2, iters=3) cost = uc.get_importance(gt) foveas_ij, fovea_part_shape = _choose_foveas(cost, fovea_shape, values, 30) best_nums.append(len(foveas_ij)) print('best nums:') print(best_nums) plt.figure() plt.hist(best_nums, np.add(range(31), 0.5)) plt.xlabel('Number of foveas', fontsize=18) plt.ylabel('Frequency of best cost', fontsize=18) plt.gca().tick_params(labelsize='18') plt.xlim((0, 31))
area = 93*275 fovea_area = 0.4 * area height = np.floor(np.sqrt(fovea_area)) width = np.floor(fovea_area / height) fovea_shape = (height, width) print(np.floor(np.sqrt(area))) n_frames = 194 best_nums = [] for index in range(n_frames): print(index) source = KittiMultiViewSource(index) average_disparity = source.get_average_disparity() uc = UnusuallyClose(average_disparity) gt = calc_ground_truth(source.frame_ten, 128, down_factor=2, iters=3) cost = uc.get_importance(gt) foveas_ij, fovea_part_shape = _choose_foveas(cost, fovea_shape, values, 30) best_nums.append(len(foveas_ij)) print('best nums:') print(best_nums) plt.figure() plt.hist(best_nums, np.add(range(31), 0.5)) plt.xlabel('Number of foveas', fontsize=18) plt.ylabel('Frequency of best cost', fontsize=18) plt.gca().tick_params(labelsize='18') plt.xlim((0, 31))
def foveation_sequence(): frame_down_factor = 1 mem_down_factor = 2 # relative to the frame down factor coarse_down_factor = 2 # for the coarse comparison fs = 80 fovea_shape = (fs, fs) full_values = 128 values = full_values / 2**frame_down_factor index = 15 n_frames = 10 source = KittiMultiViewSource(index, test=False, n_frames=n_frames) full_shape = source.frame_ten[0].shape frame_ten = [ downsample(source.frame_ten[0], frame_down_factor), downsample(source.frame_ten[1], frame_down_factor) ] frame_shape = frame_ten[0].shape average_disp = source.get_average_disparity() average_disp = cv2.pyrUp(average_disp)[:frame_shape[0], :frame_shape[1] - values] filter = Filter(average_disp, frame_down_factor, mem_down_factor, fovea_shape, frame_shape, values, verbose=False, memory_length=0) plt.figure() import matplotlib.cm as cm for i in range(0, 10, 2): frame = [ downsample(source.frame_sequence[i][0], frame_down_factor), downsample(source.frame_sequence[i][1], frame_down_factor) ] filter_disp, fovea_corner = filter.process_frame(None, frame) edge = 5 plt.subplot(5, 1, i / 2 + 1) # plt.subplot(5,2,i+1) plt.imshow(trim(frame[0], values, edge), cmap=cm.Greys_r) # remove_axes() # plt.subplot(5,2,i+2) # plt.imshow(trim(filter_disp, values, edge), vmin=0, vmax=full_values) fovea_corner = fovea_corner[0] # plot_edges(fovea_ij, (fs, fs)) fi, fj = fovea_corner fm = fs fn = fs plt.plot([fj, fj + fn, fj + fn, fj, fj], [fi, fi, fi + fm, fi + fm, fi], 'white') # plt.scatter(fovea_corner[1]-values+fs/2, fovea_corner[0]-edge+fs/2, s=100, c='green', marker='+', linewidths=2) # plt.scatter(fovea_corner[1]-values, fovea_corner[0]-edge, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values+fs, fovea_corner[0]-edge+fs, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values, fovea_corner[0]-edge+fs, s=9, c='green', marker='+', linewidths=3) # plt.scatter(fovea_corner[1]-values+fs, fovea_corner[0]-edge, s=9, c='green', marker='+', linewidths=3) remove_axes() plt.tight_layout(-1) plt.show()