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

Landscape Focus Bracketing Script

  • 247 Replies
  • 55784 Views
Re: Landscape Focus Bracketing Script
« Reply #50 on: 03 / April / 2019, 13:48:33 »
Advertisements

“you definitely have to increase the speed. I don’t think it is complicated to use at least the half press mode.”

Not sure I follow this: my ignorance.

BTW I feel the that moving focus is the main issue, ie not shooting. But I’m prepared to be corrected.

Have now educated myself  :D
« Last Edit: 04 / April / 2019, 06:59:15 by pigeonhill »

Re: Landscape Focus Bracketing Script
« Reply #51 on: 04 / April / 2019, 13:00:43 »
OK, education is not complete.

I thought I could simply replace shoot() with click("shoot_full")

Code: [Select]
function myshoot()
    ecnt = get_exp_count()
    click("shoot_full")
end

However, I get very inconsistent results.

Should I wait for something to stabilize?

Hope one of the gurus can truly educate me.

Cheers

Garry

Re: Landscape Focus Bracketing Script
« Reply #52 on: 04 / April / 2019, 16:29:52 »
 :)
OK, worked it out: I think?

That is unless someone tells me I can make it faster  ;)

Code: [Select]
function myshoot()
    ecnt = get_exp_count()
    press("shoot_full_only")
    repeat
        sleep(50)
    until (get_shooting() == true)
    release("shoot_full_only")
    repeat
        sleep(50)
    until (get_shooting() == false)
end

*

Offline reyalp

  • ******
  • 14128
Re: Landscape Focus Bracketing Script
« Reply #53 on: 04 / April / 2019, 17:22:11 »
:)
OK, worked it out: I think?

That is unless someone tells me I can make it faster  ;)

Code: [Select]
function myshoot()
    ecnt = get_exp_count()
    press("shoot_full_only")
    repeat
        sleep(50)
    until (get_shooting() == true)
    release("shoot_full_only")
    repeat
        sleep(50)
    until (get_shooting() == false)
end
It's a little hard to comment without knowing the context. I guess other code presses and holds shoot_half, and uses ecnt for something?

Or are you not pressing shoot_half at all? If that's the case, I definitely would suggest switching to the hold shoot_half, click shoot_full_only approach.

1) In general, you the wait for get_shooting to be true should be after pressing shoot_half, before pressing shoot_full_only. Pressing shoot_full_only before get_shooting becomes true uses the "quick press" code path in the canon code, which can make overrides and possibly other stuff unreliable.
2) You shouldn't assume that get_shooting() will go false while shoot_half is held.
3) To detect when it's ok to release shoot_full_only (i.e ensure it's been held long enough to trigger the shot), I'd suggest using the hook_shoot script shooting hook https://chdk.fandom.com/wiki/Script_Shooting_Hooks#hook_shoot
Since you don't need shooting to wait in the hook, you can just use the count, something like
Code: [Select]
local prevcnt=hook_shoot.count()
press'shoot_full_only'
repeat sleep(10) until prevcnt ~= hook_shoot.count()
release'shoot_full_only'

hooktest.lua in the CHDK distribution and my fixedint script are some examples of scripts that allow the hold shoot_half, click shoot_full approach.

If you are feeling sporty, you could try using continuous mode instead (also available in the scripts above), but changing focus may be more suspect.
Don't forget what the H stands for.

Re: Landscape Focus Bracketing Script
« Reply #54 on: 04 / April / 2019, 17:34:30 »
@reyalp

Really appreciate your insight and I look into this tomorrow.

BTW the function will be used in my published landscape script https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89

Replacing the function at line 130.

Simply trying to get the script to run as fast as possible, but be robust.

Once again, thanks for your support.


*

Offline reyalp

  • ******
  • 14128
Re: Landscape Focus Bracketing Script
« Reply #55 on: 04 / April / 2019, 18:04:04 »
@reyalp

Really appreciate your insight and I look into this tomorrow.

BTW the function will be used in my published landscape script https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89

Replacing the function at line 130.
Thanks, that makes it clearer.

As written, your script will press 'shoot_full_only' without pressing 'shoot_half' at all. This is a physically impossible situation for the stock firmware, so definitely not recommended, and probably slower than holding half press or using continuous mode.

What I would suggest (and I think c_joerg was suggesting) is that you press shoot_half somewhere before the first shot, and keep it held down until after the last shot. To actually trigger a shot, you click shoot_full_only (and in this case, you can probably just use click'shoot_full_only' without the reliability problems you had before). I usually refer to this as "quick" mode in my scripts.

If you want to go even faster (on some cameras at least) you can use continuous mode with both half press and full press held, and use the hooks to control when shots are actually taken.

If you want to start incrementally, you could convert X_bracket to use quick or continuous mode.

