def init_scene(self, scene_file, scene_name, device):
     scene_path = scene_root + "/" + scene_name
     if not os.path.exists(scene_path):
         print "SCENE NOT FOUND! ", scene_path
         sys.exit(-1)
     scene = boxm2_scene_adaptor(scene_path, device)
     return scene
Example #2
0
    def updateScene(self, stepNum):

        # Should initialize a GPU
        scenePath = os.path.abspath(self.config.uSceneFileName)
        scene = boxm2_scene_adaptor(scenePath, "gpu0")

        # Get list of imgs and cams
        imgsDir = os.path.abspath(
            os.path.join(self.config.NVMOutputDirName, "imgs"))
        camsDir = os.path.abspath(
            os.path.join(self.config.NVMOutputDirName, "cams"))

        if False == os.path.isdir(imgsDir):
            log("The folder %s does not exist." % (imgsDir))
            return -stepNum

        if False == os.path.isdir(camsDir):
            log("The folder %s does not exist." % (camsDir))
            return -stepNum

        imgFiles = getAllFilesInSubDirs(imgsDir)
        camFiles = getAllFilesInSubDirs(camsDir)

        if len(imgFiles) != len(camFiles):
            log("The number of files in %s is %d." % (imgsDir, len(imgFiles)))
            log("The number of fiels in %s is %d." % (camsDir, len(camFiles)))
            log("These numbers should match and they do not.")
            return -stepNum

        if len(imgFiles) == 0:
            log("No image files were found in %s." % (imgsDir))
            return -stepNum

        imgFiles.sort()
        camFiles.sort()

        # Make two passes over the image set
        for p in xrange(0, self.config.updateScenePassCount):
            frames = range(0, len(imgFiles), 1)
            if self.config.randomizeUpdateOrder:
                random.shuffle(frames)

            for idx, i in enumerate(frames):
                pcam = load_perspective_camera(
                    os.path.join(camsDir, camFiles[i]))
                img, ni, nj = load_image(os.path.join(imgsDir, imgFiles[i]))

                scene.update(pcam, img, 1, "", "gpu0")

                if 0 == (idx % 15
                         ):  #No idea what is special about the magic number 15
                    scene.refine()

        scene.write_cache()

        return 0
Example #3
0
    def updateScene(self, stepNum):

        # Should initialize a GPU
        scenePath = os.path.abspath(self.config.uSceneFileName)
        scene = boxm2_scene_adaptor(scenePath,  "gpu0")

        # Get list of imgs and cams
        imgsDir = os.path.abspath(os.path.join(
            self.config.NVMOutputDirName, "imgs"))
        camsDir = os.path.abspath(os.path.join(
            self.config.NVMOutputDirName, "cams"))

        if False == os.path.isdir(imgsDir):
            log("The folder %s does not exist." % (imgsDir))
            return -stepNum

        if False == os.path.isdir(camsDir):
            log("The folder %s does not exist." % (camsDir))
            return -stepNum

        imgFiles = getAllFilesInSubDirs(imgsDir)
        camFiles = getAllFilesInSubDirs(camsDir)

        if len(imgFiles) != len(camFiles):
            log("The number of files in %s is %d." % (imgsDir, len(imgFiles)))
            log("The number of fiels in %s is %d." % (camsDir, len(camFiles)))
            log("These numbers should match and they do not.")
            return -stepNum

        if len(imgFiles) == 0:
            log("No image files were found in %s." % (imgsDir))
            return -stepNum

        imgFiles.sort()
        camFiles.sort()

        # Make two passes over the image set
        for p in xrange(0, self.config.updateScenePassCount):
            frames = range(0, len(imgFiles), 1)
            if self.config.randomizeUpdateOrder:
                random.shuffle(frames)

            for idx, i in enumerate(frames):
                pcam = load_perspective_camera(
                    os.path.join(camsDir, camFiles[i]))
                img, ni, nj = load_image(os.path.join(imgsDir, imgFiles[i]))

                scene.update(pcam, img, 1, "", "gpu0")

                if 0 == (idx % 15):  # No idea what is special about the magic number 15
                    scene.refine()

        scene.write_cache()

        return 0
