ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: ajiekc905 on December 12, 2016, 09:03:19 AM

Title: get LensType inside my composite tag as a string
Post by: ajiekc905 on December 12, 2016, 09:03:19 AM
Hi.
I'm trying to get LensType tag inside my composite tag and then change it. The problem is for Panasonic raw files it works ok, but not for Olympus.
It looks like inside Olympus raw files it stored as some raw data, but exiftool automatically convert it when I use -LensType in cli.

A printed version of the tag looks "Lumix G Vario 100-300mm F4.0-5.6 Mega OIS"
Instead of it i got "2 09 10"

%Image::ExifTool::UserDefined = (

# Composite tags are added to the Composite table:
    'Image::ExifTool::Composite' => {
        LensShortName => {
            Require => {
                0 => 'LensType'
            },
            ValueConv => '
                $val[0] =~/([a-zA-Z]+)[^\d]*?([\d-]+).*(F[\d-\.]+)/;
                "$1 $2 $3";
                $val[0];
            '
        }
    },
);

Title: Re: get LensType inside my composite tag as a string
Post by: Hayo Baan on December 12, 2016, 10:58:24 AM
Correct, exiftool converts those lens codes using internal tables. I think there are ways you can use those translations yourself, but I would have to do some digging.
Title: Re: get LensType inside my composite tag as a string
Post by: Hayo Baan on December 12, 2016, 03:14:19 PM
I'm sure there are more elegant ways, but the good news is that yes, you should be able to get the string version instead of the three numbers, the bad news is that you'll have to write code that selects the particular output based on brand.

Something like this might work (haven't tested it) for you:
'Image::ExifTool::Composite' => {
        LensShortName => {
            Require => {
                0 => 'LensType'
                1 => 'Make'
            },
            ValueConv => '
               my $lt = $val[0];
               $lt = $olympusLensTypes{$lt} if ($val[1] eq "Olympus");
               $lt =~/([a-zA-Z]+)[^\d]*?([\d-]+).*(F[\d-\.]+)/;
                "$1 $2 $3";
            ',
        }
    }
Title: Re: get LensType inside my composite tag as a string
Post by: ajiekc905 on December 12, 2016, 06:15:35 PM
Unfortunately your code is not working for me.

Did a workaround for that using other tag.

        LensShortName => {
            Require => {
                0 => 'LensType',
                1 => 'Make'
            },
            Desire => {
                2 => 'LensModel',
            },


            ValueConv => '
                my $lt = $val[0];
                $lt = $val[2] if ($val[1]=~ m/^OLYMPUS/);
                $lt = "CANON " . $val[2] if ($val[1]=~ m/^Canon/);
                $lt =~/([a-zA-Z]+).*?([\d-]+).*[Ff\/]([\d-\.]+)/;
                "$1 $2 $3";
            ',
        }




Make                            : OLYMPUS IMAGING CORP.
Make                            : Panasonic
Make                            : Canon
Make                            : SAMSUNG
LensModel is absent in Panasonic raw files

For samsung there is no string version of tag. I got 3 instead Samsung NX 50-200mm F4-5.6 ED OIS
Title: Re: get LensType inside my composite tag as a string
Post by: Hayo Baan on December 13, 2016, 03:16:08 AM
Hmm, I looked a bit deeper into this and my hack didn't work because you can not access the olympusLensTypes tables from outside the olympus module within exiftool (its a local variable). But I found a much simpler approach, you can actually get the converted (print) value of each of the input variables. Instead of $val you just need to use $prt. This leads to the following much simplified code:
        LensShortName => {
            Groups => { 2 => 'Camera' },
            Require => 'LensID',
            ValueConv => q{
               $prt[0] =~ /([a-zA-Z]+).*?([\d-]+)mm.*?[Ff\/]+([\d-\.]+)/ ? "$1 $2 $3" : $prt[0];
            },
        },

Note: you may need to perform some more trickery to get the "brand" correct. Nikon lenses for instance have e.g. AF-S at the front so above simple version will give AF instead of Nikkor for the brand. But I'm sure you can find ways to fix that ;)

Note: I use LensID instead of LensType as the LensID has the most complete lens data (LensType isn't always the lens, but e.g. in case of Nikon is the type of the lens – a combination of AF, MF, G, D, and VR designations).
Title: Re: get LensType inside my composite tag as a string
Post by: ajiekc905 on December 13, 2016, 05:20:44 AM
Super!

       LensShortName => {
            Groups => { 2 => 'Camera' },
            Require => 'LensID',
            ValueConv => q{
               $prt[0] =~ /([a-zA-Z]+).*?([\d-]+).*?[Ff\/]+([\d-\.]+)/;
               my $name = "$1 $2 F$3";
               $name=~ tr/a-z/A-Z/;
               $name;
            },
        },


Works perfect!