def displacement_field(stdout, image_dir, adaptive=False): results = [int(line[1:]) for line in stdout.split('\n') if len(line) > 0 and line[0] == '$'] results = [(results[i], Displacements(*results[i+1:i+3])) for i in range(0, len(results), 3)] disp_map = dict(results) im_pair = get_image_pair(image_dir) if not adaptive: num_rows = frame_rows(im_pair.A) num_cols = frame_cols(im_pair.A) V = np.zeros([num_rows, num_cols]) U = np.zeros([num_rows, num_cols]) for frame_row in range(num_rows): for frame_col in range(num_cols): pixel_ndx = get_px_ndx(im_pair.A, frame_row, frame_col) U[frame_row][frame_col] = disp_map[pixel_ndx].u - 4 V[frame_row][frame_col] = disp_map[pixel_ndx].v - 4 X = np.array(range(num_cols)) * window_spacing + frame_size / 2 Y = np.array(range(num_rows)) * window_spacing + frame_size / 2 else: ndxs = np.array(disp_map.keys()) U = np.array([disp_map[k].u for k in disp_map]) - 4 V = np.array([disp_map[k].v for k in disp_map]) - 4 X = ndxs % im_pair.A.size[0] + frame_size / 2 Y = ndxs // im_pair.A.size[0] + frame_size / 2 return X, Y, U, V
def parse_and_show(stdout, image_dir, adaptive): im_pair = get_image_pair(image_dir) X, Y, U, V = displacement_field(stdout, image_dir, adaptive) f = plt.figure() a = f.add_axes([.1, .1, .8, .8]) a.imshow(im_pair.A.transpose(Image.FLIP_TOP_BOTTOM)) a.hold(True) a.quiver(X, Y, U, V, color='y', units='x') # a.invert_yaxis() plt.savefig(os.path.join(image_dir, 'PIV.png')) plt.show()
import sys; sys.stdout = open('log', 'w') image_dir = sys.argv[1] use_fpga = int(sys.argv[2]) adaptive = int(sys.argv[3]) num_trackers = 2 os.system('killall bluetcl') if use_fpga: tb_proc = subprocess.Popen(['runtb', './tb'],stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd='../scemi/fpga') else: bsim_proc = subprocess.Popen(['./bsim_dut'], cwd='../scemi/sim') time.sleep(1) tb_proc = subprocess.Popen(['./tb'],stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd='../scemi/sim') im_pair = get_image_pair(image_dir) bspec_im_width = int(subprocess.check_output('cat ../bspec/PIVTypes.bsv | grep "ImageWidth;"', shell=True).split(' ')[1]) if bspec_im_width != im_pair.A.size[0]: print >> sys.stderr, "WARNING: Image width doesn't match parameters used when compling bspec file. Press Enter to continue anyway." raw_input() tb_proc.stdin.write(str(num_trackers) + '\n') for im in im_pair: for pix in im.convert('L').getdata(): tb_proc.stdin.write(str(pix) + '\n') # print pix tb_proc.stdin.write('.\n') print '.'