def batch_paint(self, imgs, cams, device_string=""): # verify stream cache 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) # call batch paint process if device_string == "": batch.init_process("bstmOclPaintBatchProcess") 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, self.str_cache) batch.set_input_from_db(4, n_table) batch.run_process() elif device_string == "cpu": print "Can't use CPU for Paint Batch 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() # write out afterwards self.write_cache()
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 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 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 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 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 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 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 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 refine_scene_around_geometry( self, filter_v, n_times, p_thresh, use_gpu): if self.opencl_cache.type == "bstm_opencl_cache_sptr": print("Refining around surface geometry") batch.init_process( "bstm_ocl_refine_scene_around_geometry_process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.opencl_cache) batch.set_input_from_db(2, self.device) batch.set_input_from_db(3, filter_v) batch.set_input_int(4, n_times) # use negative value to refine all batch.set_input_float(5, p_thresh) batch.set_input_bool(6, use_gpu) return batch.run_process() else: print "ERROR: Cache type not recognized: ", cache.type return False
def render_change(scene, device, cache, cam, time=0, ni=1624, nj=1224): if cache.type == "bstm_cache_sptr": print "bstm_batch CPU render grey and vis not yet implemented" return elif cache.type == "bstm_opencl_cache_sptr" and device: batch.init_process("bstmOclRenderExpectedChangeProcess") 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_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_float(6, time) batch.run_process() (id, type) = batch.commit_output(0) exp_image = dbvalue(id, type) return exp_image else: print "ERROR: Cache type not recognized: ", cache.type
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
def filter_changes(scene, cpu_cache, time): batch.init_process("bstmCppMajorityFilterProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, time) batch.run_process()
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 copy_data_to_future(scene, cpu_cache, time): batch.init_process("bstmCppCopyDataToFutureProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, time) batch.run_process()