ROI to Crop
Posted in: NUKE from The FoundryI am trying to get the ROI square values and convert them to Crop values.
The funny thing is that ROI values ar from -1 to 1, so you have to multiply them with the width and height of the frame and taking into account the pixel aspect …
It sounds reaaaaally easy, but got allwas wrong results ….
I attach here the code I have so far, any help would be welcomed!!!
n= nuke.ViewerWindow.node(nuke.activeViewer()).input(nuke.ViewerWindow.activeInput(nuke.activeViewer()))
viewedNode = [n, n['xpos'].value(), n['ypos'].value(), n.width(), n.height(), int(nuke.value(n.name()+".actual_format.pixel_aspect"))]
#get roi
viewer = nuke.ViewerWindow.node(nuke.activeViewer())
roi = viewer['roi'].value()
crop = [((roi[0]+1)/2)*viewedNode[3], \
(((roi[1]+1)/2*viewedNode[5])*viewedNode[4])-(viewedNode[4]/2*(viewedNode[5]-1)) , \
((roi[2]+1)/2)*viewedNode[3], \
(((roi[3]+1)/2*viewedNode[5])*viewedNode[4])-(viewedNode[4]/2*(viewedNode[5]-1)) ]
#Create nodes and render
##Crop node
cropNode = nuke.createNode('Crop', 'name cropROI', inpanel = False)
cropNode['box'].setValue([crop[0], crop[1], crop[2], crop[3]])
Post a Comment