Example #4
0
    default="out.ply",
    help="specify point file (.ply, .pcd...)",
)
(options, args) = parser.parse_args()
print options
print args
######################################################

# initialize scene
scene_root = scene_registry.scene_root(options.scene)
scene_path = scene_root + "/" + options.xml
if not os.path.exists(scene_path):
    print "Cannot find file: ", scene_path
    sys.exit(-1)
os.chdir(scene_root)
scene = boxm2_scene_adaptor(scene_path)

# generate point cloud
boxm2_batch.init_process("boxm2ExtractPointCloudProcess")
boxm2_batch.set_input_from_db(0, scene.scene)
boxm2_batch.set_input_from_db(1, scene.cpu_cache)
boxm2_batch.set_input_float(2, options.prob)
# prob threshold
boxm2_batch.run_process()

boxm2_batch.init_process("boxm2ExportOrientedPointCloudProcess")
boxm2_batch.set_input_from_db(0, scene.scene)
boxm2_batch.set_input_from_db(1, scene.cpu_cache)
boxm2_batch.set_input_string(2, options.output)
boxm2_batch.run_process()
scene_root = scene_registry.scene_root( options.scene ); #
model_name = options.xml
if not os.path.exists(scene_root + "/" + model_name):
  print "Cannot find file: ", scene_root+"/"+model_name
  sys.exit(-1) 
GPU = options.gpu;
MAX_FRAMES = options.maxFrames
NI=1280
NJ=720
#################################

#should initialize a GPU
os.chdir(scene_root);
scene_path = os.getcwd() + "/" + model_name
scene = boxm2_scene_adaptor(scene_path, GPU);  
(sceneMin, sceneMax) = scene.bounding_box(); 

#init trajectory 
startInc = 38.0; 
endInc = 38.0; 
radius   = max(options.radius, 1.4*(sceneMax[0]-sceneMin[0])); 
trajectory = init_trajectory(scene.scene, startInc, endInc, radius, NI, NJ);
trajDir = os.getcwd() + "/trajectory/"
if not os.path.exists(trajDir):
  os.mkdir(trajDir);

################# 
# UPDATE LOOP
#################
for x in range(0, MAX_FRAMES, 1):
Example #6
0
    #"change_imgs/results_thresh.25/",
    #"change_imgs/results_rb/",
    #"change_imgs/results_thresh.75/",
    #"change_imgs/results_max_batch/",
    #"change_imgs/results_max_online/",
    "change_imgs/results_fixed/",
    "change_imgs/results_fixed_multires/",
]
#######################################################

#IMAGE_NUM = "046831"
IMAGE_NUM = "045361"

#load up opencl scene
scene_path = "../model_fixed/uscene.xml"
scene = boxm2_scene_adaptor(scene_path, False, "gpu")

#in image and gradients
inPath = "/home/acm/data/visualsfm/apts/change/imgs/" + IMAGE_NUM + ".png"
inImg, ni, nj = load_image(inPath)
greyImg = convert_image(inImg, "grey")
inDx, inDy, inMag = gradient(greyImg)

#expected image
inCamPath = "/home/acm/data/visualsfm/apts/change/cams_krt/" + IMAGE_NUM + "_cam.txt"
inCam = load_perspective_camera(inCamPath)
expImg = scene.render(inCam)
expDx, expDy, expMag = gradient(expImg)

#change image -> blob image
changePath = "/home/acm/data/visualsfm/apts/change/change_imgs/results_fixed_multires/cd_5x5/cd_" + IMAGE_NUM + ".tiff"
Example #7
0
import os, sys
from os.path import basename, splitext
import numpy
import pylab
from glob import glob
from change.helpers import *

#################################
# Set some update parameters
GPU = True
RGB = False
#################################

#load up opencl scene
scene_path = "../model/rscene.xml"
scene = boxm2_scene_adaptor(scene_path, RGB, "gpu")

## move the apperance out the way
move_appearance(os.getcwd() + "/../model/")

#grab all change images
allImgs = glob(os.getcwd() + "/imgs/*.png")
allImgs.sort()
allCams = glob(os.getcwd() + "/cams_krt/*.txt")
allCams.sort()

