Landscape Focus Bracketing Script - page 7 - Completed and Working Scripts - CHDK Forum

Landscape Focus Bracketing Script

  • 247 Replies
  • 48404 Views
Re: Landscape Focus Bracketing Script
« Reply #60 on: 07 / April / 2019, 02:15:56 »
Advertisements
@reyalp

More hours just trying to get to the bottom of 'my mystery', ie why my bookend function works at the end of the script, but not the beginning.

As I said above, I can get it running ok, ie bookend taken, if I inject a 'random' sleep call: but I don't like this approach.

In the example of the script below, I used the method you suggested, but it still doesn't work.

As I said before, when you get a chance, I would welcome any insight you have.

Cheers

Garry

Code: [Select]
--[[
@title Basic Landscape Bracketing
'Perfect' focus brackets from near to blur defined 'infinity': overlap defined at a fraction of camera's CoC
Plus option of two additional exposure brackets at each focus step, at 1Ev, 2Ev or 3Ev using -/+ or -/-- or +/++ logic
Use Bookends to help differentiate bracket set in post
More info at https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets
Camera should be in manual focus mode and M mode
Rev 1.0
April 2019
Tested on a G7X
(c) Garry George
@chdk_version 1.5
# overlap = 0 "Overlap at" {CoC 2CoC/3 CoC/2 diff}
# delta = 0 "Exposure bracket delta?" {None 1Ev 2Ev 3Ev 800 1600 ZN}
# logic = 0 "Exposure bracket logic?" {0/-/+ 0/-/-- 0/+/++}
# delay = 3 "Script Delay (s)" [0 5]
# bookends = 1 "Bookends?" {No Yes}
# quality = 1 "Infinity focus quality?" {CoC/2 CoC/3 CoC/4}
--]]

capmode = require("capmode")
if (capmode.get_name() ~= "M") then
    print("Switch to M mode")
    return -- exit script
end

if get_focus_mode() ~= 1 then
    print("Switch to MF mode")
    return -- exit script
end

if (get_focus() == -1) then
    print("@ Infinity")
    return -- exit script
end

press("shoot_half") -- get current set camera values
t = get_tick_count()
repeat
    sleep(50)
    if get_tick_count() - t > 5000 then
        print("Unknown Error")
        release("shoot_half")
        return -- exit script
    end
until (get_shooting() == true)
release("shoot_half")

    s = get_tv96()
    av = get_av96()
    set_tv96_direct(s)
    set_av96_direct(av)
    dof = get_dofinfo()
    x = dof.focus
    base_h = dof.hyp_dist -- that is without diffraction accounted for
    fl = dof.focal_length/100

x_start = x
last_x = x
temp = 0
temp1 = 0
temp2 = 0
ecnt = get_exp_count()

function myshoot() -- so I can change shooting strategies ;-)
    press("shoot_half")
        repeat sleep(50) until (get_shooting() == true)
        local prevcnt=hook_shoot.count()
        press'shoot_full_only'
        repeat sleep(10) until prevcnt ~= hook_shoot.count()
        release'shoot_full_only'
    release("shoot_half")
end

function bookend()
    set_tv96_direct(960)
    set_av96_direct(640)
    ecnt = get_exp_count()
    myshoot()
    set_tv96_direct(s)
    set_av96_direct(av)
    repeat sleep(100) until (get_exp_count() ~= ecnt)
end

function refocus(xx)
    set_focus(xx)
    sleep(500) -- may need adjusting for some cams?
end

