removing specific face regions

Started by bungaman, March 09, 2024, 12:04:59 PM

Previous topic - Next topic

bungaman

I was reading the following message thread and StarGeek's response.
https://exiftool.org/forum/index.php?msg=67665

I did an export of the region structure:
exiftool -json -struct -regioninfo '0697_05_3.jpg' >region.json
Then I edited the json file to remove some of the regions - so now the json looks like:
[file name: region3.json]

[{
  "SourceFile": "*",
  "RegionInfo": {
    "AppliedToDimensions": {
      "H": 1770,
      "Unit": "pixel",
      "W": 1169
    },
    "RegionList": [{
      "Area": {
        "H": 0.0728813559322034,
        "Unit": "normalized",
        "W": 0.0898203592814371,
        "X": 0.370402053036784,
        "Y": 0.58361581920904
      },
      "Name": "Person3",
      "Type": "Face"
    },{
      "Area": {
        "H": 0.0740112994350283,
        "Unit": "normalized",
        "W": 0.0915312232677502,
        "X": 0.484174508126604,
        "Y": 0.390960451977401
      },
      "Name": "Person4",
      "Type": "Face"
    }]
  }
}]

All good so far, but running into the following error when I try to write that new info back to the image with:
exiftool -j='region3.json' 0697_05_3.jpg
Format error in JSON file 'JSON file'
No SourceFile '0697_05_3.jpg' in imported JSON database
(full path: 'c:/temp/test1/dup3/0697_05_3.jpg')

I have tried putting full path sourcefile into the JSON file, just filename, and also wildcard *. All give same error message. There is something really easy I'm sure I'm missing!

Version 12.65 on Windows with Powershell.


StarGeek

Your command and example JSON work correctly here in both CMD and PowerShell.  I used both the asterisk as in your example and with a filepath that used slashes, which is what exiftool outputs.

The only way I could duplicate the error is if I used backslashes in the filename
  "SourceFile": "y:\!temp\Test4.jpg",
I think the problem there is the backslashes are escape codes (not overly familiar with JSON, so unsure).  If I double them, then it works correctly
  "SourceFile": "y:\\!temp\\Test4.jpg",
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bungaman

thanks for the quick response.

this is still stumping me... have tried forward slash, escaped back slash, and asterisk in the sourcefile line... and filename only and full path and wildcard, and quotes (both single and double) around the filename on the command line. even removed the underscore from the filename. still get the exact same error. baffling. there has to be a simple explanation :o

i'll try on my mac.

StarGeek

Ah, the problem might be PowerShell. PowerShell messes with any redirection or piping of data, so the json file might be UTF16, where exiftool wants UTF8.

Try running your first command to create the JSON in CMD and see if that JSON file works.

If you use a text editor like Notepad++, it has an option to convert to UTF8.

Or see this SuperUser question for some options.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bungaman

same thing on my Mac.

i upgraded both mac and windows to latest exiftool.

i went back to the original command line on windows:
exiftool -json -struct -regioninfo '0697-05-1.jpg' >regiontest.json
generated a new json file. immediately turned around and submitted that back to the image:

exiftool -json='regiontest.json' 0697-05-1.jpg
Format error in JSON file 'JSON file'
No SourceFile '0697-05-1.jpg' in imported JSON database
(full path: 'c:/temp/test1/dup1/0697-05-1.jpg')

ok, then i did the same thing on the Mac. finally that worked. so there is something with the json file creation in powershell OR the handling of the json input on the Windows side of things. very strange.



bungaman

Ok, thanks StarGeek!

That powershell conversion did the trick.

powershell "Get-Content 'regiontest.json' | Out-File 'regionascii.json' -Encoding ascii"

StarGeek

Quote from: bungaman on March 09, 2024, 05:37:59 PMso there is something with the json file creation in powershell OR the handling of the json input on the Windows side of things. very strange.

Yes, when redirecting PS output through a Pipe | or file redirection </>, PS "helps" by converting the output to UTF16. It's bad enough for text but even worse if you try to exact binary data, such as a thumbnail or preview image.  The output is totally corrupted.

There are other things that are bad about PS.  I get why sysadmins love it, but there's a lot of stuff it gets wrong.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).