def merge(scene, cpu_cache, p_threshold, time): batch.init_process("bstmCppMergeTTProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, p_threshold) batch.set_input_float(3, time) batch.run_process()
def refine(scene, cpu_cache, p_threshold, time): batch.init_process("bstmCppRefineSpacetimeProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, p_threshold) batch.set_input_float(3, time) batch.run_process()
def refine_time(scene, cpu_cache, change_prob_t, time): batch.init_process("bstmCppRefineTTProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, change_prob_t) batch.set_input_float(3, time) batch.run_process()
def create_stream_cache(self, imgs, interval=1, types="", max_gb=6.0): # write image identifiers to file # imgRange = range(0, len(imgs), interval); # num_imgs = len(imgRange); image_id_fname = self.model_dir + "/image_list.txt" fd = open(image_id_fname, "w") print >> fd, len(imgs) # for i in imgRange: # print >>fd, "img_%05d"%i for img in imgs: fname, fextension = splitext(img) bname = basename(fname) print >> fd, bname fd.close() # write type identifiers into file type_id_fname = self.model_dir + "/type_names_list.txt" fd2 = open(type_id_fname, "w") print >>fd2, 4 print >>fd2, "aux0" print >>fd2, "aux1" print >>fd2, "aux2" print >>fd2, "aux3" fd2.close() # open the stream cache, this is a read-only cache batch.init_process("bstmCreateStreamCacheProcess") batch.set_input_from_db(0, self.scene) batch.set_input_string(1, type_id_fname) batch.set_input_string(2, image_id_fname) batch.set_input_float(3, max_gb) batch.run_process() (cache_id, cache_type) = batch.commit_output(0) self.str_cache = batch.dbvalue(cache_id, cache_type)
def transform_to_scene(self, to_scene, trans, rot, scale): if self.opencl_cache.type == "bstm_opencl_cache_sptr": print("transforming scene") batch.init_process("bstmVecfOclTransformSceneProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, to_scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_double(3, trans[0]) batch.set_input_double(4, trans[1]) batch.set_input_double(5, trans[2]) batch.set_input_double(6, rot[0][0]) batch.set_input_double(7, rot[0][1]) batch.set_input_double(8, rot[0][2]) batch.set_input_double(9, rot[1][0]) batch.set_input_double(10, rot[1][1]) batch.set_input_double(11, rot[1][2]) batch.set_input_double(12, rot[2][0]) batch.set_input_double(13, rot[2][1]) batch.set_input_double(14, rot[2][2]) batch.set_input_double(15, scale[0]) batch.set_input_double(16, scale[1]) batch.set_input_double(17, scale[2]) return batch.run_process() else: print "ERROR: Cache type not recognized: ", self.opencl_cache.type return False
def trajectory_next(trajectory): batch.init_process("bstmViewTrajectoryNextProcess") batch.set_input_from_db(0, trajectory) batch.run_process() (id, type) = batch.commit_output(0) cam = dbvalue(id, type) return cam
def remove_from_db(dbvals): if not isinstance(dbvals, (list, tuple)): dbvals = [dbvals] for dbval in dbvals: batch.init_process("bbasRemoveFromDbProcess") batch.set_input_unsigned(0, dbval.id) batch.run_process()
def change_btw_frames(scene, cpu_cache, time0, time1): batch.init_process("bstmCppChangeBtwFramesProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, time0) batch.set_input_float(3, time1) batch.run_process()
def trajectory_size(trajectory): batch.init_process("bstmViewTrajectorySizeProcess") batch.set_input_from_db(0, trajectory) batch.run_process() (id, type) = batch.commit_output(0) size = batch.get_output_unsigned(id) batch.remove_data(id) return size
def write_cache(cache, do_clear=0): if cache.type == "bstm_cache_sptr": batch.init_process("bstmWriteCacheProcess") batch.set_input_from_db(0, cache) batch.set_input_bool(1, do_clear) batch.run_process() else: print "ERROR: Cache type needs to be bstm_cache_sptr, not ", cache.type
def load_scene(scene_str): # print("Loading a Scene from file: ", scene_str); batch.init_process("bstmLoadSceneProcess") batch.set_input_string(0, scene_str) batch.run_process() (scene_id, scene_type) = batch.commit_output(0) scene = dbvalue(scene_id, scene_type) return scene
def load_cpp(scene_str): scene = load_scene(scene_str) batch.init_process("bstmCreateCacheProcess") batch.set_input_from_db(0, scene) batch.set_input_string(1, "lru") batch.run_process() (id, type) = batch.commit_output(0) cache = bstm_register.dbvalue(id, type) return scene, cache
def label_change(scene, device, cache, cam, change_img, change_t, label, time): batch.init_process("bstmOclLabelRayProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_from_db(4, change_img) batch.set_input_float(5, change_t) batch.set_input_float(6, time) batch.set_input_int(7, label) batch.run_process()
def clear_cache(cache): if cache.type == "bstm_cache_sptr": batch.init_process("bstmClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() elif cache.type == "bstm_opencl_cache_sptr": batch.init_process("bstmOclClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() else: print "ERROR: Cache type needs to be bstm_cache_sptr, not ", cache.type
def boxm2_clear_cache(cache): if cache.type == "boxm2_cache_sptr": batch.init_process("boxm2ClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() elif cache.type == "boxm2_opencl_cache_sptr": batch.init_process("boxm2ClearOpenclCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() else: print "ERROR: Cache type needs to be boxm2_cache_sptr, not ", cache.type
def ocl_batch_compute_normal_albedo( self, img_id_list, metadata_filename_list, atmospheric_params_filename_list): batch.init_process( "bstmOclBatchComputeNormalAlbedoArrayProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_string(3, img_id_list) batch.set_input_string(4, metadata_filename_list) batch.set_input_string(5, atmospheric_params_filename_list) batch.run_process()
def boxm2_load_scene(scene_str): # print("Loading a Scene from file: ", scene_str); batch.init_process("boxm2LoadSceneProcess") batch.set_input_string(0, scene_str) status = batch.run_process() if status: (scene_id, scene_type) = batch.commit_output(0) scene = dbvalue(scene_id, scene_type) return scene else: raise Exception('Could not load scene file')
def ocl_info(): # print("Init Manager"); batch.init_process("boclInitManagerProcess") batch.run_process() (id, type) = batch.commit_output(0) mgr = dbvalue(id, type) print("Get OCL info") batch.init_process("bocl_info_process") batch.set_input_from_db(0, mgr) batch.run_process()
def init_trajectory(scene, startInc, endInc, radius, ni=1280, nj=720): batch.init_process("bstmViewInitTrajectoryProcess") batch.set_input_from_db(0, scene) batch.set_input_double(1, float(startInc)) # incline0 batch.set_input_double(2, float(endInc)) # incline1 batch.set_input_double(3, float(radius)) # radius batch.set_input_unsigned(4, ni) # ni batch.set_input_unsigned(5, nj) # nj batch.run_process() (id, type) = batch.commit_output(0) trajectory = dbvalue(id, type) return trajectory
def transform(self, tx, ty, tz, rx, ry, rz, scale): batch.init_process("bstmTransformModelProcess") batch.set_input_from_db(0, self.scene) batch.set_input_float(1, tx) batch.set_input_float(2, ty) batch.set_input_float(3, tz) batch.set_input_float(4, rx) batch.set_input_float(5, ry) batch.set_input_float(6, rz) batch.set_input_float(7, scale) batch.run_process() return
def scene_statistics(scene, cache): batch.init_process("bstmSceneStatisticsProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.run_process() (s1_id, s1_type) = batch.commit_output(0) (s2_id, s2_type) = batch.commit_output(1) (s3_id, s3_type) = batch.commit_output(2) s1 = batch.get_output_float(s1_id) s2 = batch.get_output_float(s2_id) s3 = batch.get_output_unsigned(s3_id) return [s1, s2, s3]
def cpu_batch_paint(self, imgs, cams): if (self.str_cache is None): self.create_stream_cache(imgs) # sigma norm table? under_estimation_probability = 0.2 batch.init_process("bstaSigmaNormTableProcess") batch.set_input_float(0, under_estimation_probability) batch.run_process() (id, type) = batch.commit_output(0) n_table = batch.dvalue(id, type) # loop over images creating aux data for idx in range(0, len(imgs)): # load cam/img img, ni, nj = vil.load_image(imgs[idx]) pcam = vpgl.load_perspective_camera(cams[idx]) gcam = vpgl.persp2gen(pcam, ni, nj) # create norm intensity (num rays...) batch.init_process("bstmCppCreateNormIntensitiesProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, gcam) batch.set_input_from_db(3, img) batch.set_input_string(4, "img_" + "%05d" % idx) batch.run_process() # create aux batch.init_process("bstmCppCreateAuxDataOPT2Process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, gcam) batch.set_input_from_db(3, img) batch.set_input_string(4, "img_" + "%05d" % idx) batch.run_process() self.write_cache(True) batch.init_process("bstmCppBatchUpdateOPT2Process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, self.str_cache) batch.set_input_from_db(3, n_table) batch.run_process() # close the files so that they can be reloaded after the next iteration batch.init_process("bstmStreamCacheCloseFilesProcess") batch.set_input_from_db(0, self.str_cache) batch.run_process() self.write_cache()
def scene_bbox(scene): batch.init_process("bstmSceneBboxProcess") batch.set_input_from_db(0, scene) batch.run_process() out = [] for outIdx in range(6): (id, type) = batch.commit_output(outIdx) pt = batch.get_output_double(id) batch.remove_data(id) out.append(pt) minPt = (out[0], out[1], out[2]) maxPt = (out[3], out[4], out[5]) return (minPt, maxPt)
def update_change(scene, device, cache, cam, img, time, mask_img=None): batch.init_process("bstmOclUpdateChangeProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_from_db(4, img) batch.set_input_from_db(5, mask_img) batch.set_input_float(6, time) batch.run_process() (id, type) = batch.commit_output(0) cd_img = dbvalue(id, type) return cd_img
def cpu_batch_compute_normal_albedo( self, metadata_filename_list, atmospheric_params_filename_list): batch.init_process("bstmCppBatchComputeNormalAlbedoProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, self.str_cache) batch.set_input_string(3, metadata_filename_list) batch.set_input_string(4, atmospheric_params_filename_list) batch.run_process() # close the files so that they can be reloaded after the next iteration batch.init_process("bstmStreamCacheCloseFilesProcess") batch.set_input_from_db(0, self.str_cache) batch.run_process()
def update_color(scene, device, cache, cam, img, time, mog_var=-1, mask_img=None, update_alpha=True, update_changes_only=False): batch.init_process("bstmOclUpdateColorProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_from_db(4, img) batch.set_input_float(5, time) batch.set_input_float(6, mog_var) batch.set_input_from_db(7, mask_img) batch.set_input_bool(8, update_alpha) batch.set_input_bool(9, update_changes_only) batch.run_process()
def update_alpha_naa(self, image, camera, metadata, atmospheric_params, alt_prior, alt_density): batch.init_process("bstmOclUpdateAlphaNAAProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_from_db(4, image) batch.set_input_from_db(5, metadata) batch.set_input_from_db(6, atmospheric_params) batch.set_input_from_db(7, alt_prior) batch.set_input_from_db(8, alt_density) if not (batch.run_process()): print("ERROR: run_process() returned False") return
def render_expected_albedo_normal(self, camera, ni, nj): batch.init_process("bstmOclRenderExpectedAlbedoNormalProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.run_process() (id, type) = batch.commit_output(0) exp_albedo = batch.dvalue(id, type) (id, type) = batch.commit_output(1) exp_normal = batch.dvalue(id, type) (id, type) = batch.commit_output(2) mask_image = batch.dvalue(id, type) return(exp_albedo, exp_normal, mask_image)
def change_detect(scene, device, cache, cam, img, time, mask_img=None, raybelief="", max_mode=False): batch.init_process("bstmOclChangeDetectionProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_from_db(4, img) batch.set_input_from_db(5, mask_img) batch.set_input_string(6, raybelief) batch.set_input_bool(7, max_mode) batch.set_input_float(8, time) batch.run_process() (id, type) = batch.commit_output(0) cd_img = dbvalue(id, type) return cd_img
def render_expected_image_naa( self, camera, ni, nj, metadata, atmospheric_params): batch.init_process("bstmOclRenderExpectedImageNAAProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_from_db(6, metadata) batch.set_input_from_db(7, atmospheric_params) batch.run_process() (id, type) = batch.commit_output(0) exp_image = batch.dvalue(id, type) (id, type) = batch.commit_output(1) mask_image = batch.dvalue(id, type) return(exp_image, mask_image)
def export_pt_cloud(scene, cache, output_filename, prob_t, time, output_aux=True): batch.init_process("bstmCppExtractPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_float(2, prob_t) batch.set_input_float(3, time) batch.run_process() batch.init_process("bstmCppExportPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, output_filename) batch.set_input_bool(3, output_aux) batch.set_input_float(4, time) batch.run_process() return