function X_bracket()
    set_tv96_direct(s)
    if delta == 0 then
        myshoot()
    elseif delta < 4 and logic == 0 then
        myshoot()
        set_tv96_direct(s-96*delta)
        myshoot()
        set_tv96_direct(s+96*delta)
        myshoot()
    elseif delta < 4 and logic == 1 then
        myshoot()
        set_tv96_direct(s+96*delta)
        myshoot()
        set_tv96_direct(s+2*96*delta)
        myshoot()
    elseif delta < 4 and logic == 2 then
        myshoot()
        set_tv96_direct(s-96*delta)
        myshoot()
        set_tv96_direct(s-2*96*delta)
        myshoot()
    elseif delta == 4 then
        local iso = get_sv96()
        set_sv96(sv96_market_to_real(iso_to_sv96(100)))
        myshoot()
        set_sv96(sv96_market_to_real(iso_to_sv96(800)))
        myshoot()
        set_sv96(iso)
    elseif delta == 5 then
        local iso = get_sv96()
        set_sv96(sv96_market_to_real(iso_to_sv96(100)))
        myshoot()
        set_sv96(sv96_market_to_real(iso_to_sv96(1600)))
        myshoot()
        set_sv96(iso)
    elseif delta == 6 then
        myshoot()
        set_tv96_direct(s-96*4)
        myshoot()
    end
    set_tv96_direct(s)
end

h = base_h -- no overlap case: brackets 'touch' at CHDK CoC

if overlap == 1 then -- adjust h to achieve the requested overlap, ie 'touching' at 2*CoC/3 or CoC/2 or at the diffraction aware defocus blur
    h = (h*3)/2
elseif overlap == 2 then
    h = 2*h
elseif overlap == 3 then -- use diffraction aware overlap: Assume CHDK CoC is total blur, formed in quadrature from defocus and diffraction blurs
    temp1 = 1000*dof.coc -- total blur set up for imath
    temp2 = (1342*dof.aperture)/1000 -- set up for imath. From diff_blur = 2.44*0.55*N (um)
    if temp1 > temp2 then -- can use diffraction aware overlap
        temp = imath.sqrt(imath.mul(temp1,temp1) - imath.mul(temp2,temp2)) -- diffraction aware defocus blur
        temp2 = imath.div(temp1,temp)
        if temp2 > 3000 then
            h = 3*h
        else
            h = (h*temp2)/1000
        end
    else -- diff blur > total blur
        h = 3*h
    end
end

if (x > base_h or x == -1) then
    print("@/beyond H")
    if bookends == 1 then bookend() else sleep(delay*1000) end
    X_bracket()
    if bookends == 1 then bookend() end
    return -- exit script
end

if bookends == 1 then bookend() else sleep(delay*1000) end

while (x < h/3) do -- capture focus brackets up to h/3
    refocus(x) -- move to x
    X_bracket()
    dof = get_dofinfo()
    x = dof.focus -- register actual x moved by cam
    last_x = x
    x = (x*(h*10 - 2*fl))/(h*10 - 2*x*10) -- position of next focus bracket
    if x <= last_x or x <= 0 then
        print("Unknown Error")   
        refocus(x_start)
        return
    end   
end

refocus(h/3) -- take shot at h/3
X_bracket()

temp2 = h*(quality+2)

refocus(h) -- take shot at h
X_bracket()

if temp2 > h then -- take additional infinity focus shot
    refocus(temp2)
    X_bracket()     
end

if bookends == 1 then bookend() end

refocus(x_start)



*

Offline reyalp

  • ******
  • 14085
Re: Landscape Focus Bracketing Script
« Reply #61 on: 07 / April / 2019, 02:45:40 »
@reyalp

More hours just trying to get to the bottom of 'my mystery', ie why my bookend function works at the end of the script, but not the beginning.

As I said above, I can get it running ok, ie bookend taken, if I inject a 'random' sleep call: but I don't like this approach.
Sorry, I haven't had a chance to look at this yet.

In general, it's not *too* unusual for CHDK script to need random sleeps in some cases. Yes, it feels hokey, but CHDK is hooked into an multi-tasking operating system in poorly specified ways, so there are situations where script simply doesn't have a way to know exactly when a particular thing has happened.

Without looking in detail, based on what you posted in reply #58 https://chdk.setepontos.com/index.php?topic=13638.msg139948#msg139948

