def save_images(counter, model_image, sim_image, gt_image, gt_pos): trackdir = os.path.join(dataset_name, str(counter + 1)) if not os.path.exists(trackdir): os.makedirs(trackdir) gt_image = np.minimum(np.maximum(gt_image, 0.), 1.) cv2.imwrite(os.path.join(trackdir, "1.png"), (255. * np.rot90(model_image, k=2)).astype(np.uint8)) cv2.imwrite(os.path.join(trackdir, "2.png"), (255. * np.rot90(sim_image, k=2)).astype(np.uint8)) cv2.imwrite(os.path.join(trackdir, "3.png"), (255. * np.rot90(gt_image, k=2)).astype(np.uint8)) #im = draw_map.BathyMapImage(std_pings, 1000, 1000) im = draw_map.BathyMapImage(height_map, bounds) im.draw_height_map(height_map) im.draw_track(gt_pos[3:-3]) im.rotate_crop_image(gt_pos[3], gt_pos[-3], 40.) im.write_image(os.path.join(trackdir, "q.png")) image = cv2.imread(os.path.join(trackdir, "q.png")) image = cv2.resize(image, (3 * image.shape[1], 3 * image.shape[0]), interpolation=cv2.INTER_CUBIC) cv2.imwrite(os.path.join(trackdir, "q.png"), image)
def run_draping(args): mesh_res = args.mesh_res waterfall_bins = args.waterfall_bins sensor_offset = np.array(args.sensor_offset) sensor_yaw = args.sensor_yaw cloud = xyz_data.cloud.parse_file(args.xyz_file) height_map, bounds = mesh_map.height_map_from_dtm_cloud(cloud, mesh_res) if os.path.exists("mesh.npz"): # use cached mesh if it exists data = np.load("mesh.npz") V, F, bounds = data['V'], data['F'], data['bounds'] else: V, F, bounds = mesh_map.mesh_from_dtm_cloud(cloud, mesh_res) np.savez("mesh.npz", V=V, F=F, bounds=bounds) xtf_pings = xtf_data.xtf_sss_ping.read_data(args.xtf_file) # read sss xtf_pings = xtf_data.correct_sensor_offset(xtf_pings, sensor_offset) sound_speeds = csv_data.csv_asvp_sound_speed.parse_file(args.asvp_file) # initialize a draper object that will accept sidescan pings draper = base_draper.BaseDraper(V, F, bounds, sound_speeds) draper.set_sidescan_yaw(sensor_yaw) draper.set_ray_tracing_enabled(False) # images for displaying results meas_im = np.zeros((2000, 2 * waterfall_bins)) model_im = np.zeros((2000, 2 * waterfall_bins)) normals_im = np.zeros((2000, 2 * waterfall_bins, 3)) cv2.namedWindow('Model image', cv2.WINDOW_NORMAL) cv2.namedWindow('Meas image', cv2.WINDOW_NORMAL) cv2.namedWindow('Normal image', cv2.WINDOW_NORMAL) cv2.resizeWindow('Model image', 256, 1000) cv2.resizeWindow('Meas image', 256, 1000) cv2.resizeWindow('Normal image', 256, 1000) # create a bathymetry height map for showing vehicle position d = draw_map.BathyMapImage(height_map, bounds) draping_results = [] # results list for i, ping in enumerate(xtf_pings): left, right = draper.project_ping(ping, waterfall_bins) # project draping_results.append((left, right)) # store result # the rest is basically just for visualizing the images model = np.concatenate([ np.flip(left.time_bin_model_intensities), right.time_bin_model_intensities ]) normals = np.concatenate( [np.flip(left.time_bin_normals, axis=0), right.time_bin_normals], axis=0) meas = np.concatenate([ np.flip( base_draper.compute_bin_intensities(ping.port, waterfall_bins)), base_draper.compute_bin_intensities(ping.stbd, waterfall_bins) ]) meas_im[1:, :] = meas_im[:-1, :] meas_im[0, :] = meas model_im[1:, :] = model_im[:-1, :] model_im[0, :] = model normals_im[1:, :, :] = normals_im[:-1, :, :] if normals.shape[1] > 0: normals_im[0, :, :] = .5 * (normals + 1.) normals_im[0, :, 2] = 0. if i % 10 == 0: d.draw_height_map(height_map) # draw the height map d.draw_blue_pose(ping.pos_, ping.heading_) d.blip() cv2.imshow("Model image", model_im) cv2.imshow("Meas image", meas_im) cv2.imshow("Normal image", normals_im) cv2.waitKey(1) base_draper.write_data(draping_results, args.output) # save results
#!/usr/bin/python from auvlib.data_tools import std_data, gsf_data, utils from auvlib.bathy_maps import draw_map import sys import os def parse_or_load_gsf(path): if os.path.exists("gsf_cache.cereal"): gsf_pings = gsf_data.gsf_mbes_ping.read_data("gsf_cache.cereal") else: gsf_pings = gsf_data.gsf_mbes_ping.parse_folder(path) gsf_data.write_data(gsf_pings, "gsf_cache.cereal") return gsf_pings gsf_pings = utils.parse_or_load_gsf(sys.argv[1]) mbes_pings = gsf_data.convert_pings(gsf_pings) d = draw_map.BathyMapImage(mbes_pings, 500, 500) d.draw_height_map(mbes_pings) d.draw_track(mbes_pings) d.write_image("height_map.png") d.show()
#!/usr/bin/env python from auvlib.data_tools import std_data, gsf_data from auvlib.bathy_maps import draw_map import sys gsf_pings = gsf_data.gsf_mbes_ping.parse_folder( sys.argv[1]) # parse folder of gsf data mbes_pings = gsf_data.convert_pings(gsf_pings) # convert to std_data pings d = draw_map.BathyMapImage(mbes_pings, 500, 500) # create a bathymetry height map d.draw_height_map(mbes_pings) # draw the height map d.draw_track(mbes_pings) # draw the track of the vehicle d.write_image("height_map.png") # save the height map to "height_map.png"