Author Topic: Assign lens focal length and name for non cpu lenses  (Read 19764 times)

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Assign lens focal length and name for non cpu lenses
« on: October 29, 2016, 12:04:45 PM »
If we can assign lens focal length and name for non cpu lenses, ( like using nikon lenses on a canon with an adapter) then I can use this data in post processing to identify what lens was used and which lens profile I should apply for distortion correction.

Nikon has something like this and It saves me to manually write down all the lenses used per shot.




dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #1 on: October 29, 2016, 01:58:11 PM »
Interesting. I used Nikons when I was making a living in photography (too many years ago) and never had to replace my old lenses, just get them modified to AI for metering on newer bodies.

That Nikon feature you are pointing out only works with Nikon bodies and F-mount lenses and is designed to allow metering through the camera while keeping the aperture wide open until the moment of exposure. Canon EF doesn't use any mechanical coupling so if you adapt a Nikon lens to a Canon body the lens stops down as you close the aperture. This is something desirable in time-lapse and stop motion animation because it eliminates mechanically induced flicker.

However, what you want is for the lens information to be saved in the metadata. It doesn't seem like this Nikon feature specifies the lens model, only the focal length and maximum aperture. Don't you need more information for distortion control? Do the programs that provide lens profile distortion correction even allow looking up Nikon lenses on Canon bodies? Maybe some experimenting modifying the metadata with exiftool is in order before going any further.

Note that maybe this can be done as a lua script that includes a list of just the lenses that you own.

EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #2 on: October 29, 2016, 02:46:33 PM »
Yes thats correct I would not need the aperture information so much
My mean use would be for distortion profile for the wide angle lenses that are manual focus. ( and nikon mount )

If I just could write the focal length and a description text (like ZEISS 50) or (Nikon 50) in the meta data then I know what to select in ACR.  Ideally ACR would figure out which lens I used automatically. but that would need some investigation into which how the EXIF data is formatted.

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #3 on: October 29, 2016, 02:52:18 PM »
As seen in this video about the ACR lens profiles

There is the automatic selection if it detects the lens meta data, and I can select here the right lens.
Just after shooting on trip with different zeiss lenses after some days I forget which lens was used in my shots. so this would help a lot for that.


dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #4 on: October 29, 2016, 04:29:02 PM »
Of course with your feature request you still have to remember to change the lens information in the menu every time you switch lenses but it would be nice to have the metadata recorded properly in camera instead of having to write it down or try to remember when you're editing the photos.

I just checked in Lightroom and it is possible to manually select any lens no matter what camera body you used, even combinations that are impossible like a COOLPIX lens on a Canon body.

Ok, the thing is will your editing program recognize the lens from the metadata? This is what I'm getting from a CR2 shot on an EOSM:
Code: [Select]
Lens Info                       : 11-22mm f/0
Lens Model                      : EF-M11-22mm f/4-5.6 IS STM
Lens Serial Number              : 0000004904

Hum, f/0? Anyway, it looks like the Lens Model tag is what we're interested in. (Off topic: I can't understand why people blank out serial numbers on posts unless they are using stolen equipment.) According to the exiftool instructions you can write to that tag. Let's say you want to put my lens on your file named "myfile.CR2"
Code: [Select]
exiftool -LensModel="EF-M11-22mm f/4-5.6 IS STM" myfile.CR2
I haven't tried this myself and maybe you don't want to modify the original file but there's also a way to write a sidecar XMP file with exiftool. Come to think of it writing an XMP file in camera might be doable and it looks like your feature request would a good candidate for a lua script.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #5 on: October 29, 2016, 04:49:52 PM »
I just did test with the exif info you provided and Adobe camera raw recognises the lens profile from that info :)

I used this app to edit the exif info, but im sure you can edit the same info also with the exif tool
https://itunes.apple.com/nl/app/exif-editor/id477514607?l=en&mt=12


DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 2939
  • 5D3 / M1 / 7D / 70D / SL1
