import nuke

cornerPinMatrix = nuke.math.Matrix4()
node = nuke.selectedNode()
#node = nuke.toNode('CornerPin2D2')· # Replace with the node object of a cornerPin node of your choice
 
# Get image width and height to normalize the format to a 0,0,1,1 square
imageWidth = float(node.width())
imageHeight = float(node.height())

time =0

while time < 100:
    vectors = []
    for f in sorted(node.knobs().keys()):
        if f.startswith('to'):
#            print f
#           print node[f].getValueAt(time)
            vectors.append(nuke.math.Vector2(node[f].getValueAt(time,0)/imageWidth, node[f].getValueAt(time,1)/imageHeight))
                           
    print "vectors", vectors
            # Feed all 4 coordinates into the mapUnitSquareToQuad() function
    cornerPinMatrix.mapUnitSquareToQuad(vectors[0].x, vectors[0].y, vectors[1].x, vectors[1].y, vectors[2].x, vectors[2].y, vectors[3].x, vectors[3].y)
             
            # Test the matrix
    screenCenter = nuke.math.Vector4(0.5,0.5,0,1) # Define a point at the center of the screen
            # Using Vector4 since the matrix will do
            # the equivalent of a perspective projection
             
    transformedPoint = cornerPinMatrix.transform(screenCenter)
             
    transformedCoordinates = ((transformedPoint.x/transformedPoint.w)*imageWidth, (transformedPoint.y/transformedPoint.w)*imageHeight)
             
    print "frame: ", time, "\ncpinmatrix ", cornerPinMatrix, "\ntranf coordinates:", transformedCoordinates, "\n"
        
    time+=1

 
 