one difference I notice for the first bookend is that it's immediately after the initial half press. Perhaps adding
Code: [Select]
repeat sleep(10) until not get_shooting()
after the first release("shoot_half") would do it.
Don't forget what the H stands for.

Re: Landscape Focus Bracketing Script
« Reply #62 on: 07 / April / 2019, 03:09:32 »
@reyalp

First of all let me say I wasn't expecting a personal service from you  ;)

But I do value you, and other Lua gurus, helping people such as a myself.

And, yes, that simple line was the 'fix'.

BTW I'm also using your shooting suggestion, but I'm not sure it is much quicker than me just calling shoot()?

Code: [Select]
function myshoot() -- so I can change shooting strategies ;-)
    press("shoot_half")
        repeat sleep(50) until (get_shooting())
        local prevcnt=hook_shoot.count()
        press'shoot_full_only'
        repeat sleep(10) until prevcnt ~= hook_shoot.count()
        release'shoot_full_only'
    release("shoot_half")
    repeat sleep(50) until (not get_shooting())
end

Plus here is the draft full script:

Code: [Select]
--[[
@title Basic Landscape Bracketing
'Perfect' focus brackets from near to blur defined 'infinity': overlap defined at a fraction of camera's CoC
Plus option of two additional exposure brackets at each focus step, at 1Ev, 2Ev or 3Ev using -/+ or -/-- or +/++ logic
Use Bookends to help differentiate bracket set in post
More info at https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets
Camera should be in manual focus mode and M mode
Rev 1.0
April 2019
Tested on a G7X
(c) Garry George
@chdk_version 1.5
# overlap = 0 "Overlap at" {CoC 2CoC/3 CoC/2 diff}
# delta = 0 "Exposure bracket delta?" {None 1Ev 2Ev 3Ev 800 1600 ZN}
# logic = 0 "Exposure bracket logic?" {0/-/+ 0/-/-- 0/+/++}
# delay = 3 "Script Delay (s)" [0 5]
# bookends = 1 "Bookends?" {No Yes}
# quality = 1 "Infinity focus quality?" {CoC/2 CoC/3 CoC/4}
--]]

capmode = require("capmode")
if (capmode.get_name() ~= "M") then
    print("Switch to M mode")
    return -- exit script
end

if get_focus_mode() ~= 1 then
    print("Switch to MF mode")
    return -- exit script
end

if (get_focus() == -1) then
    print("@ Infinity")
    return -- exit script
end

press("shoot_half") -- get current set camera values
t = get_tick_count()
repeat
    sleep(50)
    if get_tick_count() - t > 5000 then
        print("Unknown Error")
        release("shoot_half")
        return -- exit script
    end
until (get_shooting())
release("shoot_half")
repeat sleep(50) until (not get_shooting())

    s = get_tv96()
    av = get_av96()
    set_tv96_direct(s)
    set_av96_direct(av)
    dof = get_dofinfo()
    x = dof.focus
    base_h = dof.hyp_dist -- that is without diffraction accounted for
    fl = dof.focal_length/100

x_start = x
last_x = x
temp = 0
temp1 = 0
temp2 = 0
ecnt = get_exp_count()

function myshoot() -- so I can change shooting strategies ;-)
    press("shoot_half")
        repeat sleep(50) until (get_shooting())
        local prevcnt=hook_shoot.count()
        press'shoot_full_only'
        repeat sleep(10) until prevcnt ~= hook_shoot.count()
        release'shoot_full_only'
    release("shoot_half")
    repeat sleep(50) until (not get_shooting())
end

function bookend()
    set_tv96_direct(960)
    set_av96_direct(640)
    ecnt = get_exp_count()
    myshoot()
    set_tv96_direct(s)
    set_av96_direct(av)
    repeat sleep(100) until (get_exp_count() ~= ecnt)
end

function refocus(xx)
    set_focus(xx)
    sleep(500) -- may need adjusting for some cams?
end