Assign lens focal length and name for non cpu lenses
« Reply #6 on: October 29, 2016, 07:06:57 PM »
Excellent progress guys and Thanks for starting this thread @Lars Steenhoff -- I also am intrigued by this exiftool app (Exif Editor) from the iTunes App store. Seems like a nice gem but for $10.99 I'm not so sure yet. Care to try and convince me?  :)
5D3.113 • 5D3.123 • EOSM.203 • 7D.203 • 70D.112 • 100D.101

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #7 on: October 29, 2016, 11:31:48 PM »
We know that it is possible in post with various exif editing apps.

There seems to be two ways to do this in camera. The easy way would be to write an XMP sidecar file every time you shoot a picture. The harder way would be to re-assign the lens information so that it writes the metadata directly into the raw file. Either way should work with Adobe Camera Raw to do automatic lens correction.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #8 on: October 29, 2016, 11:53:45 PM »
Right now my main interest is to get the metadata into an mlv file.
then when the dngs are generated in post this metadata will be put inside the dng files.

My knowledge of how the metadata is written in mlv video is limited.

Anyone know how its written in the mlv?

for stills it would be nice to have it in the cr2 but this might be more difficult. then the xmp route might be best for stills.

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #9 on: October 29, 2016, 11:57:13 PM »
@DeafEyeJedi. I just bought the tool because i was impatient to use the terminal and just bought it as it was the first thing that i found that looked simple, it is very simple to use 😎
but there are many free tools that can do the same.

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #10 on: October 30, 2016, 02:08:32 AM »
My knowledge of how the metadata is written in mlv video is limited.

Same here but we do know that the lens information does shows in the DOF display:



And it is in the MLV file in the Lens Block:

Code: [Select]
Block: LENS
  Offset: 0x0000014c
    Size: 96
    Time: 0.003000 ms
     Name:        'EF-M11-22mm f/4-5.6 IS STM'
     Serial:      ''
     Focal Len:   21 mm
     Focus Dist:  22 mm
     Aperture:    f/9.10
     IS Mode:     0
     AF Mode:     0
     Lens ID:     0x00000033
     Flags:       0x00000000

So it looks like your feature request is probably doable if we can get the attention of someone who can point this discussion in the right direction. Maybe there's a way to change the values for lens_info.name and maybe also lens_info.lens_id? Look in src/lens.h and src/lens.c. Don't know if there are lua hooks that can reassign property values. If you look in modules/lua/lua_property.c you'll find this:

Code: [Select]
// !!!DANGER WILL ROBINSON!!!
//#define LUA_PROP_REQUEST_CHANGE
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3199
  • 60Da / 1100D / EOSM
Re: Assign lens focal length and name for non cpu lenses
« Reply #11 on: October 30, 2016, 02:34:16 AM »
Maybe there's a way to change the values for lens_info.name and maybe also lens_info.lens_id? Look in src/lens.h and src/lens.c. Don't know if there are lua hooks that can reassign property values. If you look in modules/lua/lua_property.c you'll find this:

Code: [Select]
// !!!DANGER WILL ROBINSON!!!
//#define LUA_PROP_REQUEST_CHANGE
Not the way to do it. You don't need to mess with setting Canon properties. lens_info struct is in ML's control. All you need to do is set it's fields to the values you want. This is not currently exposed to lua (the lens properties are readonly), but it wouldn't be hard to change the API so you could write to them from lua.

