How can I get a handle on Fusion point trackers? (API docs?)

Posted:
Wed Mar 03, 2021 2:50 pm
by Charles Duffy
Howdy --
I'm trying to figure out how to import a series of paths for a point tracker using the Fusion Python API (or if that's not feasible for some reason, Lua).
Unfortunately, if there's proper API documentation, I haven't found it yet -- all I'm seeing through the help menu is a directory with example code for very specific tasks. I've managed to get a handle on a manually-created Tracker object (albeit a roundabout way), but looking through its API using introspection (GetData, SetData, GetInput, SetInput...), there's nothing that's obviously suited to the task of "set position at frame N to X,Y", which is all I'm looking to do here.
Pointers -- at least, to the docs I should be reading?
Re: How can I get a handle on Fusion point trackers? (API do

Posted:
Mon Mar 08, 2021 1:59 am
by Charles Duffy
No luck at finding official API documentation for Resolve 17, but there are fortunately some quite good 3rd-party docs, YouTube tutorials, etc.
I'd still be a lot happier to find official, maintained documentation; but to provide pointers to anyone else finding this, I ended up using code akin to the following to import 2d trackers exported from SynthEyes with "Export" => "Plain Text" => "Tracker 2-d Paths":
- Code: Select all
if not 'tool' in locals():
tool = comp.ActiveTool
def rescalePointFn(fromRange=(-1,+1), toRange=(0,1), fromRangeX=None, fromRangeY=None, toRangeX=None, toRangeY=None):
fromRangeX = fromRangeX or fromRange
fromRangeY = fromRangeY or fromRange
toRangeX = toRangeX or toRange
toRangeY = toRangeY or toRange
fromScaleX = fromRangeX[1] - fromRangeX[0]
fromOffX = fromRangeX[0]
toScaleX = toRangeX[1] - toRangeX[0]
toOffX = toRangeX[0]
fromScaleY = fromRangeY[1] - fromRangeY[0]
fromOffY = fromRangeY[0]
toScaleY = toRangeY[1] - toRangeY[0]
toOffY = toRangeY[0]
def fn(x, y):
# map from original range to (0,1)
x += (0 - fromOffX)
y += (0 - fromOffY)
x *= (1 / fromScaleX)
y *= (1 / fromScaleY)
# map from (0,1) to target range
x *= toScaleX
y *= toScaleY
x += toOffX
y += toOffY
return x, y
return fn
def importPoints(filename, trackerName, destInput, startFrame=None, endFrame=None, ignoreValues=None, **args):
rescaleFn = rescalePointFn(**args)
try:
comp.Lock()
comp.StartUndo("Import points from file")
with open(filename, 'rt') as f:
for line in f:
pieces = line.strip().split(' ')
name = pieces[0]
if trackerName != name:
continue
flags = int(pieces[4])
if flags == 0:
continue
frame = int(pieces[1])
if startFrame is not None and frame < startFrame:
continue
if endFrame is not None and frame > endFrame:
continue
x = float(pieces[2])
y = float(pieces[3])
if ignoreValues is not None and (x,y) == ignoreValues:
continue
x, y = rescaleFn(x, y)
destInput[frame] = {1: x, 2: y, 3: 0}
comp.EndUndo(True)
finally:
comp.Unlock()
Some notes:
- The mouseover status-bar text when looking at the inspector provides the names which can be used to look items up from the scripting interface (so the function can be passed `tool["Center"]`, f/e, if `Center` is shown in that bar).
- Note that, from Python, points can't be mutated in-place -- they need to be replaced with new objects.