function X_bracket()
    set_tv96_direct(s)
    if delta == 0 then
        myshoot()
    elseif delta < 4 and logic == 0 then
        myshoot()
        set_tv96_direct(s-96*delta)
        myshoot()
        set_tv96_direct(s+96*delta)
        myshoot()
    elseif delta < 4 and logic == 1 then
        myshoot()
        set_tv96_direct(s+96*delta)
        myshoot()
        set_tv96_direct(s+2*96*delta)
        myshoot()
    elseif delta < 4 and logic == 2 then
        myshoot()
        set_tv96_direct(s-96*delta)
        myshoot()
        set_tv96_direct(s-2*96*delta)
        myshoot()
    elseif delta == 4 then
        local iso = get_sv96()
        set_sv96(sv96_market_to_real(iso_to_sv96(100)))
        myshoot()
        set_sv96(sv96_market_to_real(iso_to_sv96(800)))
        myshoot()
        set_sv96(iso)
    elseif delta == 5 then
        local iso = get_sv96()
        set_sv96(sv96_market_to_real(iso_to_sv96(100)))
        myshoot()
        set_sv96(sv96_market_to_real(iso_to_sv96(1600)))
        myshoot()
        set_sv96(iso)
    elseif delta == 6 then
        myshoot()
        set_tv96_direct(s-96*4)
        myshoot()
    end
    set_tv96_direct(s)
end

h = base_h -- no overlap case: brackets 'touch' at CHDK CoC

if overlap == 1 then -- adjust h to achieve the requested overlap, ie 'touching' at 2*CoC/3 or CoC/2 or at the diffraction aware defocus blur
    h = (h*3)/2
elseif overlap == 2 then
    h = 2*h
elseif overlap == 3 then -- use diffraction aware overlap: Assume CHDK CoC is total blur, formed in quadrature from defocus and diffraction blurs
    temp1 = 1000*dof.coc -- total blur set up for imath
    temp2 = (1342*dof.aperture)/1000 -- set up for imath. From diff_blur = 2.44*0.55*N (um)
    if temp1 > temp2 then -- can use diffraction aware overlap
        temp = imath.sqrt(imath.mul(temp1,temp1) - imath.mul(temp2,temp2)) -- diffraction aware defocus blur
        temp2 = imath.div(temp1,temp)
        if temp2 > 3000 then
            h = 3*h
        else
            h = (h*temp2)/1000
        end
    else -- diff blur > total blur
        h = 3*h
    end
end

if (x > base_h or x == -1) then
    print("@/beyond H")
    if bookends == 1 then bookend() else sleep(delay*1000) end
    X_bracket()
    if bookends == 1 then bookend() end
    return -- exit script
end

if bookends == 1 then bookend() else sleep(delay*1000) end

while (x < h/3) do -- capture focus brackets up to h/3
    refocus(x) -- move to x
    X_bracket()
    dof = get_dofinfo()
    x = dof.focus -- register actual x moved by cam
    last_x = x
    x = (x*(h*10 - 2*fl))/(h*10 - 2*x*10) -- position of next focus bracket
    if x <= last_x or x <= 0 then
        print("Unknown Error")   
        refocus(x_start)
        return
    end   
end

refocus(h/3) -- take shot at h/3
X_bracket()

temp2 = h*(quality+2)

refocus(h) -- take shot at h
X_bracket()

if temp2 > h then -- take additional infinity focus shot
    refocus(temp2)
    X_bracket()     
end

if bookends == 1 then bookend() end

refocus(x_start)

*

Offline reyalp

  • ******
  • 14085
Re: Landscape Focus Bracketing Script
« Reply #63 on: 07 / April / 2019, 03:49:48 »
BTW I'm also using your shooting suggestion, but I'm not sure it is much quicker than me just calling shoot()?
Sorry, my earlier post might have been unclear. That method would only be expected to be faster if you take multiple shots without releasing shoot_half.

