< Previous | Contents | Manuals Home | Boris FX | Next >
Loading a Shot and Path
This example reads a file that contains the file name of the images for a shot, a number of typical shot setup parameters, and then reads camera path information from that file and loads it into the camera seed path. Then it tracks and solves the shot.
There's a main function that can be called with command line arguments via a small stub at the end. The function can connect to an existing SynthEyes or create a new one. There's a fair amount of debugging printout available if you want; with verbose = 2 you'll see the entire communications between python and SynthEyes.
The incoming rotation angles must be interpreted correctly. The code shows cases for x, y, and z angles in the most common ZXY ordering, or for pan/tilt/roll angles. You'll see that you can easily rearrange to other formats that you might need. You can also readjust for different coordinate axes if needed: this code assumes the incoming data is in Z-Up format.
The recalculation controls are used to prevent spline recalculations from taking too much time; after the path is read, the spline recalculation routine is called directly.
The code shows different ways to accomplish some operations, ie directly changing the scene file or remote-controlling the user interface. Generally the scene access is preferred since it can be done more quickly, without requiring specific UI panels or dialogs to be opened.
You can generate sample input data by exporting a solved shot using the Plain Camera export and adding the initial information in a text editor.
######################################################################
# Scripted open of a new shot by reading a text file with the # image name, aspect, and FOV and a recorded mocap camera path # Boris FX, Inc.
import sys import SyPy
from SyPy import sytrans
verbose = 1 # set the debug level to 0/1/2 hlev = SyPy.SyLevel()
# Call with the descriptive-file filename.
# Supply valid port/pin to connect to an existing instance, # otherwise a new SynthEyes will be created.
def OpenSceneFromFile(descrfnm, port=0, pin=""): global hlev, verbose
# Open the description file istrm = open(descrfnm, "r")
# First line is the shot name
imgfilnm = istrm.readline().strip()
# Second has focal length and H/V plate sizes
wds = istrm.readline().split() rate = float(wds[0])
focal = float(wds[1]) plateWidth = float(wds[2]) plateHeight = float(wds[3]) if verbose > 0:
print "rate", rate, "focal", focal, "width", plateWidth, \ "height", plateHeight
aspect = plateWidth / plateHeight if verbose > 0:
print "aspect", aspect
# Create a new SynthEyes instance. We could pass it the file name # to open directly but do it in two steps to show how to do it in # case we want to run an existing instance
if port != 0:
rv = hlev.OpenExisting(port, pin) if verbose > 0:
print "port", port, "pin", pin
else:
rv = hlev.OpenSynthEyes() if verbose > 0:
print "OpenSynthEyes returned", rv
print "port", SyPy.syconfig.DefaultPort(), \ "pin", SyPy.syconfig.DefaultPin()
if not rv:
if verbose > 0:
print "couldn't connect to SynthEyes" return False
if verbose > 0:
print "Connected..." if verbose > 1:
hlev.Debug(1) # watch communications... # Open the shot
rv = hlev.NewSceneAndShot(imgfilnm, aspect) if rv == None:
if verbose > 0:
print "couldn't open the shot" return False
if verbose > 0:
print "Opened shot..."
# Make sure in Z-up mode, override user temporarily hlev.SetSzlAxisMode(0)
# Locate the camera and shot (via Sizzle attribute access)
cam = hlev.FindObjByName("Camera01") sht = cam.Get("shot")
# Adjust the shot parameters more here.... BeginShotChanges not needed # just to set the plateWidth, but use it in case more complex things
# are added later.
hlev.BeginShotChanges(sht)
sht.Set("backPlateWidth", plateWidth) # in mm per Sizzle doc
# no need to set height, SynthEyes calculates it from the aspect # Start reading data lines from the file
frm = 0
hlev.SetSzlRecalc(0) # suppress spline recalculation for mass reload while True:
line = istrm.readline() if not line:
break
# Pull out the tokens
wds = line.split() if len(wds) == 0:
continue
elif not wds[0][0].isdigit(): continue # header line
elif len(wds) < 6:
raise Exception("incomplete data") px = float(wds[0])
py = float(wds[1]) pz = float(wds[2])
rx = pan = float(wds[3]) ry = tilt = float(wds[4]) rz = roll = float(wds[5])
# Crank up the right orientation matrix --- for Z-Up coordinates
# Rotate cam up to pointing along Y, roll around Y, tilt u/d around X, # pan around Z
pose = sytrans.SyTrans()
if True: # rx/ry/rz in ZXY order pose.SetProd( sytrans.Prod( \
sytrans.YRot(ry), \ sytrans.XRot(rx)), \
sytrans.ZRot(rz))
else: # pan/tilt/roll pose.SetProd( sytrans.Prod( \
sytrans.ZRot(pan), \
sytrans.XRot(tilt)), \ sytrans.Prod( \
sytrans.YRot(-roll), \ sytrans.XRot(90)))
pose.SetPos([px,py,pz]) # Store the data
hlev.SetSzlFrame(frm) cam.Set("trans", pose) frm += 1
# Reenable spline calculations and recalculate now that changes done
cam.Call("RecalcSeedPath") # now the deferred recalculation hlev.SetSzlRecalc(1) # turn back on
hlev.ClearSzlFrame() if verbose > 0:
print "read", frm, "frames" # TODO
# Set up Known with Estimate lens mode.
# Note that if the scene was already solved, we'd have to use seedFOV # so we'd have to convert the FL to a FOV with sytrans.FLen2FOV
# If a zooming FOV estimate was supplied, we'd probably want to solve
# once as a Known lens, then do a Refine cycle with the lens set to Zoom
sht.Set("rate", rate) if focal != 0:
cam.SetF(0, "fl", focal) # animated, be sure at frame zero cam.Set("lensMode", 3) # known with estimate
# Set from seed path solving mode, as long as we have one
if frm >= 2:
cam.Set("mode", "From Path") # or a different way....
# hlev.SetRoom("Solver") # to Summary room # hlev.Main().ByID(1274).SetOption("From Path")
# or this: hlev.Main().ByID(1274).SetOptionNo(9) # wrap up a little
hlev.AcceptShotChanges(sht, "Set up shot") istrm.close()
# Launch a solve
hlev.ClickMainMenuAndWait("Summary") # to Summary room, for variety # hlev.SetRoom("Summary") # normally this...
hlev.Main().ByName("AUTO").ClickAndContinue(); # or via Action code
if verbose > 0: print "Success!"
return True
#
# Make it work as a standalone script with description filename on the # command line
if name == " main " and len(sys.argv) >= 2: if verbose > 0:
print "source file name:", sys.argv[0]
if len(sys.argv) >= 4: # port and pin
OpenSceneFromFile(sys.argv[1], int(sys.argv[2]), sys.argv[3]) else:
OpenSceneFromFile(sys.argv[1])
©2024 Boris FX, Inc. — UNOFFICIAL — Converted from original PDF.