import math, pfpy def pfNodeName(): return 'Hide bad points' def calcResidual(a, b): return math.sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])) def main(): # how many trackers? num= pfpy.getNumTrackers() # fetch the camera cam= pfpy.getCameraRef(0) # loop over every tracker idx= 0 while (idx < num): # fetch a reference to this tracker t= pfpy.getTrackerRef(idx) # is the tracker solved? if t.getSolved() : # fetch the tracker's 3D point position X= t.getSolvedPos() # loop over every frame inp= t.getInPoint(); outp= t.getOutPoint(); f= inp; while (f <= outp): # is the tracker visible in this frame? if t.getHidden(f) == False : # is the tracker infront of the camera? if cam.inFront(f, X) : # project the tracker into the camera proj= cam.project(f, X) # fetch the tracker position in the image pos= t.getTrackPosition(f) # calculate the distance between the points err= calcResidual(proj, pos) # more than two pixels difference? if err > 2.0 : # hide the tracker in this frame t.setHidden(f, True) print("Removed", t.getName(), "from frame", f, "error:", err) f += 1 idx += 1 print("Done")