Skip to content

Commit

Permalink
Added photo caption labelling option
Browse files Browse the repository at this point in the history
  • Loading branch information
colin0brass committed Oct 23, 2022
1 parent 02008ea commit 836d185
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 75 deletions.
14 changes: 8 additions & 6 deletions FaceLabellingExport.lrplugin/FLEExifToolAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ function FLEExifToolAPI.closeSession(handle)
end

--------------------------------------------------------------------------------
-- ExifTool get Face Regions
-- ExifTool get Face Regions and Photo Info

function FLEExifToolAPI.getFaceRegionsList(handle, photoFilename)
function FLEExifToolAPI.getFaceRegionsAndPhotoInfo(handle, photoFilename)
local success = true -- initial value
local queryResults = nil -- initial value
local personTags = {} -- initial value
local photoSize = {} -- initial value
local photoDescription = '' -- initial value

-- Define which fields to retrieve from EXIF using ExifTool and custom config (script) file
local exif_command = '-struct -j -RegionsAbsoluteNotFocus'
local exif_command = '-struct -j -RegionsAbsoluteNotFocus -Description -ImageWidth'
if logger.get_log_level() >= 5 then -- get more information to help with debug
exif_command = exif_command .. ' -ImageWidth -ImageHeight -RegionsCentred -AlreadyApplied -Orientation'
exif_command = exif_command .. ' -RegionsCentred -AlreadyApplied -ImageHeight -Orientation'
end

success = _exifTool_send_command(handle, exif_command)
Expand All @@ -104,11 +105,12 @@ function FLEExifToolAPI.getFaceRegionsList(handle, photoFilename)
else
logger.writeTable(5, results) -- write to log for debug
personTags, photoSizes = _extract_face_regions(results[1])
photoDescription = utils.ifnil(results[1].Description, '')
end
end
end

return personTags, photoSizes
return personTags, photoSizes, photoDescription
end

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -152,9 +154,9 @@ function _extract_face_regions(results)
local photoSize = {}