#load up GT images, grab the corresponding imgs and cams
#gts = glob(os.getcwd() + "/gt/*.png"); gts.sort();
#imgs = []; cams = []
for idx, img in enumerate(allImgs):
    imgnum, ext = os.path.splitext(basename(img))
    print saveout
    print "STD_OUT is being redirected"
    set_stdout(options.std_file)


#################################
# Initialize a GPU
#################################
print "Initializing DEVICE"

os.chdir(scene_root)
scene_path = os.getcwd() + "/" + SCENE_NAME
if not os.path.exists(scene_path):
    print "SCENE NOT FOUND! ", scene_path
    sys.exit(5)
scene = boxm2_scene_adaptor(scene_path, DEVICE)

#################################
# refine
#################################

ncells = scene.refine()
if ncells < 0:
    print "Refined Failed, clearing cache and exiting:"
    scene.clear_cache()
    boxm2_batch.clear()
    sys.exit(1)

#################################
# write and clear cache before exiting
#################################
Example #9
0
        sys.exit(-1)

    #output frame size
    NI, NJ = 1280, 720

    # ensure trajectory images can be written out
    trajDir = os.getcwd() + "/spiral/"
    if not os.path.exists(trajDir):
        os.mkdir(trajDir)
    camDir = os.getcwd() + "/spiral_cams/"
    if not os.path.exists(camDir):
        os.mkdir(camDir)

    #should initialize a GPU
    os.chdir(scene_root)
    scene = boxm2_scene_adaptor(scene_path, options.gpu)
    (sceneMin, sceneMax) = scene.bounding_box()

    #init trajectory, look at center point - this can drift
    startInc, endInc = [int(x) for x in options.incline.split(":")]
    if options.radius > 0.0:
        radius = options.radius
    else:
        radius = 1.4 * (sceneMax[0] - sceneMin[0])
    modCenter = numpy.add(sceneMax, sceneMin) / 2.0

    #Generate camera params - fLenght, ppoint
    fLength = math.sqrt(NI * NI + NJ * NJ)
    ppoint = (NI / 2, NJ / 2)

    ###########################################
Example #10
0
if len(imgs) != len(cams) :
    print "CAMS NOT ONE TO ONE WITH IMAGES"
    sys.exit();

#the folder where expected images are saved
expected_img_dir = boxm2_dir +  "/expectedImgs"
if not os.path.isdir(expected_img_dir + '/'):
    os.mkdir(expected_img_dir + '/');


list = range(0,len(imgs),1);

#delete *.bin files in the folder
deleteAllFiles(boxm2_dir)

scene = boxm2_scene_adaptor(boxm2_dir + "/scene.xml", "gpu0");

#choosen a cam to render the expected images
render_cam = load_perspective_camera(cams[0]);

#do a few iterations over the images while refining the octree 
NUM_ITER = 4
for iter in range(NUM_ITER):
    random.shuffle(list);

    #do linear randomized pass
    for idx, image_number in enumerate(list):

        #refine the octree every 10th iteration
        if idx % 10 == 9:
            print "REFINING OCTREE"
Example #11
0
import random, os, sys, scene_registry;  
from boxm2_scene_adaptor import *; 
from optparse import OptionParser

#scene is given as first arg, figure out paths        #
parser = OptionParser()
parser.add_option("-s", "--scene", action="store", type="string", dest="scene", help="specify scene name")
parser.add_option("-x", "--xmlfile", action="store", type="string", dest="xml", default="uscene.xml", help="scene.xml file name (model/uscene.xml, model_fixed/scene.xml, rscene.xml)")
parser.add_option("-g", "--gpu",   action="store", type="string", dest="gpu",   default="gpu1", help="specify gpu (gpu0, gpu1, etc)")
parser.add_option("-t", "--thresh", action="store", type="float", dest="thresh", default=.3, help="Specify refine probability threshold")
(options, args) = parser.parse_args()
print options
print args

# handle inputs
#scene is given as first arg, figure out paths
scene_root = scene_registry.scene_root( options.scene ); 
os.chdir(scene_root)
scene_path = os.getcwd() + "/" + options.xml
if not os.path.exists(scene_path):
  print "SCENE NOT FOUND! ", scene_path
  sys.exit(-1)
