Assign lens focal length and name for non cpu lenses

Started by Lars Steenhoff, October 29, 2016, 12:04:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Lars Steenhoff

Great progress !   :)

Focal length I think yes
Perhaps if the name has the focal length included then it may not be nessesary.

Did you open the dng file in Adobe Camera Raw?   And did it detect the profile?

dfort

I just got it working and haven't done much testing yet.  Let me know what camera(s) you have and I can send you a patched ML build with this script.

I saw on another topic that you're thinking of setting up a development system. What's cool about lua scripting is that you don't need to set up anything and can start coding with just a text editor and a little help from your ML forum friends.


Sent from my iPhone using Tapatalk

Lars Steenhoff

Cool,  I have the canon 5d mark 3, and a couple of nikon mount zeiss and nikon lenses

Zeiss 25 f2 zf.2
Zeiss 35 f2 zf.2
Zeiss 50 f2 zf.2 mp
Zeiss 85 f1.4 zf.2

I will try the build and see if i can get then reconised.
About compiling,  i still have to read up a bit on how it works, will give it a try soon.

dfort

@Lars_Steenhoff

Here is a build for you to try out. It is from the lua_fix branch with dmilligan's patch and has the lens.lua script in it:
https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-custom_lens_name.2016Nov16.5D3113.zip

The lua script I posted earlier had a mistake in it. You can't do:

lens_info.name = "Zeiss 25 f2 zf.2"

To assign a value to lens_info.name from lua you need to:

lens.name = "Zeiss 25 f2 zf.2"

I copied a previous version when I was writing the post and corrected it later. I also edited the post.

Here are the EXIF lens tags from the dng files extracted from the MLV file:

QuoteF Number                        : 0
Subject Distance              : 0 m
Focal Length                    : 50.0 mm
Lens Model                      : Rokinon Cine Prime

Note that some of the information from the LENS Block of the MLV file didn't get saved in the dng metadata. I also checked if the Lens Model is saved when using the Silent (stills) module and it does when using MLV but it doesn't with the DNG option. As expected CR2 also didn't save Lens Model.

We should probably test this some more before making any other lens properties writable to lua. I can see the value of having control over the Focal Length and Lens Serial Number information in controlled situations. For example when doing stop motion animation with manual lenses it would help to have this in the metadata if someone needs to do a reshoot and the lens wasn't noted on the shot log. Of course if they didn't take the time to fill out the shot log they probably didn't run the lua script either. In any case, this project may appeal to just a few users but it does seem worthwhile fleshing it out.

If you want to check out the code without having to apply the patch it is in my custom_lens_name branch.

https://bitbucket.org/daniel_fort/magic-lantern/branch/custom_lens_name

Lars Steenhoff

Thanks dfort,

I just tested the script, and it works fine!

I changed the name in the lua script to match the name in ACR, in this case it looked like this

-- Non CPU Lens
-- Prints lens_info.name on the console

menu.close()
console.show()
if lens.name == "" then
    print("non-cpu lens")
    lens.name = "Zeiss Distagon T* 2/25 ZF.2"
end
print("lens: "..lens.name)
print "Press any key to exit."
key.wait()
console.hide()



One more property I would love to write to the file is the focal length, and if possible also the aperture.  Then we have complete lens info for distortion corrections as wel as for cataloging.
Now I see in ACR 50 mm while its a 25mm

Here on the left is the auto detection result   :)   
   

And here on the right is the list of zeiss lenses how they are written in ACR
When using these exact names ACR selects the profile automatically, so thats a great result!  Thanks

Lars Steenhoff


dfort

Quote from: Lars Steenhoff on November 17, 2016, 11:20:13 AM
One more property I would love to write to the file is the focal length, and if possible also the aperture.

That should be doable. On cpu lenses the aperture tracks the F-stop and focal length changes dynamically with zoom lenses but with non cpu lenses these are set to the default values of f0.0 and 50mm. Lens names are probably updated only when the camera senses a change in the lens but we're not sure how often the aperture and focal length properties are polled so there's a chance that it might not work.

Another thing that should be doable is to put these tags into dng files when using the silent module. CR2 files will most likely need the xmp sidecar treatment. Since you are mainly interested in working with MLV files let's concentrate on that first.

If you have some coding ability feel free to jump in, otherwise you'll have to wait for me to figure out how to expand on dmilligan's patch.

DeafEyeJedi

Wonderful stuff @Lars Steenhoff and Thanks for sharing these useful links as you obviously got @dfort's attention!  :P