logger.writeLog(3, "_extract_face_regions")
photoSize.width = results.ImageWidth
if results.RegionsAbsoluteNotFocus then
local regionsInfo = results.RegionsAbsoluteNotFocus
photoSize.width = regionsInfo.ImageInfo.ImageWidth
photoSize.height = regionsInfo.ImageInfo.ImageHeight
photoSize.orient = regionsInfo.ImageInfo.Orientation
photoSize.CropX = utils.ifnil(regionsInfo.ImageInfo.CropX, 0)
Expand Down
179 changes: 179 additions & 0 deletions FaceLabellingExport.lrplugin/FLEExportDialogs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ function exportLabeledImageView(f, propertyTable)
value = bind 'draw_label_boxes',
enabled = bind 'label_image',
},
f:checkbox {
title = LOC "$$$/FaceLabelling/ExportDialog/ImageLabelBoxes=Draw caption text",
value = bind 'draw_caption_text',
enabled = bind 'label_image',
},
}, -- group_box
f:group_box {
title = LOC "$$$/FaceLabelling/ExportDialog/ImageFilenameOptions=Obfuscation options",
Expand Down Expand Up @@ -885,6 +890,174 @@ function exportLabellingView(f, propertyTable)
return result
end

--------------------------------------------------------------------------------
-- dialog section for export labeled image caption config

function exportCaptionView(f, propertyTable)
local bind = LrView.bind
local share = LrView.share

-- expand simple list to list of tuples (title, value) for menu display
local list = {'below', 'above'}
local menu_positions_list = {}
for i, list_value in pairs(list) do
menu_positions_list[i] = {title=list_value, value=list_value}
end

-- expand simple list to list of tuples (title, value) for menu display
local list = { 'white', 'black', 'blue', 'red', 'green', 'grey' }
local menu_colour_list = {}
for i, list_value in pairs(list) do
menu_colour_list[i] = {title=list_value, value=list_value}
end

result = f:group_box { -- caption config
title = "Caption format options",
f:row {
fill_horizontal = 1,

f:column {
fill_horizontal = 0.3,
f:static_text {
title = 'Caption options:',
enabled = bind 'caption_image',
},
}, -- column

f:column {
fill_horizontal = 0.3,
f:group_box { -- Caption options
title = "Caption format options",
-- fill_horizontal = 1,
f:static_text {
title = 'Caption position:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:popup_menu {
items = menu_positions_list,
value = bind 'caption_position',
tooltip = "Caption position",
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
place_horizontal = 0.1,
},
f:static_text {
title = 'Caption font size:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:row {
f:edit_field {
width_in_digits = 3,
place_horizontal = 0.1,
min = 1,
max = 100,
precision = 0,
increment = 1,
value = bind('caption_font_size_fixed'),
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
tooltip = "Caption font size",
},
f:slider {
min = 1,
max = 100,
integral = true,
value = bind('caption_font_size_fixed'),
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
tooltip = "Caption font size",
place_vertical = 0.5,
width = 50
},
}, -- row
}, -- group_box
}, -- column

f:column {
f:group_box { -- Caption format options
title = "Caption format options",
-- fill_horizontal = 1,

f:static_text {
title = 'Caption font line width:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:row {
f:edit_field {
width_in_digits = 2,
place_horizontal = 0.5,
min = 1,
max = 10,
precision = 0,
increment = 1,
value = bind('caption_font_line_width'),
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
tooltip = 'Caption font line width',
},
f:slider {
min = 1,
max = 10,
integral = true,
value = bind('caption_font_line_width'),
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
tooltip = 'Caption font line width',
place_vertical = 0.5,
width = 50,
},
}, -- row
f:static_text {
title = 'Caption font colour:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:popup_menu {
items = menu_colour_list,
value = bind 'caption_font_colour',
place_horizontal = 0.5,
tooltip = "Caption font colour",
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:static_text {
title = 'Caption background colour:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:popup_menu {
items = menu_colour_list,
value = bind 'caption_background_colour',
place_horizontal = 0.5,
tooltip = "Caption background colour",
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:static_text {
title = 'Caption font type:',
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
},
f:popup_menu {
items = LrView.bind { key = 'font_list',
transform = function( value, fromTable )
if fromTable then return list_to_menu(value, caption_font_type) end
return LrBinding.kUnsupportedDirection -- to avoid updating the property table
end,
},
value = bind 'caption_font_type',
place_horizontal = 0.5,
enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
tooltip = 'Font type, from available system fonts'
},
-- f:static_text {
-- title = 'Caption undercolour:',
-- enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
-- },
-- f:static_text {
-- title = bind 'caption_undercolour',
-- place_horizontal = 0.5,
-- enabled = LrBinding.andAllKeys( 'label_image', 'draw_caption_text'),
-- tooltip = 'Background colour behind caption'
-- },
}, -- group_box
}, -- column
}, -- row
} -- group_box; caption config

return result
end

--------------------------------------------------------------------------------
-- dialog section for dynamic label options

Expand Down Expand Up @@ -1623,6 +1796,12 @@ function FLEExportDialogs.sectionsForBottomOfDialog( f, propertyTable )
exportLabellingView(f, propertyTable),
}, -- view

f:separator { fill_horizontal = 1 },
f:view {
fill_horizontal = 1,
exportCaptionView(f, propertyTable),
}, -- view

f:separator { fill_horizontal = 1 },
f:view {
fill_horizontal = 1,
Expand Down
94 changes: 52 additions & 42 deletions FaceLabellingExport.lrplugin/FLEInitPlugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,57 +103,67 @@ manager_table = {
--------------------------------------------------------------------------------
preference_table = {
-- Export preferences
{ key = 'label_image', default = true },
{ key = 'draw_label_text', default = true },
{ key = 'draw_face_outlines', default = false },
{ key = 'draw_label_boxes', default = false },
{ key = 'crop_image', default = true },
{ key = 'label_image', default = true },
{ key = 'draw_label_text', default = true },
{ key = 'draw_face_outlines', default = false },
{ key = 'draw_label_boxes', default = false },
{ key = 'draw_caption_text', default = false },
{ key = 'crop_image', default = true },

-- Obfuscation preferences
{ key = 'obfuscate_labels', default = false },
{ key = 'obfuscate_image', default = false },
{ key = 'remove_exif', default = true },
{ key = 'obfuscate_labels', default = false },
{ key = 'obfuscate_image', default = false },
{ key = 'remove_exif', default = true },

-- Labelling preferences - font
{ key = 'font_type', default = MAC_ENV and 'Courier' or 'Courier-New' },
{ key = 'font_type', default = MAC_ENV and 'Courier' or 'Courier-New' },
{ key = 'font_list', default = {} },
{ key = 'label_size_option', default = 'LabelDynamicFontSize' },
{ key = 'label_font_size_fixed', default = 60 },
{ key = 'font_colour', default = 'white' },
{ key = 'label_undercolour', default = '#00000080' },
{ key = 'font_line_width', default = 1 },
{ key = 'test_label', default = 'Test Label' }, -- used to determine label font size
{ key = 'label_width_to_region_ratio_small', default = 1.5 },
{ key = 'label_width_to_region_ratio_large', default = 0.5 },
{ key = 'image_width_to_region_ratio_small', default = 20 },
{ key = 'image_width_to_region_ratio_large', default = 1 },
{ key = 'label_size_option', default = 'LabelDynamicFontSize' },
{ key = 'label_font_size_fixed', default = 60 },
{ key = 'font_colour', default = 'white' },
{ key = 'label_undercolour', default = '#00000080' },
{ key = 'font_line_width', default = 1 },
{ key = 'test_label', default = 'Test Label' }, -- used to determine label font size
{ key = 'label_width_to_region_ratio_small', default = 1.5 },
{ key = 'label_width_to_region_ratio_large', default = 0.5 },
{ key = 'image_width_to_region_ratio_small', default = 20 },
{ key = 'image_width_to_region_ratio_large', default = 1 },

-- Caption preferences
{ key = 'caption_position', default = 'below' },
{ key = 'caption_font_size_fixed', default = 60 },
{ key = 'caption_font_line_width', default = 1 },
{ key = 'caption_font_colour', default = 'black' },
{ key = 'caption_background_colour', default = 'white' },
{ key = 'caption_font_type', default = MAC_ENV and 'Courier' or 'Courier-New' },
-- { key = 'caption_undercolour', default = '#00000080' },

-- Labelling preferences - labels
{ key = 'label_auto_optimise', default = true },
{ key = 'label_outline_colour', default = 'red' },
{ key = 'face_outline_colour', default = 'blue' },
{ key = 'label_outline_line_width', default = 1 },
{ key = 'face_outline_line_width', default = 2 },
{ key = 'image_margin', default = 5 },
{ key = 'default_position', default = 'below' },
{ key = 'default_num_rows', default = 3 },
{ key = 'default_font_size_multiple', default = 1},
{ key = 'default_align', default = 'center' },
{ key = 'label_position_search', default = true },
{ key = 'label_num_rows_search', default = true },
{ key = 'label_font_size_search', default = true },
{ key = 'format_experiment_list', default = nil },
{ key = 'positions_experiment_list', default = nil },
{ key = 'num_rows_experiment_list', default = nil },
{ key = 'font_size_experiment_list', default = nil },
{ key = 'experiment_order', default = 'Pos/Rows/Font' },
{ key = 'experiment_loop_limit', default = 200, fixed = false},
{ key = 'label_auto_optimise', default = true },
{ key = 'label_outline_colour', default = 'red' },
{ key = 'face_outline_colour', default = 'blue' },
{ key = 'label_outline_line_width', default = 1 },
{ key = 'face_outline_line_width', default = 2 },
{ key = 'image_margin', default = 5 },
{ key = 'default_position', default = 'below' },
{ key = 'default_num_rows', default = 3 },
{ key = 'default_font_size_multiple', default = 1},
{ key = 'default_align', default = 'center' },
{ key = 'label_position_search', default = true },
{ key = 'label_num_rows_search', default = true },
{ key = 'label_font_size_search', default = true },
{ key = 'format_experiment_list', default = nil },
{ key = 'positions_experiment_list', default = nil },
{ key = 'num_rows_experiment_list', default = nil },
{ key = 'font_size_experiment_list', default = nil },
{ key = 'experiment_order', default = 'Pos/Rows/Font' },
{ key = 'experiment_loop_limit', default = 200, fixed = false},

-- Export thumbnails preferences
{ key = 'export_thumbnails', default = false },
{ key = 'export_thumbnails_if_unnamed', default = false },
{ key = 'thumbnails_filename_option', default = 'RegionNumber' },
{ key = 'thumbnails_folder_option', default = 'ThumbnailsThumbFolder' },
{ key = 'export_thumbnails', default = false },
{ key = 'export_thumbnails_if_unnamed', default = false },
{ key = 'thumbnails_filename_option', default = 'RegionNumber' },
{ key = 'thumbnails_folder_option', default = 'ThumbnailsThumbFolder' },
}

experiment_definitions = {
Expand Down
Loading

0 comments on commit 836d185

Please sign in to comment.