You also need to check when PROP_LENS_NAME prop handler runs (I don't know when/how often it runs). It's going to overwrite any changes you might have made. You could also maybe use a prop handler for that one as a trigger to prompt the user to enter the lens name (when there's no value from Canon).

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #12 on: October 30, 2016, 04:41:15 PM »
As usual I was heading in the wrong direction.

@dmilligan -- as always thanks for the tips.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #13 on: October 30, 2016, 09:32:26 PM »
Yes great info,  nice to hear that its onder ML control !

I'm just making some photoshop mockups

I think it will be useful to have a predefined list that can be loaded on the memory card that has the custom the exif names, so that in the camera a user only has to select the right lens.
A favorites section of most used lenses can be handy too.

I will do some more thinkering





dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #14 on: October 31, 2016, 12:07:19 AM »
Nice, though the choices should probably go into a submenu. If you use that feature a lot you can always put it into a custom menu.

The Focus menu is rather bare on the EOSM but there's lots going on in other cameras--maybe some of this will eventually get into the EOSM?



I was thinking of reading from a lens database stored in the ML directory, in flat ascii text format to make it easy. You can put in all your non cpu lenses in there. Of course it would have to be exactly the same as the names in the ACR database.

Another idea is to turn off that menu item when a cpu lens is attached in case the user forgets to switch it off in the menu.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 2939
  • 5D3 / M1 / 7D / 70D / SL1
Assign lens focal length and name for non cpu lenses
« Reply #15 on: October 31, 2016, 12:19:12 AM »
Nice, though the choices should probably go into a submenu. If you use that feature a lot you can always put it into a custom menu.

True. Nice mockup @Lars Steenhoff! :)

I was thinking of reading from a lens database stored in the ML directory, in flat ascii text format to make it easy. You can put in all your non cpu lenses in there. Of course it would have to be exactly the same as the names in the ACR database.

Another idea is to turn off that menu item when a cpu lens is attached in case the user forgets to switch it off in the menu.

Great ideas -- especially the menu item shut off w cpu lens attached.
5D3.113 • 5D3.123 • EOSM.203 • 7D.203 • 70D.112 • 100D.101

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3199
  • 60Da / 1100D / EOSM
Re: Assign lens focal length and name for non cpu lenses
« Reply #16 on: October 31, 2016, 01:23:15 AM »
I was thinking of reading from a lens database stored in the ML directory, in flat ascii text format to make it easy. You can put in all your non cpu lenses in there. Of course it would have to be exactly the same as the names in the ACR database.

The nice thing about Lua is that it's also a great "configuration" language for storing this sort of information. To load the file from a Lua script simply use dofile() (this is how the config.lua module works, your script's configuration information is stored itself as a Lua script). Example:
Code: [Select]
return
{
    "Lens Name #1",
    "Lens Name #2",
    "Lens Name #3",
    "etc..."
}

