@@ -43,12 +43,14 @@ This plugin will add a new storage option and calls face_recognition after expor
43
43
local dt = require " darktable"
44
44
local du = require " lib/dtutils"
45
45
local df = require " lib/dtutils.file"
46
+ local dtsys = require " lib/dtutils.system"
46
47
local gettext = dt .gettext
47
48
48
49
-- constants
49
50
50
51
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"
52
54
53
55
-- namespace
54
56
81
83
local function build_image_table (images )
82
84
local image_table = {}
83
85
local file_extension = " "
84
- local tmp_dir = dt .configuration .tmp_dir .. " / "
86
+ local tmp_dir = dt .configuration .tmp_dir .. PS
85
87
local ff = fc .export_format .value
86
88
local cnt = 0
87
89
@@ -134,13 +136,13 @@ local function do_export(img_tbl)
134
136
exporter .max_width = width
135
137
136
138
-- 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 )
138
140
local exp_cnt = 0
139
141
local percent_step = 1.0 / images
140
142
job .percent = 0.0
141
143
for img ,export in pairs (img_tbl ) do
142
144
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 ) )
144
146
exporter :write_image (img , export , upsize )
145
147
job .percent = job .percent + percent_step
146
148
end
@@ -172,7 +174,7 @@ local function ignoreByTag (image, ignoreTags)
172
174
if string.find (t .name , it , 1 , true ) then
173
175
-- The image has ignored tag attached
174
176
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 )
176
178
end
177
179
end
178
180
end
@@ -213,7 +215,7 @@ local function face_recognition ()
213
215
ignoreTags = {}
214
216
for tag in string.gmatch (ignoreTagString , ' ([^,]+)' ) do
215
217
table.insert (ignoreTags , tag )
216
- dt .print_error (" Face recognition: Ignore tag: " .. tag )
218
+ dt .print_log (" Face recognition: Ignore tag: " .. tag )
217
219
end
218
220
219
221
-- list of exported images
@@ -239,7 +241,7 @@ local function face_recognition ()
239
241
dt .print_log (" Face recognition: Running command: " .. command )
240
242
dt .print (_ (" Starting face recognition..." ))
241
243
242
- dt . control . execute (command )
244
+ dtsys . external_command (command )
243
245
244
246
-- Open output file
245
247
local f = io.open (OUTPUT , " rb" )
@@ -379,32 +381,40 @@ fc.execute = dt.new_widget("button"){
379
381
end
380
382
}
381
383
382
- fc .widget = dt .new_widget (" box" ){
383
- orientation = vertical ,
384
+ local widgets = {
384
385
dt .new_widget (" label" ){ label = _ (" unknown person tag" )},
385
386
fc .unknown_tag ,
386
387
dt .new_widget (" label" ){ label = _ (" togs of images to ignore" )},
387
388
fc .ignore_tags ,
388
389
dt .new_widget (" label" ){ label = _ (" face data directory" )},
389
390
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 ,
405
391
}
406
392
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")
408
418
409
419
-- Register
410
420
-- dt.register_storage("module_face_recognition", _("Face recognition"), show_status, face_recognition)
@@ -420,5 +430,7 @@ dt.register_lib(
420
430
nil -- view_leave
421
431
)
422
432
433
+ fc .tolerance .value = dt .preferences .read (MODULE , " tolerance" , " float" )
434
+
423
435
--
424
436
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
0 commit comments