exiftool -RegionName>PersonInImage photo.jpg exiftool -RegionName>RegionPersonDisplayName photo.jpg
%Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { MyRegion => { Require => { 0 => 'RegionInfoMP', 1 => 'ImageWidth', 2 => 'ImageHeight', }, ValueConv => q{ my ($rgn, @newRgns); foreach $rgn (@{$val[0]{Regions}}) { my @rect = split /\s*,\s*/, $$rgn{Rectangle}; my %newRgn = ( Area => { X => $rect[0] + $rect[2]/2, Y => $rect[1] + $rect[3]/2, W => $rect[2], H => $rect[3], Unit => 'normalized', }, Name => $$rgn{PersonDisplayName}, Type => 'Face', ); push @newRgns, \%newRgn; } return { AppliedToDimensions => { W => $val[1], H => $val[2], Unit => 'pixel' }, RegionList => \@newRgns, }; }, }, MyRegionMP => { Require => 'RegionInfo', ValueConv => q{ my ($rgn, @newRgns); foreach $rgn (@{$val[0]{RegionList}}) { my @rect = @{$$rgn{Area}}{'X','Y','W','H'}; $rect[0] -= $rect[2]/2; $rect[1] -= $rect[3]/2; push @newRgns, { PersonDisplayName => $$rgn{Name}, Rectangle => join(', ', @rect), }; } return { Regions => \@newRgns }; }, }, }, ); 1; #end
exiftool -config ExifTool_config_convert_regions "-regioninfomp\<MyRegionMP"' photo.jpg
return { LrSdkVersion = 3.0, LrSdkMinimumVersion = 1.3, -- minimum SDK version required by this plug-in LrToolkitIdentifier = 'com.adobe.lightroom.sdk.helloworld', LrPluginName = LOC "$$$/PicasaFaceToTag/PluginName=Picasa Faces to Tags", -- Add the menu item to the Library menu. LrLibraryMenuItems = { { title = "Write Picasa Faces to Tags", file = "PersonInImage.lua"}, }, VERSION = { major=4, minor=1, revision=0, build=831116, }, }
--[[---------------------------------------------------------------------------- ------------------------------------------------------------------------------]] -- Access the Lightroom SDK namespaces. local LrTasks = import 'LrTasks' local LrProgressScope = import 'LrProgressScope' local LrApplication = import 'LrApplication' local catalog = LrApplication.activeCatalog() local photos = catalog:getTargetPhotos() local LrPathUtils = import 'LrPathUtils' local logger = import 'LrLogger'("lr") logger:enable('print') local function faceToTag() --[[Convert faces from picasa xmp tag to microsoft xmp ]] exeFile = LrPathUtils.child( _PLUGIN.path, "exiftool.exe" ) cfgFile = LrPathUtils.child( _PLUGIN.path, "ExifTool_config_convert_regions" ) redirect = LrPathUtils.getStandardFilePath('temp') .. "exiftool.stdout" local total = ( # catalog:getTargetPhotos() ) local exifArgs = {"-b -RegionName \>" .. redirect, --'-overwrite_original "-RegionName\>PersonInImage"', '-overwrite_original "-RegionName\>RegionPersonDisplayName"', '-config '..cfgFile..' -overwrite_original "-regioninfomp\<MyRegionMP"'} local progressScope = LrProgressScope{ title = "Write Picasa Faces to Tags", caption = "Updateting " .. total .. " photos." , } progressScope:setCancelable( true ) local parrent catalog:withWriteAccessDo("Create parrent keyword", function () parrent = catalog:createKeyword("names", {}, false, nil, true) --logger:debug("parrent keyword created: " .. tostring(parrent)) end) for completed, photo in ipairs(photos) do progressScope:setPortionComplete(completed, total) progressScope:setCaption("Updated " .. tostring(completed) .. " of " .. tostring(total) .. " photos") if progressScope:isCanceled() then progressScope:done() break end local path = photo:getRawMetadata('path') logger:debug(path) -- write filename to debug log for i,exifArg in ipairs(exifArgs) do local exeCmd ='"' .. exeFile.." "..exifArg.." "..path .. '"' local status = LrTasks.execute(exeCmd) if io.open(redirect):read() == nil then break end --check is there any names in the file --logger:debug(exeCmd) if status ~= 0 then logger:debug("Error "..exeCmd) progressScope:done() end end for name in io.lines(redirect) do if name ~= nil then -- check is there any pleople on photo logger:debug(name) catalog:withWriteAccessDo("Adding name keywords", function () local keyword = catalog:createKeyword(name, {}, true, parrent, true) logger:debug("keyword created: " .. tostring(keyword)) photo:addKeyword(keyword) --photo:setRawMetadata('personShown', keyword) --doesn't work logger:debug("keyword added: " .. name) end) end end end progressScope:done() end LrTasks.startAsyncTask(faceToTag)
Source: https://habr.com/ru/post/193946/
All Articles