and to load it:
Code: [Select]
local lens_list = dofile('lens_list.cfg")


This might actually be something you wouldn't put in a menu at all. If you can reliably detect when a non-CPU lens gets attached (should be possible from Lua I think), then simply popup a prompt that asks the user to select the lens they just attached. This also avoids the situation of the user forgetting to make the correct selection.

Also, to implement this for stills, you can probably just write the lens information in an xmp sidecar (already completely possible from Lua).

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #17 on: October 31, 2016, 06:46:35 AM »
...to implement this for stills, you can probably just write the lens information in an xmp sidecar...

That was my first thought too. That should be pretty easy.

Like you said earlier,

...lens_info struct is in ML's control. All you need to do is set it's fields to the values you want. This is not currently exposed to lua (the lens properties are readonly), but it wouldn't be hard to change the API so you could write to them from lua.

I see that lens_info.name is assigned in src/lens.c
Code: [Select]
PROP_HANDLER( PROP_LENS_NAME )
{
    if( len > sizeof(lens_info.name) )
        len = sizeof(lens_info.name);
    memcpy( (char*)lens_info.name, buf, len );
}

Wouldn't it just be a matter of adding an else statement in order to assign a custom name (up to 32 characters) to lens_info.name? Of course a new variable needs to be declared so does that variable need to be defined in a special way so it is available to lua? Looks like I've got some studying to do.

It shouldn't matter how often the PROP_LENS_NAME handler runs because the length of the string will always be zero if the lens doesn't communicate with the body. If the user changes lenses with the camera on it will also zero out when communications between the lens and body is broken. Am I on the right track with this?
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #18 on: October 31, 2016, 01:56:31 PM »
Maybe a good choice for the custom lens name variable could be user_lens_info.name:

I also realized a problem after writing that previous post. lens_info.name should be reset before checking it against PROP_LENS_NAME.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #19 on: November 10, 2016, 08:38:02 AM »
Thought I'd revisit this.

Looks like the missing link here is to be have a lua variable that can substitute a user supplied lens name in lens_info.name. This is really only necessary for MLV because as it turns out silent still DNG's don't save the lens name. Maybe it should? Otherwise automatic lens distortion correction doesn't work on picture editing applications.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

Lars Steenhoff

  • Member
  • ***
  • Posts: 188
Re: Assign lens focal length and name for non cpu lenses
« Reply #20 on: November 10, 2016, 01:24:45 PM »
Yes we are closing in on theoretical solution, in practice there a couple of steps needed now.

- Not currently exposed to lua (the lens properties are readonly)  (dmilligan)
- Who is able to expose this value, dfort do you know were in bitbucket this value is stored?

- If we have this value we make a list of lenses that are supported in adobe camera raw and make this user customisable

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #21 on: November 10, 2016, 06:33:59 PM »
What might work is to modify the backends so that if lens_info.name is empty it will use a lua writeable user_lens_info.name in its place. This shouldn't be too difficult but it is beyond my coding abilities. At least the part about adding something to the lua API.

@dmilligan -- are we on the right track here?
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3199
  • 60Da / 1100D / EOSM
Re: Assign lens focal length and name for non cpu lenses
« Reply #22 on: November 11, 2016, 03:15:05 AM »
I don't think that's necessary. Just make it so you can write to lens_info.name from lua.

Not tested:

Code: [Select]
diff --git a/modules/lua/lua_lens.c b/modules/lua/lua_lens.c
--- a/modules/lua/lua_lens.c
+++ b/modules/lua/lua_lens.c
@@ -48,7 +48,12 @@
 static int luaCB_lens_newindex(lua_State * L)
 {
     LUA_PARAM_STRING_OPTIONAL(key, 2, "");
-    if(!strcmp(key, "name") || !strcmp(key, "focal_length") || !strcmp(key, "focus_distance") || !strcmp(key, "hyperfocal") || !strcmp(key, "dof_near") || !strcmp(key, "dof_far") || !strcmp(key, "af"))
+    if(!strcmp(key, "name"))
+    {
+        LUA_PARAM_STRING(value, 3);
+        strncpy(lens_info.name, value, 31);
+    }
+    else if(!strcmp(key, "focal_length") || !strcmp(key, "focus_distance") || !strcmp(key, "hyperfocal") || !strcmp(key, "dof_near") || !strcmp(key, "dof_far") || !strcmp(key, "af"))
     {
         return luaL_error(L, "'%s' is readonly!", key);
     }


dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #23 on: November 11, 2016, 08:14:07 AM »
Cool -- Thanks!

Looks like we've something to chew on for a while.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*

dfort

  • Hero Member
  • *****
  • Posts: 1747
Re: Assign lens focal length and name for non cpu lenses
« Reply #24 on: November 16, 2016, 01:07:19 AM »
Baby steps.

I applied the patch to the lua_fix branch, seems like a good one for this.

Next I wrote this very simple script:

lens.lua
Code: [Select]
-- Non CPU Lens
-- Prints lens_info.name on the console

menu.close()
console.show()
if lens.name == "" then
    print("non-cpu lens")
    lens.name = "Rokinon Cine Prime"
end
print("lens: "..lens.name)
print "Press any key to exit."
key.wait()
console.hide()

Ran the script once with a lens attached then removed the lens and ran it again. It works!

Out of curiosity I also ran this on a build that didn't have the patch that dmilligan provided and got an error stating that "name is read only" when there was no lens attached.

Next test, will the metadata stick? Here's the Lens block data from mlv_dump -v:

Code: [Select]
Block: LENS
  Offset: 0x0000014c
    Size: 96
    Time: 0.003000 ms
     Name:        'Rokinon Cine Prime'
     Serial:      ''
     Focal Len:   50 mm
     Focus Dist:  0 mm
     Aperture:    f/0.00
     IS Mode:     0
     AF Mode:     3
     Lens ID:     0x00000000
     Flags:       0x00000000

Looks like everything is working. Now how to write a lua script to make this practical? @gary23 are you following this?

Thanks again @dmilligan ! Should we (I or you) submit a PR to the lua_fix branch for this?

[EDIT] Should the Serial and Focal Len also be writable? Is there a way to look up the Lens ID? It might be useful for let's say using Nikon CPU lenses with a type G adapter.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*