Skip to content

Commit 10b5dee

Browse files
committed
Added windows compatibility
1 parent be48459 commit 10b5dee

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

contrib/face_recognition.lua

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ This plugin will add a new storage option and calls face_recognition after expor
4343
local dt = require "darktable"
4444
local du = require "lib/dtutils"
4545
local df = require "lib/dtutils.file"
46+
local dtsys = require "lib/dtutils.system"
4647
local gettext = dt.gettext
4748

4849
-- constants
4950

5051
local MODULE = "face_recognition"
51-
local OUTPUT = dt.configuration.tmp_dir .. "/facerecognition.txt"
52+
local PS = dt.configuration.running_os == "windows" and '\\' or '/'
53+
local OUTPUT = dt.configuration.tmp_dir .. PS .. "facerecognition.txt"
5254

5355
-- namespace
5456

@@ -81,7 +83,7 @@ end
8183
local function build_image_table(images)
8284
local image_table = {}
8385
local file_extension = ""
84-
local tmp_dir = dt.configuration.tmp_dir .. "/"
86+
local tmp_dir = dt.configuration.tmp_dir .. PS
8587
local ff = fc.export_format.value
8688
local cnt = 0
8789

@@ -134,13 +136,13 @@ local function do_export(img_tbl)
134136
exporter.max_width = width
135137

136138
-- export the images
137-
local job = dt.gui.create_job("export images", true, stop_job)
139+
local job = dt.gui.create_job(_("export images"), true, stop_job)
138140
local exp_cnt = 0
139141
local percent_step = 1.0 / images
140142
job.percent = 0.0
141143
for img,export in pairs(img_tbl) do
142144
exp_cnt = exp_cnt + 1
143-
dt.print(_("Exporting image") .. exp_cnt .. _(" of ") .. images)
145+
dt.print(string.format(_("Exporting image %i of %i images"), exp_cnt, images))
144146
exporter:write_image(img, export, upsize)
145147
job.percent = job.percent + percent_step
146148
end
@@ -172,7 +174,7 @@ local function ignoreByTag (image, ignoreTags)
172174
if string.find (t.name, it, 1, true) then
173175
-- The image has ignored tag attached
174176
ignoreImage = true
175-
dt.print_error ("Face recognition: Ignored tag: " .. it .. " found in " .. image.id .. ":" .. t.name)
177+
dt.print_log ("Face recognition: Ignored tag: " .. it .. " found in " .. image.id .. ":" .. t.name)
176178
end
177179
end
178180
end
@@ -213,7 +215,7 @@ local function face_recognition ()
213215
ignoreTags = {}
214216
for tag in string.gmatch(ignoreTagString, '([^,]+)') do
215217
table.insert (ignoreTags, tag)
216-
dt.print_error ("Face recognition: Ignore tag: " .. tag)
218+
dt.print_log ("Face recognition: Ignore tag: " .. tag)
217219
end
218220

219221
-- list of exported images
@@ -239,7 +241,7 @@ local function face_recognition ()
239241
dt.print_log("Face recognition: Running command: " .. command)
240242
dt.print(_("Starting face recognition..."))
241243

242-
dt.control.execute(command)
244+
dtsys.external_command(command)
243245

244246
-- Open output file
245247
local f = io.open(OUTPUT, "rb")
@@ -379,32 +381,40 @@ fc.execute = dt.new_widget("button"){
379381
end
380382
}
381383

382-
fc.widget = dt.new_widget("box"){
383-
orientation = vertical,
384+
local widgets = {
384385
dt.new_widget("label"){ label = _("unknown person tag")},
385386
fc.unknown_tag,
386387
dt.new_widget("label"){ label = _("togs of images to ignore")},
387388
fc.ignore_tags,
388389
dt.new_widget("label"){ label = _("face data directory")},
389390
fc.known_image_path,
390-
dt.new_widget("section_label"){ label = _("processing options")},
391-
fc.tolerance,
392-
fc.num_cores,
393-
fc.export_format,
394-
dt.new_widget("box"){
395-
orientation = "horizontal",
396-
dt.new_widget("label"){ label = _("width")},
397-
fc.width,
398-
},
399-
dt.new_widget("box"){
400-
orientation = "horizontal",
401-
dt.new_widget("label"){ label = _("height")},
402-
fc.height,
403-
},
404-
fc.execute,
405391
}
406392

407-
fc.tolerance.value = dt.preferences.read(MODULE, "tolerance", "float")
393+
if dt.configuration.running_os == "windows" or dt.configuration.running_os == "macos" then
394+
table.insert(widgets, df.executable_path_widget({"face_recognition"}))
395+
end
396+
table.insert(widgets, dt.new_widget("section_label"){ label = _("processing options")})
397+
table.insert(widgets, fc.tolerance)
398+
table.insert(widgets, fc.num_cores)
399+
table.insert(widgets, fc.export_format)
400+
table.insert(widgets, dt.new_widget("box"){
401+
orientation = "horizontal",
402+
dt.new_widget("label"){ label = _("width ")},
403+
fc.width,
404+
})
405+
table.insert(widgets, dt.new_widget("box"){
406+
orientation = "horizontal",
407+
dt.new_widget("label"){ label = _("height ")},
408+
fc.height,
409+
})
410+
table.insert(widgets, fc.execute)
411+
412+
fc.widget = dt.new_widget("box"){
413+
orientation = vertical,
414+
table.unpack(widgets)
415+
}
416+
417+
--fc.tolerance.value = dt.preferences.read(MODULE, "tolerance", "float")
408418

409419
-- Register
410420
--dt.register_storage("module_face_recognition", _("Face recognition"), show_status, face_recognition)
@@ -420,5 +430,7 @@ dt.register_lib(
420430
nil -- view_leave
421431
)
422432

433+
fc.tolerance.value = dt.preferences.read(MODULE, "tolerance", "float")
434+
423435
--
424436
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua

0 commit comments

Comments
 (0)