Quote from: Lars Steenhoff on November 17, 2016, 03:28:07 PM
and it shows up fine in MLVplayer too  :)

That's pretty cool actually. Useful details on the previewer!

Quote from: dfort on November 17, 2016, 06:46:59 PM
That should be doable. On cpu lenses the aperture tracks the F-stop and focal length changes dynamically with zoom lenses but with non cpu lenses these are set to the default values of f0.0 and 50mm. Lens names are probably updated only when the camera senses a change in the lens but we're not sure how often the aperture and focal length properties are polled so there's a chance that it might not work.

Ah, that's true. Point taken. I still think it may be worth to try?

Quote from: dfort on November 17, 2016, 06:46:59 PM
Another thing that should be doable is to put these tags into dng files when using the silent module. CR2 files will most likely need the xmp sidecar treatment. Since you are mainly interested in working with MLV files let's concentrate on that first.

If you have some coding ability feel free to jump in, otherwise you'll have to wait for me to figure out how to expand on dmilligan's patch.

Ouch that's a tough call... Wish I could have time to get my hands dirty with coding. Anyone else care to jump onboard with this project?
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

Lars Steenhoff

https://helpx.adobe.com/camera-raw/kb/supported-lenses.html

Here is the whole list of lenses that are supported in adobe, I'm thinking that it would be cool to make a selector in the menu that has this list already.

But first the basics, I will have a look at the source code.
I can understand some coding, and I'm able to change some scripts, real coding however is not really my skill.  so I may get stuck when I have to write a proper function :)


@DeafEyeJedi  great feedback

dfort

Looking at that list it seems that some lens names are longer than the 32 characters assigned to that EXIF tag. Have you checked that ACR recognizes your lens automatically? It might instead be looking at Lens ID and going through a lookup table. If that's case we also need to have the MLV processing apps pass along that tag to the DNG files for automatic lens distortion correction to work properly.

That's the goal, isn't it? The Nikon feature that you pointed out is so that metering would work with non-cpu lenses. That's something that probably isn't possible on Canon cameras because there is no mechanical connection between the camera and lens aperture control.

Lars Steenhoff

Yes ACR recognised the lens automatically with only the name in the EXIF field.

The name on that list is the same as the one I tested, which was "Zeiss Distagon T* 2/25 ZF.2"

I do see some that are longer too, like Nikon AF-S DX VR Zoom-NIKKOR 55-200mm f/4-5.6G IF-ED.
I can do some further testing

Yes metering is not whats needed just the lens info, (name, focal lengt, f stop) so in post I can use this info to set the right profile, or to sort shots by lens.
The nikon video was more to illustrate the concept of setting lens info via a menu into the file.

Lars Steenhoff

I'm trying to make a list so that I can select a lens in lua, this is how far I got:

lenslist = {"Zeiss Makro-Planar T* 2/50 ZF.2", "Zeiss Planar T* 1,4/50 ZF.2", "Zeiss Planar T* 1,4/85 ZF.2", "Zeiss Distagon T* 2/35 ZF.2",
            "Zeiss Distagon T* 2,8/25 ZF.2", "Nikon AF DC-NIKKOR 105mm f/2D", "Nikon AF DC-NIKKOR 135mm f/2D"}


Now I need to write a function to let me select one from this list,

...   Not sure how to proceed from here

dfort

Quote from: Lars Steenhoff on November 17, 2016, 11:06:10 PM
...   Not sure how to proceed from here

Find a script that has a menu similar to what you want and copy it. There are several examples in the Scripting Corner of the forum. You can also ask someone that has written some ML lua scripts like @garry23

Your menu is about to become more complicated. I figured out how to write to the focal_length variable. Well, almost--keep reading.

    if(!strcmp(key, "focal_length"))
    {
        LUA_PARAM_INT(value, 3);
        lens_info.focal_len = value;
    }
    else if(!strcmp(key, "focus_distance") || !strcmp(key, "hyperfocal") || !strcmp(key, "dof_near") || !strcmp(key, "dof_far") || !strcmp(key, "af"))


This is an integer so it needed to be handled differently from the name. I also took off focal_length from the warning list that it cannot be written to. I'm not sure what to do about the aperture because it isn't a part of lua_lens_fields.

So here's a new lua script that works with this latest change:

-- Non CPU Lens
-- Prints lens_info.name on the console

menu.close()
console.show()
if lens.name == "" then
    print("non-cpu lens")
    lens.name = "Zeiss Distagon T* 2/25 ZF.2"
    lens.focal_length = 25
end
print("lens: "..lens.name)
print("focal_length: "..lens.focal_length)
print "Press any key to exit."
key.wait()
console.hide()