That is, press shoot_half once at the start of your script, wait for get_shooting, then, without releasing shoot_half, click shoot_full_only every time you want to shoot. That skips the entire preshoot cycle that normally happens every half press.

However, making this approach work with your script may require more than just changing myshoot and getting rid of the release('shoot_half'). As I mentioned earlier, adjusting focus with this technique may be suspect.

If you want to try this, I'd suggest making myshoot something like
Code: [Select]
function myshoot()
    local prevcnt=hook_shoot.count()
    local rawprevcnt=hook_raw.count()
    press'shoot_full_only'
    repeat sleep(10) until prevcnt ~= hook_shoot.count()
    release'shoot_full_only'
    repeat sleep(10) until rawprevcnt ~= hook_raw.count()
end
The wait for hook_raw at the end will ensure myshoot() blocks until the shot is mostly done.
Don't forget what the H stands for.


Re: Landscape Focus Bracketing Script
« Reply #64 on: 07 / April / 2019, 03:58:13 »
@reyalp

Ok, I think I get it now.

Does that mean your suggested change to myshoot, that does not involve a half press, needs to use a half press and release in the main section?

Or can I use your hook ‘stuff’ and only use shoot full only?

As you say, with my repeated refocusing, I don’t see how I can use a single press release half shoot.

Once again, thanks for the quick response, you are making my dull Sunday worthwhile :-)

*

Offline reyalp

  • ******
  • 14085
Re: Landscape Focus Bracketing Script
« Reply #65 on: 07 / April / 2019, 04:10:56 »
Does that mean your suggested change to myshoot, that does not involve a half press, needs to use a half press and release in the main section?
Yes, the speedup is from taking multiple shots without releasing half press. So, hypothetically, you'd press shoot_half exactly once at the start of your script, and release it at the end.

Quote
As you say, with my repeated refocusing, I don’t see how I can use a single press release half shoot.
Moving focus while half press is held works on at least some cameras, but it wouldn't be surprising if there were issues on some cameras, or if you had to add delays to ensure the actual shot was completed.

Updating exposure settings with this technique is generally OK, so you could make the brackets work this way at least, but it's not clear it would be worth the extra complexity.
Don't forget what the H stands for.

Re: Landscape Focus Bracketing Script
« Reply #66 on: 07 / April / 2019, 04:28:14 »
@reyalp

Great. Now I truly get it and will publish an update to my script once I’ve finished ‘tweaking’.

I’ll be biasing the update to stability over speed.  ;)

Once again, many thanks for your insight.

Cheers

Garry

Re: Landscape Focus Bracketing Script
« Reply #67 on: 08 / April / 2019, 03:11:06 »
Have just withdrawn my original script as I was not content with its stability.

Have replaced it with one that does work, but has less (focusing) functionality compared to the original.

 https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets

This version seems to work well and does what I want it to, ie take near to far focus brackets, with or without exposure brackets.

You can specify bracket to bracket overlap quality and the final infinity blur quality.

As before I welcome feedback.

BTW I attach a test image I took yesterday


Re: Landscape Focus Bracketing Script
« Reply #68 on: 09 / April / 2019, 04:02:37 »
Just added back in the option of three focus bracketing strategies: current position to infinity (X2INF), min camera focus to current position (MAC2X) and min camera focus to infinity (MAC2INF).
Enjoy  :D

Re: Landscape Focus Bracketing Script
« Reply #69 on: 10 / April / 2019, 16:56:39 »
Ok, enough is enough  :haha

This 'final' edit of the script makes this a very powerful focus (and exposure) bracketing tool.

I've added to the 'tutorial' at: https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets

The script now gives you five focus bracketing strategies and loads of exposure bracketing strategies.

The script also runs in non-M modes, eg Av mode and when using AF, ie to focus on your point of interest and thus from where focus bracketing starts.

As usual I welcome feedback from other users.
« Last Edit: 10 / April / 2019, 18:04:04 by pigeonhill »

 

Related Topics