With scripts using this approach, I generally use the raw hook to ensure exposure is set a consistent point in the canon shooting process (that is, hook_raw.wait_read(), set values, hook_raw.continue())

Setting focus while using these techniques may be questionable. I expect failing to set focus or crashing would be more likely than hardware damage, but CHDK comes with absolutely no warranty.

Note if you use the new style script header (https://chdk.fandom.com/wiki/CHDK_Script_Header#Lua_Shorthand_Parameter_Syntax ) you can use human readable names for the menu options. I highly recommend this.

Don't forget what the H stands for.

Re: Landscape Focus Bracketing Script
« Reply #56 on: 05 / April / 2019, 02:13:00 »
removed!!!!
« Last Edit: 05 / April / 2019, 02:17:57 by pigeonhill »

Re: Landscape Focus Bracketing Script
« Reply #57 on: 05 / April / 2019, 06:10:23 »
@reyalp

Have now spent a few hours 'playing' with various coding and have concluded the following:
  • Using shoot() may be a little slower than other 'quicker' approaches, but it is stable;
  • My script needs to move variable amount each focus bracket, thus I need to know the position of the last bracket;
  • This means, I believe, I must use either take an image or do a half-shutter, ie to register the last position
  • All this means that trying to speed up things, at least with my coding abilities, results in instabilities.
What I have done, however, is to defeature the original script, so that 'all' it does is create the 'perfect' focus bracket set (with exposure bracketing as well) from the current position to the required infinity blur position.

The draft of this script looks like below and I would certainly welcome your eagle-eye glancing over it, ie to see where I could improve it. If and when you have time, of course. Note in this version I am using the 'slower' shoot() and trying to manage knowing the current focus position.

Cheers

Garry

Code: [Select]
--[[
@title Fast Landscape Bracketing
'Perfect & Fast' 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
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
NOT FOR RELEASE
April 2019
Tested on a G7X
(c) Garry George
@chdk_version 1.5
# overlap = 3 "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 exposure & focus distance
t = get_tick_count()
repeat
    sleep(50)
    if get_tick_count() - t > 5000 then
        print("Unknown Error")
        release("shoot_half")
        return
    end
until (get_shooting() == true)
release("shoot_half")

s = get_tv96()
av = get_av96()
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
count = 0
ecnt = get_exp_count() -- used in the bookend function

-- A few Functions

function myshoot()
    ecnt = get_exp_count()
    shoot()
end

function bookend()
    if bookends == 1 then
        set_tv96(960)
        set_av96(640)
        myshoot()
        set_tv96_direct(s)
        set_av96_direct(av)
        repeat sleep(20) until (get_exp_count() ~= ecnt)
    end
end

function refocus(xx)
    set_focus(xx)
    sleep(1000)
end

function X_bracket()
    set_tv96_direct(s)
    count = count + 1
    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")
    sleep(delay*1000)
    bookend()
    X_bracket()
    bookend()
    return -- exit script
end

sleep(delay*1000)

bookend()

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

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

bookend()

refocus(x_start)
« Last Edit: 06 / April / 2019, 03:02:14 by pigeonhill »

Re: Landscape Focus Bracketing Script
« Reply #58 on: 06 / April / 2019, 05:46:07 »
@reyalp or some other kind CHDK Lua expert

I hope you can help with my weekend project: namely publishing a version of my landscape bracketing script that does one thing alone and stably, ie take focus bracket from the set focus point to the blur defined infinity, with or without exposure brackets.

I've decided to give up speed for stability, hence I'm using 'just' shoot.

All seems OK and the script works well, apart from one thing.

If requested, at line 156, I take the first bookend, ie a dark frame. I take one at the end as well.

I always get an end bookmark, but never a first one. I can't see why.

Line 156 must call bookend, ie I've tested it enters the if, but I never get an image captured.

I really need to get this sorted out before I publish and the problem with the first bookend image it's driving me mad!!!!

Here is the 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() == true)
release("shoot_half")

    s = get_tv96()
    av = get_av96()
    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 ;-)
    shoot()
end

function bookend()
    set_tv96(960)
    set_av96(640)
    ecnt = get_exp_count()
    shoot()
    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)
« Last Edit: 06 / April / 2019, 05:59:29 by pigeonhill »

Re: Landscape Focus Bracketing Script
« Reply #59 on: 06 / April / 2019, 14:45:22 »
OK, after hours of trying different things, at least I've got the script running as expected.

I don't understand why, but it looks like CHDK needs a few 'pauses' to get its act together.

Thus the bookend function above works if I inject a short delay:

Code: [Select]
function bookend()
    sleep(500)
    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

it's a mystery to me, but at least it's working  :)
« Last Edit: 06 / April / 2019, 14:55:36 by pigeonhill »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal