Awesome !
I had a play today as well; Here is a beta group node that worked
for the plates I had. Didn't test it properly yet.
I'll have a look at your code thanks Brian !
Cheers,
Justin
set cut_paste_input [stack 0]
version 9.0 v7
push $cut_paste_input
Group {
name JFX_OptBbox
tile_color 0xa373b5ff
selected true
xpos 1980
ypos 497
addUserKnob {20 User}
addUserKnob {52 embedded_callbacks l INVISIBLE -STARTLINE
+INVISIBLE T "#This hidden knob is only here to keep the indented
callback parts for further dev#\n#Though these lines are
converted in a single one and inserted directly in the .gizmo
file#\n\n#onKnobChanged#\n\n'''\n\n\n#OnCreate#\nthisNode =
nuke.thisNode()\nwith thisNode:\n
thisNode\['startFrame'].setValue(nuke.Root().firstFrame())\n
thisNode\['endFrame'].setValue(nuke.Root().lastFrame())\n\n\n'''"}
addUserKnob {3 startFrame l "Frame Range"}
addUserKnob {3 endFrame l "" -STARTLINE}
endFrame 100
addUserKnob {22 AutoScale l "<b>Auto - scale</b>" T "from
__future__ import with_statement\nimport sys\n\n\n\nthisNode =
nuke.thisNode()\nwith thisNode :\n\n thisNodeInput =
thisNode.input(0)\n cv =
nuke.toNode('CurveToolGenericOptBbox')\n tf =
nuke.toNode('TransformGenericOptBbox')\n\n safePixels = 3 # 3
pixels from the balck outside of the cornerpin that grow the bbox
+ 1 safe pixel\n first\t\t= thisNode\['startFrame'].value()\n
last\t\t= thisNode\['endFrame'].value()\n total \t\t=
int(last) - int(first)+1\n maxNum = 0\n max_x = 0\n max_y
= 0\n bbox_x_list = \[]\n bbox_y_list = \[]\n
bbox_r_list = \[]\n bbox_t_list = \[]\n bbox_dict = \{\}\n
f_x = thisNodeInput.format().x()\n f_y =
thisNodeInput.format().y()\n f_r =
thisNodeInput.format().r()\n f_t =
thisNodeInput.format().t()\n formatRatio = (f_r - f_x)/(f_t -
f_y)\n tf\['center'].setValue((f_r - f_x)/2,0)\n
tf\['center'].setValue((f_t - f_y)/2,1)\n optScaleFactor = 1\n
progress \t= 0\n progressBar \t= nuke.ProgressTask(\"Getting
bbox...\")\n\n \n for frame in range(int(first),
int(last)+1):\n\n # Executing a CurveTool node is just to
force the viewer to update so we can analyse on a range of
frames.\n nuke.execute(cv.name
<http://cv.name>(),start=frame,end=frame)\n
#nuke.Root().setFrame( frame )\n #time.sleep( 0.1 )\n
#nuke.updateUI\n x = int(thisNodeInput.bbox().x())\n y =
int(thisNodeInput.bbox().y())\n r =
int((thisNodeInput.bbox().w() + thisNodeInput.bbox().x()) )\n
t = int((thisNodeInput.bbox().h() + thisNodeInput.bbox().y())
)\n w = int(thisNodeInput.bbox().w())\n h =
int(thisNodeInput.bbox().h())\n\n\n bbox_dict\[frame] = \[x, y,
r, t, w, h]\n\n # ProgressBar\n if
progressBar.isCancelled():\n del progressBar\n
sys.exit()\n\n\n progress += 1\n
progressBar.setProgress(int((float(progress) / float(total))
*100))\n if (progress) >= total:\n del
progressBar\n\n \n for frame, val_list in
bbox_dict.iteritems():\n bbox_x_list.append(val_list\[0]-f_x)\n
bbox_y_list.append(val_list\[1]-f_y)\n
bbox_x_list.append(val_list\[2]-f_r)\n
bbox_y_list.append(val_list\[3]-f_t)\n\n \n\n if max(abs(i)
for i in bbox_x_list) >= max(abs(i) for i in
bbox_y_list)*formatRatio: \n maxNum = max(abs(i) for i in
bbox_x_list)\n for frame, val_list in
bbox_dict.iteritems():\n if (maxNum == (val_list\[0]-f_x)
or \n maxNum == -(val_list\[0]-f_x) or\n
maxNum == (val_list\[2]-f_r) or\n maxNum ==
-(val_list\[2]-f_r)):\n #optScaleFactor =
((val_list\[4]+ val_list\[2]+ val_list\[0])/(f_r - f_x))\n
\n \n optScaleFactor = ((val_list\[4]+
val_list\[0]*2)/(val_list\[4]))\n \n
tf\['center'].setValue((val_list\[2]+val_list\[0])/2,0)\n
tf\['center'].setValue((val_list\[3]+val_list\[1])/2,1)\n
print 'x'\n print frame\n
print (val_list\[0]-f_x, val_list\[1]-f_y, val_list\[2]-f_r,
val_list\[3]-f_t, val_list\[4], val_list\[5])\n
print (val_list\[0], val_list\[1], val_list\[2], val_list\[3],
val_list\[4], val_list\[5])\n print optScaleFactor\n else:\n
maxNum = max(abs(i) for i in bbox_y_list) \n for
frame, val_list in bbox_dict.iteritems():\n if (maxNum
== (val_list\[1]-f_y) or \n maxNum == -(val_list\[1]-f_y) or\n
maxNum == (val_list\[3]-f_t) or\n maxNum ==
-(val_list\[3]-f_t)):\n #optScaleFactor =
((val_list\[5]+val_list\[3]+val_list\[1]) /(f_t - f_y))\n
\n optScaleFactor =
((abs(val_list\[5])+abs((val_list\[1]*2))) /abs(val_list\[5]))\n
\n
tf\['center'].setValue((val_list\[2]+val_list\[0])/2,0)\n
tf\['center'].setValue((val_list\[3]+val_list\[1])/2,1)\n
print 'y'\n print frame\n
print (val_list\[0]-f_x, val_list\[1]-f_y, val_list\[2]-f_r,
val_list\[3]-f_t, val_list\[4], val_list\[5])\n
print (val_list\[0], val_list\[1], val_list\[2], val_list\[3],
val_list\[4], val_list\[5])\n print optScaleFactor\n\n\n\n
tf\['scale'].setValue(optScaleFactor)\n\n\n\n\n\n\n" +STARTLINE}
addUserKnob {26 ""}
addUserKnob {26 help_1 l "" +STARTLINE T "<div
style='color:#ffd200;'>Scale the image to get the
optimal<br/>\nbounding box for the indicated frame range.</div>"}
}
Input {
inputs 0
name Input1
xpos 0
}
Transform {
center {965 495}
shutteroffset centred
name TransformGenericOptBbox
xpos 0
ypos 139
}
Output {
name Output1
xpos 0
ypos 300
}
CurveTool {
inputs 0
ROI {480 270 1440 810}
autocropdata {480 270 1440 810}
intensitydata {{curve} {curve} {curve} 0.3067211802 <tel:3067211802>}
name CurveToolGenericOptBbox
xpos -179
ypos 122
}
end_group
2016-04-29 17:40 GMT+01:00 Brian Willard <br...@radarstudios.com
<mailto:br...@radarstudios.com>>:
I built a version of this the the other day using the
curveTool hack to sum the bbox across a range of frames. It
worked ok, but I noticed it didn't return the same values for
the bbox consistently.
A much faster method seems to be to shuffle black into the
rgba, then frameblend the range to get the bbox sum. After
that, increasing the scale in a reformat by 0.1 until the
summed bbox fits into the reformat's width & height. I'm
using a 2nd reformat expression linked to the 1st to return
to the original format size.
let me know if this is what you we're thinking of, or if you
have any suggestions!
https://gist.github.com/mybikeislost/3a28fbc5253b73f3db52160d655fe742
Brian
On Tue, Apr 26, 2016 at 3:37 AM, Justin GD
<j.grosde...@gmail.com <mailto:j.grosde...@gmail.com>> wrote:
Yep, thanks for your answers; I'll post it and will have
a look at it when I have more time !
Cheers,
J
2016-04-26 5:17 GMT+01:00 Frank Rueter|OHUfx
<fr...@ohufx.com <mailto:fr...@ohufx.com>>:
I reckon that's one for the nukepedia wishlist
<http://www.nukepedia.com/uncategorized/tool-wish-list>.
On 04/26/2016 02:46 PM, Mike Frank wrote:
What would really be magic is if a script knew the
optimal center point to scale from too.
On Apr 25, 2016 3:14 PM, "Frank Rueter|OHUfx"
<fr...@ohufx.com <mailto:fr...@ohufx.com>> wrote:
I have wanted to look into this for ever and
never had the time.
I reckon it should be totally possible with a
bit of math magic.
On 04/26/2016 01:42 AM, Justin GD wrote:
Hi all,
Is there a way to scale up a plate to the
optimal scale after stabilisation ?
What I want is the bbox to always be bigger
than my format. I can scale up by hand but I
was just wondering if there was an automatic
way of doing this (expressions?).
Cheers,
Justin
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users