scene = boxm2_scene_adaptor (scene_path, options.gpu);  
scene.refine(options.thresh);
scene.write_cache(); 
Example #12
0
  # handle inputs
  parser = OptionParser()
  parser.add_option("-s", "--scene", action="store", type="string", dest="scene", help="specify scene name")
  parser.add_option("-x", "--xmlfile", action="store", type="string", dest="xml", default="model/uscene.xml", help="scene.xml file name (model/uscene.xml, model_fixed/scene.xml, rscene.xml)")
  parser.add_option("-a", "--allImg", action="store_true", dest="allImg", default=False, help="render depth image for all available images") 
  (options, args) = parser.parse_args()
  print options
  print args
  
  #scene
  scene_root = scene_registry.scene_root( options.scene );
  scene_path = scene_root + "/" + options.xml; 
  if not os.path.exists(scene_path):
    print "Cannot find file: ", scene_path
    sys.exit(-1) 
  scene = boxm2_scene_adaptor(scene_path, "gpu"); 

  #render height map
  hdir = os.getcwd() + "/height/"
  if not os.path.exists(hdir):
    os.makedirs(hdir)
  z, var, x, y, prob, app = scene.render_height_map()
  save_image(z, hdir + "z.tiff")
  save_image(var, hdir + "var.tiff")
  save_image(x, hdir + "x.tiff")
  save_image(y, hdir + "y.tiff")
  save_image(prob, hdir + "prob.tiff")
  save_image(app, hdir + "appearance.tiff")

  #if specified to render all images
  if options.allImg:
Example #13
0
from boxm2_scene_adaptor import *; 
from bbas_adaptor import *;
from vil_adaptor import *;
from vpgl_adaptor import *;
import numpy, random, os, sys, math, scene_registry;  
from optparse import OptionParser

if __name__ == "__main__":
  # handle inputs
  parser = OptionParser()
  parser.add_option("-s", "--scene", action="store", type="string", dest="scene", help="specify scene name")
  parser.add_option("-x", "--xmlfile", action="store", type="string", dest="xml", default="model/uscene.xml", help="scene.xml file name (model/uscene.xml, model_fixed/scene.xml, rscene.xml)")
  (options, args) = parser.parse_args()
  print options
  print args

  scene_root = scene_registry.scene_root( options.scene ); #
  scene_path = scene_root + "/" + options.xml; 
  if not os.path.exists(scene_path):
    print "Cannot find file: ", scene_path
    sys.exit(-1) 

  #should initialize a GPU
  scene = boxm2_scene_adaptor(scene_path);  
  (sceneMin, sceneMax) = scene.bounding_box(); 
  print "Scene bounding box: ", sceneMin, " to ", sceneMax
 
                  dest="camera",
                  default="",
                  help="specify corresponding camera to use")
(options, args) = parser.parse_args()
print options
print args

############################################
# Create Scene
scene_root = scene_registry.scene_root(options.scene)
#
xmlPath = scene_root + "/" + options.xml
if not os.path.exists(xmlPath):
    print "Cannot find file: ", xmlPath
    sys.exit(-1)
scene = boxm2_scene_adaptor(xmlPath, options.gpu)

############################################
#search a bit for camera and image
imageDir = scene_root + "/nvm_out/imgs/"
if options.image == "" and os.path.exists(imageDir):
    print "Using first image, guessing dir: ", imageDir
    imGlob = glob.glob(imageDir + "/*")
    if len(imGlob) > 0:
        image_filename = imGlob[0]
    else:
        print "Can't find default image directory"
        sys.exit(-1)
elif options.image != "":
    print "Can't find default image directory"
    sys.exit(-1)
Example #15
0
scene_root = scene_registry.scene_root(options.scene)
#
model_name = options.xml
if not os.path.exists(scene_root + "/" + model_name):
    print "Cannot find file: ", scene_root + "/" + model_name
    sys.exit(-1)
GPU = options.gpu
MAX_FRAMES = options.maxFrames
NI = 1280
NJ = 720
#################################

#should initialize a GPU
os.chdir(scene_root)
scene_path = os.getcwd() + "/" + model_name
scene = boxm2_scene_adaptor(scene_path, GPU)
(sceneMin, sceneMax) = scene.bounding_box()

