Lens detection in certain images not working for some images

I have a substantial number of images taken with my Canon 30d that darktable fails to import the lens data for. It just reads n/a in the lens field

When I check the images with exiv2 -pt | grep -i lens I get this:

Exif.CanonCs.LensType                        Short       1  n/a
Exif.CanonCs.Lens                            Short       3  28.0 - 105.0 mm
Exif.CanonCf.LensAFStopButton                Short       1  2304
Exif.Canon.LensModel                         Ascii      64  EF28-105mm f/3.5-4.5 USM

When I check with exiftool | grep -i lens I have this:

Lens Type                       : n/a
Lens AF Stop Button             : AF stop
Lens Model                      : EF28-105mm f/3.5-4.5 USM
Lens Info                       : 28-105mm f/?
Saved Settings Parameters Lens Profile Enable: 0
Saved Settings Parameters Lens Manual Distortion Amount: 0
Saved Settings Parameters Lens Profile Setup: LensDefaults
Lens                            : 28.0 - 105.0 mm
Lens ID                         : Canon EF28-105mm f/3.5-4.5 USM
Lens                            : 28.0 - 105.0 mm (35 mm equivalent: 44.8 - 168.2 mm)

Is there something I can change in the images that will let darktable detect the lenses from these images?

Although I don’t (yet?) suffer this problem (perhaps because I’m a Nikon shooter?), it seems that others do. Well, at least one person does. This is why Bill Ferguson has apparently written a lua script to address this issue. Give it a shot to see what it does for you!

Thanks!

I took a look at that and what it seems to is fix lenses that were identified as A but should be identified as B. Since all of mine are identified as n/a with a variety of lenses I am not sure there is a good way to make that script work for me.

If I could determine what was missing it might be possible to write a script using exiftool but I am not familiar enough with darktable and exif to know what it needs to see.

So are there more than the 28-105 lens, or is that the only one?

There is more than one. Darktable brought most of the images from that time period in with n/a

Does anyone know what field/data darktable is reading to get the lens information?

I compared an image darktable can read to one that it cannot with both exiftool and exiv2 and I don’t see any obvious differences.

Since this seems to be an issue that only impacts older images in my collection I don’t have a problem with updating them via a script but I am not sure what data I would need to write to what field.

lensfun is used for lens correction and for the rest it should be exiv2.

Is the data correct in the exif? I could tweak a version to read the exif from the file and update the lens info.

It seems to be correct in the exif. The exif data is above in the first post. I wasn’t sure exactly what field in the exif needs to be populated.

It would be most excellent if there was a solution that could be scripted.

I think I found the cause of my issue.

darktable seems to use LensType over LensModel so even though LensModel appears to be set when I read the exif it isn’t being read properly by darktable because LensType is not set correctly on many of these older images.

I think I can fix that without too much trouble using exiftool now that I understand it better. Since it only impacts older images for me a one-time fix should solve my issue.