There is a problem though. The focal length value doesn't stick. The script runs fine the first time you run it but not the second time so reassigning the lua lens.focal_length doesn't seem to be changing the lens_info.focal_len property value variable and the MLV file shows the default 50mm lens instead of the script's 25mm.

In any case, this is a work in progress so here's the latest 5D3 build if you want to play with it:

https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-custom_lens_name.2016Nov17.5D3113.zip

Lars Steenhoff

Thanks!,
Yes I just tested with the same results, the focal length was not saved.

I did make a gif preview to show what the effect of the lens profile is in the case of the zeiss 25.
It corrects for vignetting and for distortion. this is not the best example, in an architecture shot it would be more obvious that lines are straight now.
And a quick tip if you import at 200% in ACR you get a nice 4K upscale from the RAW debayer.


dfort

Just tried it and ACR recognized the lens information and applied the correction automatically. Nice!

I take it that this only works properly with the 5D3 using mv1080 (full frame non-crop mode) because the vignetting and distortion would be different with a cropped frame.

I've been searching through the code trying to figure out why assigning the lens focal length isn't working. If that isn't possible I thought that maybe changing the default lens focal length from 50 to 0 might avoid some confusion but I can't find where that's taking place. I have a suspicion that lens_info.focal_len is assigned a value because there are some calculations done with it and a zero value might cause problems. Still, I'd like to give it a try and see what happens.

@dmilligan -- Mind if I put in a pull request of your patch to the lua_fix branch?

In the meantime let's move forward with the lua script. Are you putting your code on bitbucket or someplace where others can collaborate with you?  If your script is small enough you can post it here.

I'm not very familiar with lua and can't answer your question on how to set up a menu but this should help:

http://davidmilligan.github.io/ml-lua/modules/menu.html

dfort

@Lars_Steenhoff -- we're so close to being able to assign a value to the focal length:

https://www.magiclantern.fm/forum/index.php?topic=18279.msg175214#msg175214

Basically, I've got a build that works perfectly with manual lenses. No more defaulting to 50mm with non cpu lenses. The problem is that it also needs to work with cpu lenses.

A question for you and @garry23 - is assigning the aperture really going to gain us anything? It seems to me that setting the f-stop or maximum lens aperture will create more problems because there is no way that I can see to set it automatically, setting it manually adds complexity  during the shoot and it doesn't give us anything useful when processing the images other than the old, "I shot it at F5.6 at 250th of a second" information that seemed to be significant only in photography magazines. I mean we can try to put it in but I'm not sure how difficult it will be.

BTW -- has anyone explored programmable chips with Nikon to Canon adapters? Seems like there are some chipped adapters that work with focus confirmation. I heard there are programmable chips but I have no experience with them.

https://www.fotodioxpro.com/products/nikf-eos-dc

garry23

@dfort

From my perspective, as a stills photographer, not having 'any' meta data is not much of a problem.

The real value, I believe, will be for the timelapsers.

Cheers

Garry

Lars Steenhoff

@dfort great to see the focal length close to working, if the cpu lenses have a problem with this then perhaps a way to only enable the focal length setting when a non cpu lens is selected in the menu.

As for the aperture, yes it can be handy to have,  There could be away to set it automatically, The wide open value from the lens name would be used, so for example the "Zeiss Distagon T* 2/25 ZF.2"  would set the aperture to "f2"
This could then be manually changed into a more closed value.   To add the least complexity just taking the wide open value would be a nice start.


I have used a fotodiox pro adapter before, and it gave a beep and a red focus point blink when the shot was in focus.  I don't have one right now but I might get one for trap focus.

dfort

Ok--let's take this a step at a time. The lens name is working so writing a lua script for that is now possible. Well, it is possible with dmilligan's patch or my branch of lua_fix.

https://bitbucket.org/daniel_fort/magic-lantern/branch/custom_lens_name

I already committed the change needed for lua to have write access to the focal length. Once we work out an issue with getting this working with both manual and cpu lenses we can move on to the aperture.

This can probably benefit the "timelapsers" by saving the lens settings when the lens is twisted off slightly to reduce flickering. Basically, if you hold the depth of field preview button while twisting off the lens just enough to break contact it will lock the aperture so it won't open and close every time the shutter fires and possibly give inconstant exposures from frame to frame.

A little more searching turned up that lens chips may be more trouble than they are worth and years ago users were looking for a solution like the one we're working on.

https://www.magiclantern.fm/forum/index.php?topic=3312.0

dfort

