Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

javascript - Object Selection with Photoshop scripting

I need to be able to auto select humans in a big number of images. I know their coordinates, width and height, but would ideally prefer to have a more humanoid selection, and it seems to work great via normal object selection via the interface. Now I am wondering if I can do it with Photoshop scripting? Any clues appreciated!

To clarify I'm talking about the Object Selection Tool introduced recently here.

Thanks everyone!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I managed to get this working. In case anyone is interested:

Assuming the coordinates of the bounding box (top, left, bottom, right) are found.

var idset = stringIDToTypeID( "set" );
var desc4 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );

var ref3 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
var idselection = stringIDToTypeID( "selection" );
ref3.putProperty( idchannel, idselection );
desc4.putReference( idnull, ref3 );

var idto = stringIDToTypeID( "to" );
    var desc5 = new ActionDescriptor();
    var idtop = stringIDToTypeID( "top" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idtop, idpixelsUnit, top );
    var idleft = stringIDToTypeID( "left" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idleft, idpixelsUnit, left );
    var idbottom = stringIDToTypeID( "bottom" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idbottom, idpixelsUnit, bottom );
    var idright = stringIDToTypeID( "right" );
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    desc5.putUnitDouble( idright, idpixelsUnit, right );
    
var idrectangle = stringIDToTypeID( "rectangle" );
desc4.putObject( idto, idrectangle, desc5 );
var iddeepSelect = stringIDToTypeID( "deepSelect" );
desc4.putBoolean( iddeepSelect, true );
var idobjectSelectionMode = stringIDToTypeID( "objectSelectionMode" );
desc4.putInteger( idobjectSelectionMode, 0 );
var idmagicLassoAutoEnhance = stringIDToTypeID( "magicLassoAutoEnhance" );
desc4.putBoolean( idmagicLassoAutoEnhance, true );
var idsmartSubtract = stringIDToTypeID( "smartSubtract" );
desc4.putBoolean( idsmartSubtract, true );
executeAction( idset, desc4, DialogModes.NO );

These codes can be obtained via the ScriptingListener (available here)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...