コード例 #1
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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]
コード例 #2
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #3
0
ファイル: bstm_scene_adaptor.py プロジェクト: yochju/vxl
    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)
コード例 #4
0
ファイル: bstm_scene_adaptor.py プロジェクト: yochju/vxl
    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()
コード例 #5
0
ファイル: bstm_scene_adaptor.py プロジェクト: yochju/vxl
 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)
コード例 #6
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
def describe_scene(scene):
    batch.init_process("bstmDescribeSceneProcess")
    batch.set_input_from_db(0, scene)
    batch.run_process()
    (id, type) = batch.commit_output(0)
    dataPath = batch.get_output_string(id)
    batch.remove_data(id)
    (id, type) = batch.commit_output(1)
    appType = batch.get_output_string(id)
    batch.remove_data(id)
    (id, type) = batch.commit_output(2)
    voxel_size = batch.get_output_double(id)
    batch.remove_data(id)
    description = {'voxelLength': voxel_size,
                   'dataPath': dataPath,
                   'appType': appType}
    return description
コード例 #7
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #8
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #9
0
ファイル: bstm_scene_adaptor.py プロジェクト: yochju/vxl
 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)
コード例 #10
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #11
0
ファイル: bstm_from_boxm2.py プロジェクト: yochju/vxl
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')
コード例 #12
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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()
コード例 #13
0
ファイル: bstm_from_boxm2.py プロジェクト: yochju/vxl
def boxm2_load_opencl(scene_str, device_string="gpu"):
    scene = boxm2_load_scene(scene_str)

    ###############################################################
    # Create cache, opencl manager, device, and gpu cache
    ###############################################################
    # print("Create Main Cache");
    batch.init_process("boxm2CreateCacheProcess")
    batch.set_input_from_db(0, scene)
    batch.set_input_string(1, "lru")
    result = batch.run_process()
    if not result:
        raise Exception('boxm2CreateCacheProcess returned false')
    (id, type) = batch.commit_output(0)
    cache = dbvalue(id, type)

    # print("Init Manager");
    batch.init_process("boclInitManagerProcess")
    result = batch.run_process()
    if not result:
        raise Exception('boxm2InitManagerProcess returned false')

    # print("Get Gpu Device");
    batch.init_process("boclGetDeviceProcess")
    batch.set_input_string(0, device_string)
    result = batch.run_process()
    if not result:
        raise Exception('boclGetDeviceProcess returned false')
    (id, type) = batch.commit_output(0)
    device = dbvalue(id, type)

    # print("Create Gpu Cache");
    batch.init_process("boxm2CreateOpenclCacheProcess")
    batch.set_input_from_db(0, device)
    result = batch.run_process()
    if not result:
        raise Exception('boxm2CreateOpenclCacheProcess returned false')
    (id, type) = batch.commit_output(0)
    openclcache = dbvalue(id, type)

    return scene, cache, device, openclcache
コード例 #14
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #15
0
ファイル: bstm_scene_adaptor.py プロジェクト: yochju/vxl
    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()
コード例 #16
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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)
コード例 #17
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #18
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
def render(scene, device, cache, cam, time=0,
           ni=1624, nj=1224, render_label=False):
    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("bstmOclRenderExpectedImageProcess")
        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.set_input_bool(7, render_label)
        batch.run_process()
        (id, type) = batch.commit_output(0)
        exp_image = dbvalue(id, type)
        (id, type) = batch.commit_output(1)
        vis_image = dbvalue(id, type)
        return exp_image, vis_image
    else:
        print "ERROR: Cache type not recognized: ", cache.type
コード例 #19
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
def load_opencl(scene_str, device_string="gpu"):
    scene = load_scene(scene_str)

    ###############################################################
    # Create cache, opencl manager, device, and gpu cache
    ###############################################################
    # print("Create Main Cache");
    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 = dbvalue(id, type)

    # print("Init Manager");
    batch.init_process("boclInitManagerProcess")
    batch.run_process()
    (id, type) = batch.commit_output(0)
    mgr = dbvalue(id, type)

    # print("Get Gpu Device");
    batch.init_process("boclGetDeviceProcess")
    batch.set_input_string(0, device_string)
    batch.set_input_from_db(1, mgr)
    batch.run_process()
    (id, type) = batch.commit_output(0)
    device = dbvalue(id, type)

    # print("Create Gpu Cache");
    batch.init_process("bstmOclCreateCacheProcess")
    batch.set_input_from_db(0, device)
    batch.set_input_from_db(1, scene)
    batch.run_process()
    (id, type) = batch.commit_output(0)
    openclcache = dbvalue(id, type)

    return scene, cache, mgr, device, openclcache
コード例 #20
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
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
コード例 #21
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
def bundle2scene(bundle_file, img_dir, app_model="bstm_mog3_grey",
                 isalign=True, out_dir="", timeSteps=32):
    if app_model == "bstm_mog3_grey":
        nobs_model = "bstm_num_obs"
    else:
        print "ERROR appearance model not recognized!!!", app_model
        return

    # run process
    batch.init_process("bstmBundleToSceneProcess")
    batch.set_input_string(0, bundle_file)
    batch.set_input_string(1, img_dir)
    batch.set_input_string(2, app_model)
    batch.set_input_string(3, nobs_model)
    batch.set_input_bool(4, isalign)
    batch.set_input_unsigned(5, timeSteps)
    batch.set_input_string(6, out_dir)
    batch.run_process()
    (scene_id, scene_type) = batch.commit_output(0)
    uscene = dbvalue(scene_id, scene_type)
    return uscene
コード例 #22
0
ファイル: bstm_from_boxm2.py プロジェクト: yochju/vxl
def boxm2_render_grey_view_dep(scene,
                               cache,
                               cam,
                               ni=1280,
                               nj=720,
                               device=None,
                               ident_string=""):
    if cache.type == "boxm2_opencl_cache_sptr" and device:
        batch.init_process("boxm2OclRenderViewDepExpectedImageProcess")
        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_string(6, ident_string)
        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
コード例 #23
0
ファイル: bstm_adaptor.py プロジェクト: yochju/vxl
def execute_process(name, n_outputs, inputs):
    """Convenience function for running a process with the given name and
    inputs.  Initializes the process, sets the inputs, runs the
    process, and returns the given number of outputs.
    Raises an exception of process fails to run.

    NOTE: Only returns dbvalue's. Caller might need to use
    batch.get_output_float(id) or similar afterwards.

    :param name: The name of the process to run
    :param n_outputs: The number of outputs to recover
    :param inputs: A list of tuples (type_name, value) representing
    inputs to the process. The type_name determines which "set_input"
    function is called: e.g. if the type name is "string",
    batch.set_input_string will be called. If the typename is
    "from_db", batch.set_input_from_db is called. It is important
    that the names exactly match what is required by the corresponding
    process's C++ code. To automatically generate this list when
    possible, see `get_input_types`.
    :returns: A list of the outputs, of length n_outputs. If there are no outputs, returns None.

    """
    batch.init_process(name)
    for i, (t, v) in enumerate(inputs):
        method_name = "set_input_" + t
        getattr(bstm_batch, method_name)(i, v)

    if not batch.run_process():
        raise Exception("Failed to run " + name)

    outputs = []
    for i in range(n_outputs):
        (out_id, out_type) = batch.commit_output(i)
        outputs.append(bstm_register.dbvalue(out_id, out_type))
    if len(outputs) > 0:
        return outputs
    return