#init trajectory
startInc = 38.0
endInc = 38.0
radius = max(options.radius, 1.4 * (sceneMax[0] - sceneMin[0]))
trajectory = init_trajectory(scene.scene, startInc, endInc, radius, NI, NJ)
trajDir = os.getcwd() + "/trajectory/"
if not os.path.exists(trajDir):
    os.mkdir(trajDir)

#################
# UPDATE LOOP
#################
for x in range(0, MAX_FRAMES, 1):
Example #16
0
from bbas_adaptor import remove_from_db
from glob import glob

#import matplotlib.pyplot as plt;
boxm2_batch.register_processes();
boxm2_batch.register_datatypes();

class dbvalue:
  def __init__(self, index, type):
    self.id = index    # unsigned integer
    self.type = type   # string


#We assume the following scene structure
#model_dir/           : parent folder
#model_dir/boxm2_site : contains the 3d model
model_dir = "/data/3dv15_experiments/3d_scenes/capitol_2006/"
boxm2_dir = model_dir + "/boxm2_site"

if not os.path.isdir(boxm2_dir + '/'):
    print "Invalid Site Dir"
    sys.exit(-1);


scene = boxm2_scene_adaptor(boxm2_dir + "/scene.xml", "gpu0");
extract_cell_centers(scene.scene, scene.cpu_cache,prob_thresh = 0.05)
export_points_and_normals(scene.scene, scene.cpu_cache,boxm2_dir+"/pt.xyz")

raw_input("ENTER TO EXIT...")
boxm2_batch.clear()
Example #17
0
parser.add_option("-x", "--xmlfile", action="store", type="string", dest="xml", default="model/uscene.xml", help="scene.xml file name (model/uscene.xml, model_fixed/scene.xml, rscene.xml)")
parser.add_option("-g", "--gpu",   action="store", type="string", dest="gpu",   default="gpu1", help="specify gpu (gpu0, gpu1, etc)")
parser.add_option("-i", "--image", action="store", type="string", dest="image", default="", help="specify which image or directory to use")
parser.add_option("-c", "--camera", action="store", type="string", dest="camera", default="", help="specify corresponding camera or directory to use")
(options, args) = parser.parse_args()
print options
print args

############################################
# Create Scene
scene_root = scene_registry.scene_root( options.scene ); #
xmlPath = scene_root + "/" + options.xml
if not os.path.exists(xmlPath):
  print "Cannot find file: ", xmlPath
  sys.exit(-1) 
scene = boxm2_scene_adaptor(xmlPath, options.gpu);  

############################################
#search a bit for camera and image 
defImg = scene_root + "/nvm_out/imgs/"
defCam = scene_root + "/nvm_out/cams_krt/"
if os.path.exists(options.image) and os.path.exists(options.camera): 
  imageDir = options.image
  camDir = options.camera
elif os.path.exists(defImg) and os.path.exists(defCam):
  imageDir = defImg
  camDir = defCam
else:
  print "Can't find default image/cam dirs: ", defImg, defCam
  sys.exit(-1)
print "Image Directory: ", imageDir
from boxm2_scene_adaptor import *; 
from vil_adaptor import *;
from vpgl_adaptor import *;
import random, os, sys;  
from glob import glob; 

#################################
# Set some update parameters
RGB = False; 
GPU = True;
#################################

#should initialize a GPU
scene_path = os.getcwd() + "/model_batch/uscene.xml";
scene = boxm2_scene_adaptor (scene_path, RGB, "gpu1");  

# Get list of imgs and cams
imgs_dir = os.getcwd() + "/nvm_out/imgs/"
cams_dir = os.getcwd() + "/nvm_out/cams_krt/"
imgs = glob(imgs_dir + "/*.png"); imgs.sort(); 
cams = glob(cams_dir + "/*.txt"); cams.sort(); 
if len(imgs) != len(cams) :
  print "CAMS NOT ONE TO ONE WITH IMAGES"
  sys.exit();

#for idx in range(0, len(imgs)) :

#  print '--------------------------';
#  print "processing image " + imgs[idx];
#  
#  #load cam/img