Lens name and focal length now seem to be working properly. This time I made a test suite that includes all platforms along with the simple lua script so any ML user should be able to jump in and start scripting.

https://bitbucket.org/daniel_fort/magic-lantern/downloads/magiclantern-custom_lens_name.2016Nov21.zip

Next challenge, being able to change the metadata for aperture.

dfort

I thought this would take longer but:

Block: LENS
  Offset: 0x0000014c
    Size: 96
    Time: 0.003000 ms
     Name:        'Zeiss Distagon T* 2/25 ZF.2'
     Serial:      ''
     Focal Len:   25 mm
     Focus Dist:  0 mm
     Aperture:    f/2.00
     IS Mode:     0
     AF Mode:     3
     Lens ID:     0x00000000
     Flags:       0x00000000


Writing to aperture is working. Here's the modified lua script:

-- Non CPU Lens
-- Prints lens_info.name on the console

menu.close()
console.show()
if lens.name == "" then
    print("non-cpu lens")
    lens.name = "Zeiss Distagon T* 2/25 ZF.2"
    lens.focal_length = 25
    lens.aperture = 20
end
print("lens: "..lens.name)
print("focal_length: "..lens.focal_length)
print("aperture: "..lens.aperture/10)
print "Press any key to exit."
key.wait()
console.hide()


Note that the aperture needs to be divided by 10. There's a whole bunch of fancy stuff going on to display the aperture properly on the screen but it is written to the MLV header as an integer. This shouldn't be a problem when saving a value for aperture, simply have the script multiply the f-stop by 10. In other words f5.6 would be saved as 56. There doesn't seem to be a consistent way that the lens aperture appears in the lens name so it would be easier to make a separate field for it than to try and parse it out of the name.

A few interesting things came up. Perhaps mlv_dump should format the f-stop the same way as it is displayed in the live view display. Another thing is that the Serial number isn't being saved.

In any case, this is what the latest commit looks like. A block of code was indented to pretty up the formatting on a conditional statement so the diff shows it as a bigger change than it actually is. I tried some things that didn't work and am not 100% sure why somethings are working but hey--it passed my tests.

It is a little late so I'll post a test suite in the morning. I've also got some cleaning up to do before making a pull request to lua_fix.

Lars Steenhoff

Great work!   8)

I will happily test it out when you have a new build,


I don't know if could you possibly include the new crop-mode module in the build?

I just had the idea to also add a field in the metadata if the shot was recorded with the crop mode active. ( or to just multiply the focal length with the crop, which is not really happening, so that may not be the best )


dmilligan

From an API standpoint, it's a bit confusing that there's now a lens.aperture, when there was already a camera.aperture

a1ex

Well, aperture is a lens parameter, while shutter and ISO are camera (or sensor) parameters. On the other hand, all 3 are related (the exposure triangle).

They could probably be moved to expo.aperture, expo.shutter and expo.ISO. Also, expo.ec and expo.flash_ec (or maybe flash.ec, if we plan to expose some more flash functionality) could work.

Exposure transformations might also be useful (e.g. expo.raw2apex).

Just a suggestion.

dfort

Quote from: dmilligan on November 22, 2016, 07:51:39 PM
From an API standpoint, it's a bit confusing that there's now a lens.aperture, when there was already a camera.aperture

I totally missed that. Looks like I'm not quite done with this or is a1ex's comments putting the ball in dmilligan's court? As far as I'm concerned writing the aperture of a manual lens isn't as useful as lens name and focal length. In fact it looks like focal length isn't even necessary for automatic distortion correction in ACR. On the other hand if we've gotten this far why not make lens ID and serial number lua writable too?

Quote from: Lars Steenhoff on November 22, 2016, 01:57:47 PM
Great work!   8)

I will happily test it out when you have a new build,


I don't know if could you possibly include the new crop-mode module in the build?

I just had the idea to also add a field in the metadata if the shot was recorded with the crop mode active. ( or to just multiply the focal length with the crop, which is not really happening, so that may not be the best )

Thanks.

I'll be even happier when I see a lua script from you. You can start with the lens name and focal length and add the aperture later.

Adding metadata means changing the MLV specification. I'd check with g3gg0 on that first.

I'm not sure what effect cropping in on the image will have when ACR does automatic lens distortion correction. It is working now with 1920x1080 full frame 5D3 MLV files because it is using the entire sensor area.

In other words, even if we do add everything you're asking for it might not work. Try shooting some cropped and un-cropped footage of a test chart using the same lens making sure you line up the images so they match and run it through ACR's automatic lens distortion correction. Let's see what happens.