Extract an jpg image corresponding to the face detected area from digikam

Started by grimmo, February 23, 2020, 09:14:04 AM

Previous topic - Next topic

grimmo

Quote from: StarGeek on March 28, 2020, 11:08:45 AM
How about this.  Using your "Magick" command example

C:\>exiftool -config ImageMagickThumbMWG.config -g1 -a -s -IMCommandMWG  Y:\!temp\mmm\ACDsee-Regions_JSilva_092517_8623.jpg -b


Should it be-G1 instead of g1
exiftool -config ImageMagickThumbMWG.config -G1 -a -s -IMCommandMWG  Y:\!temp\mmm\ACDsee-Regions_JSilva_092517_8623.jpg -b

Then it runs, but still do not understand what it is supposed to do? Execute the magick commands you have pasted?

StarGeek

Quote from: grimmo on March 29, 2020, 07:38:28 AM
Should it be-G1 instead of g1
exiftool -config ImageMagickThumbMWG.config -G1 -a -s -IMCommandMWG  Y:\!temp\mmm\ACDsee-Regions_JSilva_092517_8623.jpg -b[/quote]

-G1 and -g1 have the same function but just a difference in the display (see -G (groupNames) option).  But in this command the whole -G1 -a -s is ignored due to the -b (binary) option.

QuoteThen it runs, but still do not understand what it is supposed to do? Execute the magick commands you have pasted?

No, this just constructs the the magick command for each of the regions.  Using your example command
exiftool -config ImageMagickThumbMWG.config  -IMCommandMWG  -b 100_2325.jpg.xmp > test/test.bat && test/test.bat

That would automatically create and run a bat file that would extract all the regions in the image.

Quote from: grimmo on March 29, 2020, 05:30:26 AM
Can't these normalized coordinates be addressed "column-like", if one knows which column is needed? In order just use the normalized spacial information for a certain person (e.g. RegionName=Chris).
If you find the value Chris at second position in RegionName then just feed the script with second position of RegionAreaW and RegionAreaH, RegionAreaX and RegionAreaY? Maybe even predefine this person's name inside the script.

I think that would require a separate script, using Windows batch, Powershell, or some other language for example,  to parse out the data and construct the command for you. 
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

grimmo

Many thanks StarGeek; I have a solution that works enough for me. There is room for improvements, but I am really not an experienced programmer and have not much time to fiddle at the moment.

So here is what works for me:
exiftool -config ImageMagickThumbMWG.config -T -ImageMagickThumbMWG *.xmp -w Person_thumbs/%f.txt
As explained I have xmp files with the face region inside, separated from the image file. Digikam uses the image file name including the format extension and saves it as a .xmp file. So this command extracts with StarGeeks script the image region for each image with a associated xmp file and writes a .txt in a subfolder.

This image region can be extracted/read with the following command (rather script but I use as a command; found it somewhere) by ImageMagick and the face region gets cropped and saved in this subfolder.
First you search all the image files present (would be better to just handle the xmp files, but it still works):

list=$(ls *.jpg *.JPG)

then you have a list of all files

for img in $list; do name=$(magick $img -format "%t" info:); suffix=$(magick $img -format "%e" info:); magick $img -crop @Person_thumbs/${name}.${suffix}.txt "./Person_thumbs/Person_${name}.${suffix}"; done

In case you have more than one person tagged in an image, you just get the face of the first person in the txt file. Just delete the first face region and rerun the last command and you get the second face.

grimmo

Hi again

I have some .dng files where I want to crop also the faces with the help of your script. The face tag info is again inside the sidecar file written by digikam. However for some reason there is no information for width and height of the .dng file inside this sidecar.

And I did not find any way to force digikam to write it.

However the size information can be read directly from the .dng
exiftool -s -ImageHeight IMGP0901.DNG
ImageHeight                     : 3300

Do you see some simple way to read the size info from the image file and the face tag info from the sidecar file and use it together in your script? I mean just two lines of eiftool code or so? I do not want you to modify your script again...

StarGeek

You could copy the width/height to the sidecar file
exiftool -TagsFromFile %d%f.dng -ImageHeight -ImageWidth -ext xmp /path/to/files/
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

grimmo

Thanks for your answer! One question, if I would copy this information several times, would then ImageWidth and Height appear several times in the xmp. I know I could try but maybe you already know the answer?

StarGeek

With the command above, ImageHeight/ImageWidth would be overwritten each time.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype