-
-
Save mstergiou/3192cf7e137090bc728229d08c47a405 to your computer and use it in GitHub Desktop.
[Import fSpy JSON to Nuke] load a json file with camera data from fSpy into Nuke for single frame camera alignment https://fspy.io/ #fspy #nuke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import nuke | |
def Matrix4toList(M): | |
mVals = [] | |
for i in range(len(M)): | |
mVals.append(M[i]) | |
return mVals | |
# --- load file --- | |
fp = nuke.getFilename("Select fSpy data file", "*.json") | |
with open(fp) as datafile: | |
data = json.load(datafile) | |
# --- create camera, set knobs | |
camera = nuke.createNode("Camera") | |
# camera transform | |
M = nuke.math.Matrix4() # camera pose | |
matrixVals = data["cameraTransform"]["rows"] | |
for row, values in enumerate(matrixVals): | |
rowStart = row * 4 | |
M[rowStart + 0] = values[0] | |
M[rowStart + 1] = values[1] | |
M[rowStart + 2] = values[2] | |
M[rowStart + 3] = values[3] | |
camera["useMatrix"].setValue(True) | |
camera["matrix"].setValue(Matrix4toList(M)) | |
# projection parameters | |
aspectRatio = float(data["imageWidth"]) / float(data["imageHeight"]) | |
camera["vaperture"].setExpression("haperture / {aspect}".format(aspect=aspectRatio)) | |
camera["focal"].setExpression("haperture / (2 * tan({hFOV} / 2))".format(hFOV=data["horizontalFieldOfView"])) | |
principal = data["principalPoint"] | |
camera["win_translate"].setValue([principal["x"], principal["y"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment