From: Vishal J. <vi...@vi...> - 2013-06-21 15:54:36
|
from boxm2_scene_adaptor import *; from bbas_adaptor import *; from vil_adaptor import *; from vpgl_adaptor import *; import numpy, random, os, sys, math; from optparse import OptionParser ####################################################### # handle inputs # #scene is given as first arg, figure out paths # parser = OptionParser() parser.add_option("-m", "--modelfile",dest="model_path", default="model/uscene_color.xml",help="Color Model") parser.add_option("-r", "--radius", action="store", type="float", dest="radius", default=1.25, help="starting cam radius") parser.add_option("-i", "--incline", action="store", type="string", dest="incline", default="40:40", help="incline change throughout spiral in degrees (ex 38:45)") (options, args) = parser.parse_args() print options NI=2560/2 NJ=1440/2 ####################################################### ################################################# # Set some update parameters #model_name = "model" GPU = "gpu0" NUM_IMAGES = 500; #ensure trajectory images can be written out trajDir = os.getcwd() + "/spiral/" if not os.path.exists(trajDir): os.mkdir(trajDir); ################################################ #should initialize a GPU #os.chdir(scene_root); scene_path = options.model_path scene = boxm2_scene_adaptor(scene_path, 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(":")] radius = max(options.radius, 0.9*(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) ################################################### # method for rendering/saving/incrementing globalIdx def render_save(cam): global globalIdx expimg = scene.render(cam, NI, NJ); bimg = convert_image(expimg); exp_fname = trajDir + "/exp_%(#)03d.png"%{"#":globalIdx}; save_image(bimg, exp_fname); #remove_from_db([cam, expimg, bimg]) globalIdx+=1 ################################################################### #render a spiral around a look point returns cam center it ends up on #lookPt (center of spiral) #camCenter (az,inc,rad) w.r.t. lookPt def renderSpiral(lookPt, camCenter, dCamCenter, numImages): global globalIdx for idx in range(numImages): print "Rendering # ", idx, "of", numImages #create cam, and render currAz,currInc,currR = camCenter center = get_camera_center(currAz, currInc, currR, lookPt) cam = create_perspective_camera( (fLength,fLength), ppoint, center, lookPt ) render_save(cam) #increment az, incline and radius camCenter = numpy.add(camCenter, dCamCenter) return camCenter ########################################### ####Render the various maneuvers########### ########################################### # Initialize list of look points to spiral around globalIdx =0 #generate starting point, and delta cam center currR = radius currInc = startInc currAz = 45.0 dr = 0; dAz = 360.0 / NUM_IMAGES dInc = (endInc-startInc)/NUM_IMAGES #render first spiral dcam = (dAz, dInc, dr) center = renderSpiral(modCenter, (currAz, currInc, currR), dcam, NUM_IMAGES) |