CHDK Forum

Using CHDK => Script Writing => Completed and Working Scripts => Topic started by: pigeonhill on 03 / January / 2019, 07:25:26

Title: Landscape Focus Bracketing Script
Post by: pigeonhill on 03 / January / 2019, 07:25:26
*** Go here for latest version: https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets) ***


This script does one thing. Namely, takes the 'perfect' focus stack from near to far and gives you exposure bracketing at each focus station.

I've written about the script on my blog: for example at: http://photography.grayheron.net/2019/01/landscape-focus-bracket-script-for- (http://photography.grayheron.net/2019/01/landscape-focus-bracket-script-for-g7x.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 05 / January / 2019, 04:23:23
I'm now publishing my Landscape Bracketing script at Rev 1.

You can download it from: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89 (https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89)

The script seamlessly covers from near to far and gives the following user options:In addition the script prints to the console the number of non-bookend images taken and the infinity blur in microns.

As usual I welcome any feedback on the script and ideas for improvement.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 06 / January / 2019, 10:09:53
Have tidied up a few things and added in a log file that looks like this for each bracketing sequence:
Quote
Sun Jan  6 15:52:21 2019

Image 3281 @ 218

Image 3282 @ 286

Image 3283 @ 418

Image 3284 @ 784

Image 3285 @ 1769

Image 3286 @ 5307

Took 6 brackets

Infinity blur 4um

*** FINISHED ***


The script keeps adding to a single log file (LOG_0001.txt), so you will need to delete when you don't need it anymore.

Latest rev can be downloaded from here: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89 (https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89)

There are a few things I'm still not happy with, eg to create the log file it still prints to the console, ie I can't work out how to just print to a file.
Over all however, the scripts works pretty well and should be well received by those seeking near to infinity perfect focus bracketing.

As usual I welcome any feedback.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 06 / January / 2019, 14:59:18
to create the log file it still prints to the console, ie I can't work out how to just print to a file.
You can't use the print( ) statement if you just want to log to a file.

Take a look at the printf( ) and lprintf( ) functions in the ultimate.lua (https://chdk.wikia.com/wiki/Ultimate_Intervalometer) script for an example of more sophisticated logging.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 06 / January / 2019, 16:35:02
@waterwingz

Thanks for the pointer to the intervalometer script, I’ll have a good read.

I am using print() at the moment, after using print_screen, however, doesn’t it still print to the console?
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 06 / January / 2019, 16:42:11
FWIW, I like to use CSV files for script logging. You can find framework for this in the drtest.lua in CHDK distribution, between
-- log module
and
-- end log module

This may well be more heavy weight than you want.

edit:
Some usage notes in https://chdk.setepontos.com/index.php?topic=13401.0
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 06 / January / 2019, 16:43:08
I am using print() at the moment, after using print_screen, however, doesn’t it still print to the console?
Yes, if you want just write to a file, you should use lua IO http://www.lua.org/manual/5.1/manual.html#5.7
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 06 / January / 2019, 17:15:16
I am using print() at the moment, after using print_screen, however, doesn’t it still print to the console?
Yes it does. That's why I suggested looking at the print functions in ultimate.lua.   Cut& paste them to your script. That's what I did, more or less, when I got them from reyalp.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 06 / January / 2019, 17:20:44
@waterwingz @reyalp

Many thanks to both of you for the insight.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / January / 2019, 15:19:42
Not sure if anyone has tried this script, or it's worth me putting in on the CHDK scripts page; however, here is the latest version, which adds in exposure bracketing (+/- or -/-- or +/++ around 0Ev) and tidies things up.
The script can be downloaded from here: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89
The unit of blur used in the script is the CHDK CoC for the camera.
Thus the overlap choices are none, ie each focus bracket just touches the previous one, or overlaps at 2CcC/3 or CoC/2.
The infinity blur final shot, ie the one taken beyond the hyperfocal, is taken at either CoC/2, CoC/3 or CoC/4.
The script creates a log of the focus positions by default.
As usual I welcome any feedback.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2019, 14:16:51
I’ve published the script now at https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 12 / January / 2019, 15:04:14
I’ve published the script now at Landscape_Focus_Bracketing (https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)
Nice!
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 16 / January / 2019, 12:09:32
Just updated the Landscape Bracketing script that gives the user the option to use a diffraction aware overlap criterion. This ensures, irrespective of aperture, that the total blur, ie defocus blur and diffraction blur taken in quadrature, equals the CHDK set CoC.

See: https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 21 / January / 2019, 13:44:53
Just updated this script, having refactored the code and tidied things up.

https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 02 / February / 2019, 12:01:31
Updated the script for robustness.
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 02 / February / 2019, 12:49:46
Updated the script for robustness.
It's somewhat interesting to be able to track the number of downloads a script gets.  I now host mine on GE.TT (http://ge.tt/) as it's one of the few download sites that keeps track of downloads and shares that data (ever since www.box.net stopped making that data available for free acccounts).
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 02 / February / 2019, 12:59:08
@waterwingz

Thanks, I’ll have a look.

I often think I’m the only user of my scripts ;-)

But that’s ok, as I write them for myself.

I must say, that my landscape bracketing script really makes my G7X and especially my G1X, into great travel cams.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 02 / February / 2019, 13:02:06
@waterwingz

Maybe I won’t use ge.tt, as my system says the site is not secure.
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 02 / February / 2019, 13:09:28
I often think I’m the only user of my scripts ;-) But that’s ok, as I write them for myself.
The heyday of interest in CHDK is long gone, mostly because the huge improvement in mobile phone camera quality over the last 10 years has basically gutted the low end of the "point and shoot" compact digital camera market.  While high end Powershots and mirrorless cameras continue to sell well, many of these already have most of the features CHDK adds to the lower cost simpler cameras.

That being said, I'm guessing that only a small percentage of people who take a look at CHDK and try it out ever post anything here.  So unless there is a bug in your script, you'll likely never hear much from people using your script.

Maybe I won’t use ge.tt, as my system says the site is not secure.
Chrome browser has started to get fussy about allowing you to access sites using just http: protocol - it wants to see https:   That's overkill in my opinion and certainly somewhat presumptuous.   

One of the things I do is compute an MD5SUM for my scripts and publish that value along with the download link. That way anyone downloading the file can confirm they have an unmodified copy of what I originally uploaded.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 02 / February / 2019, 13:21:02
@waterwingz

I must say I get confused by all that ‘extra stuff’ and reading that that checksum approach is not deemed secure and that you should use something like sha256sum.

BTW I really appreciate your insight and suggestions/help.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 07:28:18
Just updated the script: https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)

The user can now select from three focusing scenarios:
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 08:26:38
If you have a little time, can you post one or two images that you've created that show off the script's capability?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 10:37:29
@waterwingz

Tried multiple times: website not working :-(
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 12:47:13
website not working
Can you be little more specific?  "Website not working" is not a lot to go on.

Are you unable to attach images to a post? (there is an attachment sized limit). 

Are you unable to embed images into a post? 

Can you just upload to a file sharing site and post a download link? 

Can you upload to www.imgur.com and share the images that way (using the left hand edit button with the mona lisa picture on it).

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 12:58:50
@waterwingz

Sorry about the unhelpful comment.

Just tried again with two images at about 1Mb each. Page just goes blank when I post.

Mona Lisa ??? ??
Title: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 13:09:54
Just tried again with two images at about 1Mb each. Page just goes blank when I post.
Are you trying to attach the images?  Or embed the with the text?  Attachment works better.

Quote
Mona Lisa ??? ??
One of the formatting buttons in the full editor mode of the forum :
(https://imgur.com/Ficwub6.png)

<< if no image here - you are right, it's broken.>>

Image attached as well.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 13:23:00
@waterwingz

Sorry to be a pain: I see/use all those but where/what is the Mona Lisa button?
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 13:37:01
Sorry to be a pain: I see/use all those but where/what is the Mona Lisa button?
See the attached. If you look really closely, it's a picture of the Mona Lisa.

It inserts the BBS tags for an image  [ img ]   [ / img ]
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 13:45:44
Here are two example images that I took with my G1X using this script:
(https://imgur.com/a/XTGzrd1)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 13:47:02
Well that didn't work :-(
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 13:50:40
Well that didn't work :-(
yea - I'll post a note to the forum admin about that ...
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 15:26:56
OK: I'm getting frustrated now ;-)
I've tried uploading via the browse images but that didn't work :-(
So let's try via 'Mona Lisa' :-)
These two images were captured with this script on a G7X.
(https://imgur.com/a/izILG40)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 15:27:16
No: No good :-(
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / February / 2019, 17:36:19
Hopefully this post will work now. Another image example from my G7X running the script.


(https://chdk.setepontos.com/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fzcm3MOD.jpg&hash=e0cf49abb493d75259a12e0ff4a2da69)
Title: Re: Landscape Focus Bracketing Script
Post by: waterwingz on 10 / February / 2019, 18:58:50
Way cool. How many images did you stack?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / February / 2019, 01:58:33
@waterwingz

I didn't have the additional focus stacking options running when I took the image in the above post (Winchester Cathedral BTW). Now I would select Mac2Inf option and the camera would do a full focus stack from the camera's minimum focus to the blur defined infinity, say at 3xHF distance, ie giving an infinity blur of CoC/3.

For the above, I focused on the nearest tile and the script also took three exposures at each focus plane. Aperture was f/6.3 at a focal length of 8.8mm.

The script took four focus brackets, thus giving 12 images for post processing in LR (for the exposures) and Helicon Focus for the processed exposures.

I had bookends switched on, which means each bracket set is easy to spot in LR.

BTW here is another example of a 3x4 stack, ie 3 exposures at 4 focus stations.

(https://i.imgur.com/WxNsBCP.jpg)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / February / 2019, 16:33:36
Ok: one more/last image from my Winchester Cathedral trip with my G7X and the Landscape Bracketing Script:

(https://i.imgur.com/LK2FQ7d.jpg)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 16 / February / 2019, 15:59:08
The latest update adds two additional exposure bracketing options: https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets

The first exploits the 'fact' that most (sic) Canon cameras exhibit ISO-Less attributes above ISO 800, thus there is little point in ISO bracketing above this, ie simply create virtual copies of the ISO 800 and push in post. The ISO bracketing is useful when hand holding.
[Note I might add in a ISO1600 option in addition to the ISO800].

The second exposure option is to add in a Zero Noise (see Guillermo Lujik's work) option. That is a single +4Ev exposure time bracket.

As usual I welcome any feedback.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 20 / February / 2019, 03:02:39
Added what I hope is helpful advice on ISO invariance when ISO bracketing:
https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets
Key point being that you need to know if you camera can be assumed to be ISO less or not; and over what ISO range.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 21 / February / 2019, 11:37:43
Just posted on my blog about the script and thought some may find the post of value/interest: http://photography.grayheron.net/2019/02/more-focusing-stacking-with-chdk.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 24 / February / 2019, 03:07:38
Although I wrote this script for landscape/cityscape/xscape photography I thought I would test its stacking algorithm at the macro end. The test subject was a broken head of garlic in our kitchen.

I choose to use my G7X as this has a 50mm minimum focus, compared to a 200mm on my G1X. I also wanted to see how the script coped with a wide open aperture, ie F/1.8.

I used the Mac2X stacking option and focused on the far point of the head of garlic that I wished to see in focus.

I used diffraction aware overlap, although at F/1.8 there isn't a lot of diffraction.

The script refocused to 50mm and took 38 images.

After ingesting into Lightroom I selected 16 that covered the subject of interest. That is I could have placed the camera much closer to the head of garlic, but, of course, I wouldn't have been able to capture the entire scene.

[Note to self: look at adding an X2Y stacking option ;-)]

I did a round trip to Helicon Focus and tidied up the image in LR.

Shooting at F/1.8 was never going to create the sharpest of images, but overall I'm pleased with the robustness of the script.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 24 / February / 2019, 06:28:23
In the last post I suggested to myself to add a X2Y macro option.

I then realised I could achieve this really simply by implementing an additional focus backeting logic, ie current position (X) to y mm from X, ie X2DelX

I've thus updated the script and I'm beginning to convince myself there is not much more to add.

As an example, I just took this test image where I focused on the front of the garlic head and selected a delta of 30mm, to cover the bulb's depth. I shot at F/1.8 and the script took 19 images to cover the 30mm. I also used an overlap criterion of CoC/2 microns.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 24 / February / 2019, 10:01:55
One more example to show the script's ability to capture detail and control DoF.

In this example I set the aperture to the camera's minimum plus two stops, ie F/3.5.

I also used the zero-noise exposure option, ie at +4Ev.

I told the script to capture enough brackets for 30mm beyond where I first focused, ie at the front of the bulb.
 
Because I was focus and exposure bracketing the script took 18 images, ie 9 for focus and two exposures at each focus station.

Over all I'm pretty pleased.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 26 / March / 2019, 06:41:31
Interesting script and great results ...
I have a question about the following code section.

Code: [Select]
if u == 1 or u == 2 then -- change focus to min focus
    set_focus((4*fl)/10)
    press("shoot_half")
    repeat
        x = get_focus()
        sleep(100) -- seems to work on G7X & G1X, may need changing on other cams
    until x == get_focus()
    release("shoot_half")
end

Why do you focus on
Code: [Select]
set_focus ((4 * fl) / 10) and not
Code: [Select]
set_focus (0) to get the min focus?
That seems to work with the G1x.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 26 / March / 2019, 07:20:05
Regarding the use of 4*Fl.


I originally had (0) as you suggest and it works fine.


There is still a little confusion in my mind regarding where is zero for CHDK focus reporting, ie the sensor plane or at some position within the lens.


The 4*Fl is often reported as the min focus of a generic lens relative to the sensor.


Bottom line: I think 4*Fl or 0 will give the same result, ie the lens will focus at its minimum.


Cheers


Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 26 / March / 2019, 13:01:09
There is still a little confusion in my mind regarding where is zero for CHDK focus reporting
I thought the values come from the Canon firmware ...
the sensor plane or at some position within the lens.
I find exactly the values that are synonymous in the manual. For the S110, that's 30mm (wide angle). I would say that's the distance from the front lens to the object.
The 4*Fl is often reported as the min focus of a generic lens relative to the sensor.
I haven’t checked my SX50hs yet, but the manual says 0!
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 26 / March / 2019, 13:18:39
If it says zero, then it can’t be the sensor.

As I say, using simple lens theory, ie ignoring the principal planes being separate,  the min focus to the sensor plane is 4*FL. My understanding is that min focus can be more than 4*FL, but not less, unless the lens design is exotic.

Bottom line: unless you are well towards the macro end, the simple theory is good enough...I believe.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 31 / March / 2019, 08:31:42
I've tried the script now. Have fun working with it.
At first, I wondered about the black images. But they really make sense for the post processing.

What you can improve in any case is the speed. You could definitely leave the camera in the press ("shoot_half ") and then only ever perform a press (" shoot_full_only ") and release (" shoot_full_only "). In that case you could run the script in AV mode as well because exposure not change.
I saw another script running in continuous mode. This can be done on a SX50 in burst mode with 6.8 JPG photos / sec.

I have not much experience in the stack. Can you tell me where the artifacts come from (second image)? I use Adobe CS6 for stacking.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 31 / March / 2019, 09:03:37
@c_joerg

Thanks for the feedback.

Yes I did play around with making it work in all modes, ie other than M, but I’m an M shooter so I decided to satisfy myself first ;-)

The artefacts result from the fact that each image needs to be scaled before focus blending, as we are not using a cine lens.

Photoshop thus does what it thinks is best and masks each layer according.

Have you gone into each layer and corrected the blur? That is manually adjust the masks that PS creates for each layer.

BTW I use Helicon Focus, which allows you to choose different algorithms.

I also use Zerene Stacker. 

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 03 / April / 2019, 04:15:52
Yes I did play around with making it work in all modes, ie other than M, but I’m an M shooter so I decided to satisfy myself first ;-)

M is fine for me. But to use the script in the landscape, you definitely have to increase the speed. I don’t think it is complicated to use at least the half press mode.


Have you gone into each layer and corrected the blur? That is manually adjust the masks that PS creates for each layer.

Do you have any example (link) how to adjust the masks manually?

BTW I use Helicon Focus, which allows you to choose different algorithms.
I tried Helicon Focus with all 3 Methods. More or less, however, the problem also occurs here in the same place.


About the Overlap
CoC is none? And default is CoC/2?

From the distance in your log I calculate near and far with the DOF calculator (values attached).
From my experience in the past I could say, setting of focus is not accurate. For example if you write a script which changes the focus always from 1000mm and 10000mm, and then you investigate the pictures with same settings, you will see that the focus differs. That might be a problem with the overlap.


I have a little bit problems to understand which mode

Code: [Select]
X2Inf Mac2Inf Mac2X X2delX
Fits the following description

Quote
In macro mode, eg using Macro2X or X2DelX, the script will take as many images as required, ie without warning how many!

In order to cover various needs, the user can select from the following focusing scenarios:
From the current focus to the blur-defined Infinity
From the minimum focus to the current focus
From current focus to a specified number of mm beyond the current position
From the minimum focus to the blur-defined Infinity
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 03 / April / 2019, 13:48:33

“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
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp 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 (https://chdk.setepontos.com/index.php?topic=12695.0) 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.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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.

Title: Re: Landscape Focus Bracketing Script
Post by: reyalp 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.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 05 / April / 2019, 02:13:00
removed!!!!
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 05 / April / 2019, 06:10:23
@reyalp

Have now spent a few hours 'playing' with various coding and have concluded the following: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)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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  :)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 07 / April / 2019, 02:15:56
@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)


Title: Re: Landscape Focus Bracketing Script
Post by: reyalp 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.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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)
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp 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.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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 :-)
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp 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.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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 (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
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill 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 (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.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 03:17:29
The new style script header makes Script really readable now ...

I'm not sure about the Overlap. CoC means I have the largest overlap and therefore a larger number of images?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 07:11:38

@c_joerg


An 'overlap' at a blur of CoC means that the focus brackets touch at a blur of CoC.


An overlap ay a blur of 2CoC/3 means that the focus brackets touch at a blur of 2CoC/3 < CoC = more brackets, but higher 'focus quality' throughout the scene.


BTW I've already seen a few areas where I need to tidy up my coding: will this hell never end  ::)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 11:37:22
An overlap ay a blur of 2CoC/3 means that the focus brackets touch at a blur of 2CoC/3 < CoC = more brackets, but higher 'focus quality' throughout the scene.

Thanks, i understand now...

I play a little bit with the script…

Why you removed the interesting log files?
I would also log TV, AV, ISO, focal length….


I don’t find a description what
Code: [Select]
# delx = 1 "Focus depth (mm)" [5 100]is doing and why the default is out of range?

Then I had a strange problem. I set manually in M Mode TV=1/10s and AV=5.6
The first picture where made with TV=1/40s and AV=2.8 (with correct exposure) and all the other pictures have TV=1/40s and AV=5.6. But the problem only happens on one of 3 tries.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 13:15:49
@c_joerg  (sorry don't know your first name)

Many thanks for testing out the script: I really appreciate your time and feedback.

The delx menu was a typo: should have been
Quote
# delx = 10 "Focus depth (mm)" [5 100]

As for what is delX doing, have you looked at the updated words here: https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)

I added in a graphic that shows the various focusing strategies.

I've also tided up a few bits of code: https://gist.github.com/pigeonhill/3fe9e52621db7149eb3505bd60b395cb (https://gist.github.com/pigeonhill/3fe9e52621db7149eb3505bd60b395cb)

As for your exposure variation, I can't see why that occurs? Maybe you can test with the latest release?

Also, I have noticed that the restore() function, which in Lua is meant to be triggered by an interrupt, eg a shutter press, doesn't always work. Maybe I've coded it incorrectly?

Finally, I will add back in the log file, just for you ;-)

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 13:35:53
(sorry don't know your first name)
Joerg
Many thanks for testing out the script: I really appreciate your time and feedback.
Thank you is on my side; I have already learned a lot...
Finally, I will add back in the log file, just for you ;-)
It’s not for me, the day will come where it helps you with the error search…
Here you can find a logfile from rawopint. The files were always a great help in the search for errors.
https://chdk.setepontos.com/index.php?topic=12761.msg137365#msg137365

Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 13:58:43
I can reproduce the problem:
First run was with f2.8 and TV=1/15s. Everything was OK

The I change to f5.6 an TV=1/5s
First shoot has f2.8 and TV=1/15s.
All other shoots have f5.6 and TV=1/15s.

May be the problem comes from av and tv setting in bookend()
There is no log file…
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 14:03:48
Strange, as the script grabs the shutter speed and aperture at the start, after locking the script into M mode.

BTW did you do the test with the latest versions?
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 14:27:53
BTW did you do the test with the latest versions?

Rev 1.32
If you can’t reproduce it, you should log everything with timestamp.
I would log also the version and all current settings.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 14:42:40
@c_joerg


Just tried it out on my G7X and all ok.


BTW did you try a half shutter press after you changed the settings.


You shouldn’t have to as the script does this, but you never know.


Not sure what logging would do to help me sort things out, as I don’t see the problem  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2019, 14:54:49
BTW did you try a half shutter press after you changed the settings.
Yes

Not sure what logging would do to help me sort things out, as I don’t see the problem  ;)
May be it depends on the settings….
I would log all values (AV,TV, Focus…) immediately after you read them and all values which you write (set_xxx) to the cam…
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 15:03:25
Just did some testing and I think I don’t fully understand modes.


I just did a test from Av mode.


If I just switch between Av and M mode, the Av exposure looks ok and the shutter speed is ok. But if I switch from Av to M the shutter speed is too fast, ie image dark.


What I need to do is work out how to come into the script from, say, Av mode and get the right Av set shutter speed.


More thinking required I think.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2019, 15:24:16
@c_joerg

If you have the time, maybe you can try this version and see if it fixes your problem?
https://gist.github.com/pigeonhill/3fe9e52621db7149eb3505bd60b395cb
Fingers crossed  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / April / 2019, 12:11:02
If you have the time, maybe you can try this version and see if it fixes your problem?

Looks OK  :)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / April / 2019, 12:38:54
@c_joerg

 :D
Many thanks for testing.

The 'issue' was related to PowerShot deficiencies and me not fully appreciating them.

PowerShot Av mode is limited to 1s Tv, thus you should never use Av mode with a Tv reported value of 1s, as you don't know if it is 1s.

Also if you switch to M mode from Av, the Tv value isn't transferred to M mode by Canon.

Anyway, hopefully the script is now solid.

BTW I did a test shot on the way home that gives a flavour of the script's capability, although I should have focused a little closer to the camera.  Also, I used f/8 rather than the optimum aperture of f/5.6.

Once again, thanks for all your support and feedback.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 13 / April / 2019, 07:45:12
BTW I did a test shot on the way home that gives a flavour of the script's capability, although I should have focused a little closer to the camera. 
Such shots can only be done in absolute calm, right?
Also, I used f/8 rather than the optimum aperture of f/5.6.
Here is a script where you can find the optimum aperture. Most of my P&S with small Senor had there optimum already with open aperture.
https://chdk.setepontos.com/index.php?topic=13532.30


About focus bracketing strategies:
From -DelX to +DelX (around the current position) might be a good range…

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / April / 2019, 09:15:12
@c_joerg

'Best' here means 'best' balance between defocus blur and diffraction blur. Plus, of course, this then needs to be balanced out with intrinsic lens quality.
Which is why F/5.6 on G7X is pretty good for 'best' quality, over all.
By the way have added in the -Del to + Del option: https://gist.github.com/pigeonhill/3fe9e52621db7149eb3505bd60b395cb
Will update CHDK words this weekend.
Cheers
Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 08 / January / 2020, 10:05:10
I have used the script 'Get Brackets.lua' Rev 1.5 for a long time on the G1x. All settings default, only display is on. Camera mode is M.

With AF everything is ok.

If I set the focus manually, then the script hangs. A picture is taken and then it's over. Have you ever tried that?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / January / 2020, 11:54:10
I’ll take a look when I can.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / January / 2020, 13:35:30
@c_joerg


Just had a quick look and all looks ok at my end.


I always set the focus manually and as I say, I can’t make the script not work.


A bit of a mystery, as the script sets itself to Manual exposure mode and manual focus mode.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 09 / January / 2020, 11:59:46
I update now to latest CHDK release.
Now the script doesn’t work anymore. Made only one shoot. Video attached.
I miss the text output from an older version. I have attached the script used.
I haven’t debug yet but maybe it waits in

Code: [Select]
hook_shoot.count() or hook_raw.count()
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / January / 2020, 12:49:07
@c_joerg


I have CHDK 1.5.0 and, as I say, the script works fine.


Not sure what else I can do to help resolve your issues.


Cheers


Garry
Title: Re: Landscape Focus Bracketing Script
Post by: Caefix on 09 / January / 2020, 12:54:09
The following error or errors occurred while posting this message:
The message body was left empty.  :blink:
Does it help ?
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 09 / January / 2020, 13:03:17
I have CHDK g1x 100e 1.5.0 5399
Not sure what else I can do to help resolve your issues.
If I found some time; I would put some text messages in like
Code: [Select]
Shot Number
Shot at focus=xxxx,
Next shot at focus=xxx
Script finished because….
I still think the script waits here, because of different timing (SD Card)
Code: [Select]
        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()
May be a timeout with error messages  in this loop,


Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / January / 2020, 13:53:12
@c_joerg


I have 5153 and it works.


I’m not sure what 5399 does, compared to 5153.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / January / 2020, 14:32:29
Maybe someone who understands the core CHDK can throw some light on this, ie why version 5133 works but 5399?
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 09 / January / 2020, 14:35:12
Attached the script with prints and log files.
I run the script three times in MF Mode. The first two times it works.
The third time, the script makes only a Bookend Shot and not more. I have to stop the script by pressing shot bottom.
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 09 / January / 2020, 14:38:07
I have 5153 and it works.
I’m not sure what 5399 does, compared to 5153.
The difference might be camera settings, or even scene. I don't see any significant changes to the G1x port between 5153 and now.

If the hooks aren't being reached in some situation, that's probably a CHDK bug. The other obvious place it could maybe wait forever is waiting for get_shooting to change. That could be a CHDK bug, or possible related to scene and canon settings.

If you use hookutil instead of waiting for hook_*.count directly, you get timeout support free. You do have to set the hook in that case.
Code: [Select]
require'hookutil'
hook_shoot.set(100) - wait up to 100ms in hook
...
hook_shoot.wait_ready{timeout=2000} -- wait two seconds. Default is 10 sec.
hook_shoot.continue()
...
By default, it will use error() if the hook times out. You can make it non-fatal with
Code: [Select]
if not hook_shoot.wait_ready{timeout=1000,timeout_error=false} do
...

edit:
updated code, probably safer to explicitly use continue()
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 09 / January / 2020, 14:40:42
Attached the script with prints and log files.
I'd suggest a print before / after each point the script waits for get_shooting or a hook.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 10 / January / 2020, 03:11:13
I'd suggest a print before / after each point the script waits for get_shooting or a hook.

For the hook, I did it already:

 
Code: [Select]
   print("Shot 1",os.date("%X"))
    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()
    local dof=get_dofinfo()
   
    --print("TV=",tv96_to_usec(get_tv96())," AV=",av96_to_aperture(get_av96())," SV=",sv96_to_iso(get_sv96()))
    print("Hyp=",dof.hyp_dist," FL=",dof.focal_length," EFL=",dof.eff_focal_length)
    print("F=",dof.focus," Near=",dof.near," Far=",dof.far)
But when the script stops, I don’t see the print  “Shot 1”. So the problem is not on this point.

I will add print also for the get_shooting.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / January / 2020, 03:52:31
@c_joerg


Thanks for putting effort into resolving this. As it seems to only be an issue on the latest build, which I don’t have, I’m afraid I can’t add much.


BTW I didn’t know there was a new build  ;)


Do you know what the latest build does, relative to the previous builds?
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 10 / January / 2020, 04:10:35
Do you know what the latest build does, relative to the previous builds?
There's a new build every time a change is checked in, but that doesn't mean it has any effect on existing ports.

As I posted earlier, I didn't see anything likely to impact g1x, or obvious candidates in changes to generic code. My suspicion is factors other than the build. Aside from settings and scene, there are sometimes bugs that only affect the port for one firmware version of a given port.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / January / 2020, 04:34:52

@reyalp


Thanks for the update, let’s hope @c_joerg can find some time to investigate, as I said, I don’t see the error on my version.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 10 / January / 2020, 05:08:38
There's a new build every time a change is checked in, but that doesn't mean it has any effect on existing ports.

My first test with the script was with Rev 5157. Problems where similar.
I still think it’s timing Problem

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / January / 2020, 11:34:59
@c_joerg

Quote
I still think it’s a timing issue
If so, I don’t understand why I never see the issue.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / January / 2020, 13:54:50
I'd suggest a print before / after each point the script waits for get_shooting or a hook.
I have now inserted a text output before and after every get_shooting. Now I don't have the problem anymore (20 runs without problems).
Unfortunately, I don't have my second G1x with other firmware available at the moment.

If so, I don’t understand why I never see the issue.
Different conditions…
Different Firmware of G1x, only RAW, different size and speed of SD card…

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / January / 2020, 14:01:51
Quote
I have now inserted a text output before and after every get_shooting. Now I don't have the problem anymore (20 runs


I guess indicating a short delay needs to be inserted at a critical time?


As I say, with my setup and card etc, I don’t see the error.


Once again, thanks for all your investigations.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / January / 2020, 14:20:30
I guess indicating a short delay needs to be inserted at a critical time?

Yes, I think so, too...
I can live with the prints  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / January / 2020, 14:24:33
@c_joerg


Maybe, if you get the time, you could replace the prints with a delay and confirm this helps.


Despite not seeing the problem here, I’ll update the script according to your findings, ie for the record.


Cheers


Garry
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 11 / January / 2020, 16:13:14
I have now inserted a text output before and after every get_shooting. Now I don't have the problem anymore (20 runs without problems).
I would be quite surprised if a print triggered enough delay make a difference. My guess is there is some other factor involved, perhaps related to the scene you are shooting. OTOH, I have been surprised before ;)

Having timeouts for get_shooting loops would generally be a good practice.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / January / 2020, 17:02:33
@reyalp

Quote
Having timeouts for get_shooting loops would generally be a good practice.

My current shoot function looks like the:

Code: [Select]
function myshoot() -- works inside X_bracket function
    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
I guess you are suggesting putting in the repeats above.
But doesn't this ignore the question: why is it occurring. As I say, I use the same script, but have never seen the error that @c_joerg has observed.
Strange.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / January / 2020, 17:14:59
My guess is there is some other factor involved, perhaps related to the scene you are shooting.
The scene was always the same.
Indoor, tungsten light, low light,…  in M Mode.
The next days I will replace the prints by sleep.

Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 11 / January / 2020, 17:37:14
I guess you are suggesting putting in the repeats above.
From c_joerg's description, my impression is the failure is occurring in one of the sections like
Code: [Select]
    press("shoot_half")
    repeat sleep(10) until get_shooting()

rather than in the myshoot parts you quoted. I did suggest earlier you include a timeout in myshoot: https://chdk.setepontos.com/index.php?topic=13638.msg142296#msg142296

Quote
But doesn't this ignore the question: why is it occurring.
On some cameras in some scene and/or setting dependent situations, get_shooting() may never becomes true after half press. Some also fail to shoot after shoot_full is pressed, see https://chdk.setepontos.com/index.php?topic=7611.msg96494#msg96494

shoot() attempts to handle this by timing out in get_shooting and retrying shoot, but if you use button presses you need to deal with it yourself. There should probably be a utility function like hookutil wait_ready for get_shooting, but no one has got around to adding it.

edit:
That said, it's certainly possible that there are issues specific to script, or other bugs in CHDK.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / January / 2020, 03:03:11
My guess is there is some other factor involved, perhaps related to the scene you are shooting.

Maybe the scene after all ...
I wanted to do a direct compare today. First the original script without text, then my modified version with text.
The scene was changed slightly. The old bouquet was no longer there.
I am currently unable to reproduce the problem ...

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 04:18:40
@c_joerg

I found some time this morning to play around with the script.
Could you try this version: https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d
Ideally on the same scene that forces the other version to not work.
This version seems to work for me  ;)
Cheers
Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 06:12:15
@c_joerg


BTW I forgot to ask, what focus logic are you using when you see the problem?


Also, does the script freeze in alt mode, or just terminate?
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / January / 2020, 10:50:19
BTW I forgot to ask, what focus logic are you using when you see the problem?
I’m setting MF to around 0.5m. All parameters are default, only display is on.
So focus logic is X2Inf.

Also, does the script freeze in alt mode, or just terminate?
After shooting the bookends the camera is still in alt mode.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 10:57:30
@c_joerg


Thanks. I asked because there is a problem with the script if you select, say, Min2Inf and your base position is greater than the hyperfocal. An easy fix once I know if there are other ‘fixes’.


If you could test the other version(s) I pushed out that would be great. But only when you get a chance, as I said, my end looks OK  :)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / January / 2020, 11:21:50
Could you try this version: https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d
 
I tried it…
I’m setting MF to around 1m. All parameters are default, only display is on. So, focus logic is X2Inf.
M Mode TV=0.5s; f5.6; ISO100; Focal Length 21.3mm.
Indoor, tungsten light and camera is on tripod.

First run. The same problem :(
After shooting the bookends the script stops.  Still in alt mode. No text message seen. After one minute I stop the script with the shoot button.

Run 2-5. Everything is ok. No problem. Text message seen. Nothing has changed between the first run.

Camera off /on.
Same settings as before. No problem with 3 runs….
It’s confusing.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 12:03:21
I just downloaded the same version you have, to eliminate that as a difference between us.


I then used your settings.


All looks fine at my end. The script prints out the focus logic, ie 0, then prints out the x, start, stop. All looks ok.


Do you still get the hang up if you switch bookends off?


The only difference between us is the CHDK version  ;)


I don’t know where to go from here.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / January / 2020, 12:24:09
The script prints out the focus logic, ie 0, then prints out the x, start, stop. All looks ok.
When it runs, I got the same…
Do you still get the hang up if you switch bookends off?
I have not tried.
Difficult to find out when I had just one error…

The only difference between us is the CHDK version  ;)
Firmware of the cam, SD card…

I don’t know where to go from here.
Most time it runs now. I can live with it.
When I got my second G1x back I will try with this cam.
I will add additional prints to see, if we got more information’s.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 12:27:22
@c_joerg

On the assumption the problem is in the bookend function, I've changed things.
Could you try this and try and replicate the error: https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d
If this works I'll up issue the code and get rid of the prints.

Cheers
Garry

Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 12 / January / 2020, 13:04:58
On the assumption the problem is in the bookend function, I've changed things.
Three attempts without errors. Lets see how it goes on...
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 13:06:01
 :)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 13:26:37

@reyalp



If, fingers crossed, we’ve narrowed down the issue @c_joerg was having to this


Code: [Select]
repeat sleep(10) until (get_exp_count() ~= ecnt)


Can you throw some light on this, why the latest version throws up the error, but the previous one didn’t.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 15:15:59
@c_joerg

Have tidied up the non-M3 version of the script and the pre-release version is here: https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d (https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d)

Thanks for all your support in flagging up the issue and helping to sort things out, although I have no idea what was going wrong and still don't  ;)

If I don't hear from you in the next couple of days, I'll assume all is OK and I'll update the script on the CHDK site.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 12 / January / 2020, 17:11:26
If, fingers crossed, we’ve narrowed down the issue @c_joerg was having to this

Can you throw some light on this, why the latest version throws up the error, but the previous one didn’t.
IMO, again, it's extremely unlikely that it actually depended on CHDK build. If I understand correctly, the problem was intermittent for c_joerg, so the simplest explanation is that it depends on other, unknown factors.

The only way I could see
Code: [Select]
    local ecnt = get_exp_count()
    shoot()
...
    repeat sleep(10) until (get_exp_count() ~= ecnt)
failing is if shoot() failed to shoot, or the exposure counter being totally broken on that port. shoot failing is possible, though I think very rare with existing retry logic. If the exposure counter were broken, it would likely have been noticed a long time ago. AFAIK nothing significant in these areas (or really, any other area) has changed for G1 X between the versions mentioned earlier.
But there's a lot of other changes in the script so it's not clear to me that was the problem. Switching myshoot to use shoot() instead of hook loops without timeouts seems more likely.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / January / 2020, 17:55:57
@reyalp

Understood and I'm certainly not challenging your insight ;-)

I've been frustrated as I simply can't replicate the issues that @c_joerg has been having.

Thanks for all your support, as always.
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 12 / January / 2020, 18:18:15
Understood and I'm certainly not challenging your insight ;-)
FWIW, if there were changes in the g1x port or core code related to shooting, then those would be the obvious place to start looking. But in this case, pretty much all the recent changes have been specific to other ports or in areas unlikely to be related to the symptom.

There's still the possibility that a minor change in where things end up in memory or timing could expose a bug, but that doesn't really give anything to investigate without clearly identifying what exactly is failing.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 13 / January / 2020, 12:42:00
Today I made a lot of runs with your latest version. All X2Inf. I did runs with an overlap CoC and CoC/2. The last problem should be solved. But I came to another problem.
On higher focal length (42mm) and CoC/2 the focus did not change anymore but the script still shoots.
Then I add prints again in your script. Log attached.
I find out, the script works for a while, and then it makes 41 shot with same focus and exposure.
Code: [Select]
F= 6849  Near= 5102  Far= 10411Then the script moves, made 2 shots and then it starts again with a lot of shots with same focus.
Code: [Select]
F= 6856  Near= 5106  Far= 10428I think, the script comes to a point, where the focus difference is too small.

I can’t understand why you remove the prints. I would always have prints in my script with logging of script params, focus, far, near, focal length, AV, TV, ISO. That really helps in these conditions.


Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / January / 2020, 13:01:36
@c_joerg


Personally I would not use the script beyond, say, 30-40mm, as, as you found, the equations may break down and you will end up with loads of focus brackets.


Also you could increase the overlap criterion to coc, ie not so low. Coc/2 is very low.


In an earlier version I did have a feature to handle this situation, I’ll retook at that in the light of your findings.


Bottom line: Focus bracketing works well at the wide end, but don’t go too long.


Plus, looking at your log, I think you have maxed out the info that CHDK can provide. Once again, I’ll look at putting in a check for this situation.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / January / 2020, 13:15:35
@c_joerg


CHDK’s limits are quoted as 0 to 65535 (millimeters)

Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 13 / January / 2020, 13:21:40
CHDK’s limits are quoted as 0 to 65535 (millimeters)
That's outdated. On many modern cams, it goes beyond 64K. But which values correspond to distinct focus settings and when it starts reporting -1 is not well specified.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / January / 2020, 17:40:59
@c_joerg

I wrote this script for my photography needs, which are highly biased towards wide angle photography, so I never tested the script at the long end.

The script uses the CHDK hyperfocal's CoC as the overlap, hence when you choose CoC/2, the script scales the CHDK H to 2*H when bracketing up to H/3. It then inserts two other images at H and H times the infinity criterion you selected.

Your example needed a large number of brackets. BTW you can get an estimate of the number of brackets from (1+H/x)/2. In your example the CHDK H is 19933 which is doubled as you chose CoC/2. You started at 687, which means about 30 brackets.

I've changed the code and now you can specify the maximum number of brackets. I personally think 10 is a good max, but it's your choice.

I've also changed the code so that it doesn't hang, ie it just terminates that part of the bracketing if it has a problem. That is you should always get something.

The latest version can be downloaded from here as usual: https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d (https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d)

Bottom line: if things start terminating at a (long) focal length, then back off the overlap and/or shut down the aperture, ie lowering the hyperfocal. You may get more diffraction, but that's life  ;)

Once again, thanks for the testing and feedback.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / January / 2020, 13:11:15
@reyalp


I’m finalising a new release of my script and am testing it out and noticed a ‘strangeness’.


The version is here https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d (https://gist.github.com/pigeonhill/7056282940415f7d99e0cc8688f48a0d)


The strangeness is that as the script progresses I notice that the CHDK hyperfocal distance seems to change between taking an image and moving the lens, eg 2.84 vs 3.01.


The obvious strangeness is, without changing focal length or aperture, why does the CHDK reported hyperfocal change.


Is this expected?


BTW I am thinking of explicitly calculating H myself, rather than rely on CHDK reporting.
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 14 / January / 2020, 16:32:20
The strangeness is that as the script progresses I notice that the CHDK hyperfocal distance seems to change between taking an image and moving the lens, eg 2.84 vs 3.01.

The obvious strangeness is, without changing focal length or aperture, why does the CHDK reported hyperfocal change.

Is this expected?
Without digging deeply into either the DOF calculator code or the script, I'd guess some value in the calculation is only updated in halfpress, or calculated differently when not in half press. The most likely candidate is aperture.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / January / 2020, 17:15:17
@reyalp

Sorry, I appreciate I'm asking a difficult question without you spending time looking at my code.
However, I have looked into the strangeness, and it doesn't appear to be my code.
If I put my G1X into M mode and MF and do a half shutter press, the CHDK reported hyperfocal distance changes.
As I say, strange.
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 14 / January / 2020, 17:35:22
If I put my G1X into M mode and MF and do a half shutter press, the CHDK reported hyperfocal distance changes.
Sorry, I guess the previous reply wasn't clear:
* Some information is only updated on halfpress, or only reflects what the camera will use during half press. This is a characteristic of the Canon firmware, not just CHDK or your script.
* The DOF calculator code (see http://subversion.assembla.com/svn/chdk/trunk/core/shooting.c shooting_update_dof_values) does things differently depending on various conditions, including whether get_shooting() is true.
* I did not write this and do not fully understand either the code or the original intent. Some aspects of it appear questionable to me.
* Bottom line: getting different results in / out of half press is not surprising. Values obtained in half press should be more likely to be right, but there could be bugs in either case.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / January / 2020, 17:46:29
@reyalp

Thanks for the education, I'll look into things and decide what way to go, i.e. live with the CHDK data, or generate my own.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 14 / January / 2020, 18:28:39
Thanks for the education, I'll look into things and decide what way to go, i.e. live with the CHDK data, or generate my own.
FWIW, if you decide to roll your own, you'll most likely still have to address the half press or not issue, but you get to decide how to do it. If you operate only in M mode, you can use the USER propcases, which should always reflect the set value.

One of the parts of the current DOF calculator that I find questionable is that it uses shooting_get_current_av96 (in some case, the logic of which aren't immediately obvious to me), which is the current physical aperture value at the time of the call. This may not reflect the set aperture at all, even in half press.  I actually expected shooting_get_current_av96 to reflect the set value in half press, but from testing on g7x just now that does not appear to be the case.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / January / 2020, 01:49:39
@reyalp

Quote
but you get to decide how to do it.

I only need get the focal length, CoC and aperture at the start of the script.

I don't change aperture, just use it to calculate diffraction. I currently use dof.aperture, I wonder if I should use get_user_av96 instead?

One thing I'll do is switch off CHDK DoF feedback and explicitly screen print out the progress in the script, eg focus and how many brackets will be needed etc.

I also use get_tv96() and get_av96(). Once again, any suggestion regarding getting the 'correct' values would be welcome. For example, is this the 'best' way:

Code: [Select]
press("shoot_half")   
repeat sleep(10) until get_shooting()
s = get_tv96()   
av = get_av96()
release("shoot_half")
repeat sleep(10) until (not get_shooting())

I guess the same question for setting. I currently use

Code: [Select]
set_tv96_direct(s)
set_av96_direct(av)
set_sv96(sv96_market_to_real(iso_to_sv96(1600)))
Do you consider this the 'best way'

Once again, thanks for your assistance in helping me understand the differences between my normal Lua environment (ML) and CHDK's.
Title: Re: Landscape Focus Bracketing Script
Post by: reyalp on 15 / January / 2020, 03:14:53
Quote
but you get to decide how to do it.

I only need get the focal length, CoC and aperture at the start of the script.
I would expect that you could just get dof_info once, inside the initial half press after get_shooting becomes true.

Quote
I don't change aperture, just use it to calculate diffraction. I currently use dof.aperture, I wonder if I should use get_user_av96 instead?
The "user" values should be the value set in the canon UI for M/Av/Tv modes. If you are just getting the values once, getting the regular av96 inside half press should be fine.

I would hope the dof aperture value is equivalent to the av96 if you get it in half press, and it seems to be in a quick test, but the code is complicated enough that I'm not totally sure it is in every case.

I did verify that dof aperture can return different values outside of halfpress, so I would recommend not calling get_dofinfo outside of half press.
Quote
For example, is this the 'best' way:
Code: [Select]
press("shoot_half")   
repeat sleep(10) until get_shooting()
s = get_tv96()   
av = get_av96()
release("shoot_half")
repeat sleep(10) until (not get_shooting())
As long as waiting for the extra half press cycle isn't an issue (which I expect it isn't in your case) that seems like a good way to me.

Quote
I guess the same question for setting. I currently use

Code: [Select]
set_tv96_direct(s)
set_av96_direct(av)
set_sv96(sv96_market_to_real(iso_to_sv96(1600)))
Do you consider this the 'best way'
That should be fine. Note that overrides take effect for the next shot or half press cycle only. I noticed your script has code like
Code: [Select]
function bookend()
    set_tv96_direct(960)
    set_av96_direct(640)
    local ecnt = get_exp_count()
    myshoot()
    set_tv96_direct(s)
    set_av96_direct(av)
    press("shoot_half")
    repeat sleep(10) until get_shooting()
    sleep(500)
    release("shoot_half")
    repeat sleep(10) until (not get_shooting())
end
which will effectively throw away the the set tv/av values. It will set the propcase values, but they will normally be clobbered in the next half shoot.

ISO override has another quirk: after you use set_sv96, ISO mode is effectively set to auto after the shot the override is used in. So you should either set sv96 for each shot, or set ISO_MODE to a specific value. If you are only using specific, standard ISO stops like ISO 1600, you can just set ISO_MODE and not use set_sv96.

ISO_MODE stays set until ISO is changed in the UI or set_sv96 is used, so you don't need to set it every shot.

If you do use set_sv96, it's a good practice to save ISO_MODE at the start of the script, and restore it at the end.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / January / 2020, 07:50:16


@reyalp


Many thanks for finding the time to educate/help me.


As I say, I'm used to ML Lua, not CHDK Lua.


I'll be up issuing my bracketing script soon and will refresh the CHDK info for it.


I'll then tweak the M3 version, which is different to the 'standard' CHDK version.


IMHO my script is a great tool for the landscape 'bracketeer', ie seeking a one stop shop for exposure and focus bracketing. But then again, I would say that, wouldn't I  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: Caefix on 15 / January / 2020, 12:58:44
( ( ( :-X
void shooting_update_dof_values()      /// (not my code...) :haha

I´m not shure, haven´t verified on tripod, but dof.... seems to be influenced by...
zooming in | out, zoom steps, speed,...

&&   That could be useful values for Lua & Ubasic, too:
   camera_info.dof_values.distance_valid
   shooting_get_prop(camera_info.props.metering_mode)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / January / 2020, 14:37:58
@Caefix


I’m sorry to be blunt, but often see you posting here, but I have no idea what you are talking about.
Title: Re: Landscape Focus Bracketing Script
Post by: Caefix on 15 / January / 2020, 14:54:18
 :o `C´ stands for conspiracy, I guess, as allways.
Sorry for not endian confusion.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / July / 2020, 10:01:00
Just an alert that I’ve tweaked the M3 version of my landscape bracketing script. The latest version can be downloaded from here: https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849 (https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849)


If you are unfamiliar with the need for this script, then this may help: https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)


I needed to tweak things as the M3 has a major weakness, ie no custom timer, so no controlled CHDK bracketing in continuous mode.


My script allows you to focus bracket from the current position or, automatically, from the focus minimum, to a stated infinity, based on an infinity blur. The infinity blur is a fraction of the overlap blur you select.


At each focus station, including the no focus bracketing option, you can capture the following exposure brackets, all assuming your base exposure is an ETTR one: 1*2Ev or 1*3Ev or 1*4Ev or 2Ev+4Ev or 2Ev+4Ev+6Ev or an iso invariant capture at ISO1600.


You can bookend the full bracket sequence with a dark frame if you wish.


The script appears pretty robust, and, as I say, it was written for landscapers, ie not macro work ;-)


As usual I welcome and feedback and suggestions to make the script better.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 14 / July / 2020, 01:55:13
The latest version can be downloaded from here: https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849 (https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849)

If I’m following the link and ‘Download ZIP’, the ZIP includes gfbs2.lua and not M3 Brackets.lua.

So you didn't dare to extend the script for the M10?

Have you ever tried a1ex focus_stack.m which is running under the free Octave?
My impression was that it can keep up with helicon focus.

https://www.magiclantern.fm/forum/index.php?topic=24937.msg226183#msg226183 (https://www.magiclantern.fm/forum/index.php?topic=24937.msg226183#msg226183)
Download
http://files.apertus.org/align_image_stack/ (http://files.apertus.org/align_image_stack/)

My Version in MATLAB
https://www.magiclantern.fm/forum/index.php?topic=24937.msg226276#msg226276 (https://www.magiclantern.fm/forum/index.php?topic=24937.msg226276#msg226276)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / July / 2020, 02:55:13
@c_joerg

Quote
If I’m following the link and ‘Download ZIP’, the ZIP includes gfbs2.lua and not M3 Brackets.lua.

I don't know what is going on your end, I just followed the link and downloaded the zip and it is the M3 bracket script. Strange.

As I haven't (yet) got an M10, I haven't extended the script yet, ie can’t test  ;-)

I'll have a look at focus_stack.m: Does it handle handholding and frame to frame movement, ie landscape focus bracketing has large lens breathing movements?

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 14 / July / 2020, 04:21:05
I don't know what is going on your end, I just followed the link and downloaded the zip and it is the M3 bracket script. Strange.

Hmmm, really strange. I tried 3 times in the morning. Now it works….


I'll have a look at focus_stack.m: Does it handle handholding and frame to frame movement,
No.
There is a second script align_image_stack_finetune.m which has to run before.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / July / 2020, 04:40:35
@c_joerg

Code: [Select]
There is a second script align_image_stack_finetune.m which has to run before
My gut feeling that that align function is optimised for macro work and not landscape, ie handling the lens breathing issue. But that’s a guess.

I usually find if Helicon Focus can’t handle the focus breathing, believe it or not, Photoshop CC can.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / July / 2020, 11:20:38
Just to say I've added an auto exposure bracketing option, to the other ETTR based options on the M3 script.

The Auto option assumes your base exposure is made for the shadows. The exposure bracketing will increase, in 2Ev steps, until the top x% of the histogram has 'zero' content. You can choose x to be between 5 and 30%.

As usual the script can be downloaded from here: https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849 (https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849)

For non-macro use this script is 'all' you need on the M3 to do exposure and focus bracketing, individually or together.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 18 / July / 2020, 02:41:40
Have now tweaked the non-M3 script to also include the auto exposure bracketing feature.
Info on the script may be found here: https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2020, 08:27:03
Another minor, but useful, tweak to the non M3 version of the script, that provides an estimate of the number of focus brackets that will be taken.

The script will pause to show the number of brackets, thus allowing you to terminate the script, with a full shutter press, if the number is too high, or to run the script with a half shutter press.

A large number of brackets may occur if you are, say, using the Min2Inf option and/or you are using an overlap less than the CHDK CoC. That is the full focus range or your camera has a small minimum focus.


I’ve updated the info in the Scripts area, where the latest version may be accessed.


Have tested the script on my S95, G7X, G5X and G1X.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 21 / August / 2020, 10:33:36
I thought some may be interested in my latest post, where I carried out simple deep focus test on the G7X:

http://photography.grayheron.net/2020/08/deep-focus-test.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 18 / March / 2021, 11:29:58
Some may be interested in this post on the M3 version of my focus/exposure bracketing script:
https://photography.grayheron.net/2021/03/eos-m3-update.html (https://photography.grayheron.net/2021/03/eos-m3-update.html)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 19 / March / 2021, 03:48:59
Quote
The slight limitation with the M3 is that focus position feedback is to the nearest cm; but this is good enough for landscape focus bracketing, ie not macro bracketing.

Is this different on ML?
The feedback on EF lenses is the same or?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 19 / March / 2021, 04:11:24
Unless I’ve made a big mistake I believe peeking the focus distance upper returns the focus in cm on the M3 in CHDK.


On ML focus distance is reported in mm, eg on the M.


But, I truly don’t know what’s going on behind the scene.


I guess because I’m peeking at the Canon data feed in M3 CHDK, it’s in cm, whereas in ML, and other CHDK functions, it gets converted to mm before being returned, ie to be self consistent with other info.


In other words, cm is the best we can do? Whether reported at 1cm or 10mm ;-)



UPDATE just looked in the ML source code, looks like ML uses the Canon cm focus info as well, ie reports focus as Canonx10 in mm.
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 19 / March / 2021, 06:06:33
UPDATE just looked in the ML source code, looks like ML uses the Canon cm focus info as well, ie reports focus as Canonx10 in mm.
That would have been my expectations now...
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 19 / March / 2021, 06:42:22
In fact I should have known this  ;)


What I will do is bring my CHDK script into alignment, ie return from my peeking of focus function in mm.


BTW I personally only use the lower value, as this gives me a conservative DoF estimate, which is better for my contiguous focus bracketing needs, ie near to infinity.


For other uses I guess taking the geometric mean of the upper and lower, might be considered a ‘better’ estimate.  But this becomes problematic as you approach infinity, ie the upper value becomes huge relative to the lower.


I guess as long as you are less than, say, the hyperfocal, doing a geometric mean should be ok. But as I say, for focus bracketing insurance, using the lower value, with a sensible overlap blur criterion, is likely the safest bet. Especially as I ignore pupil mag, although this ‘offset’ tends to be a small amount.


Plus, I ‘only’ focus bracket with wide lenses  :)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 19 / March / 2021, 13:13:04
I thought some may be interested in this test of deep focus photography:

https://photography.grayheron.net/2021/03/helicon-focus-deep-focus-photography.html
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 20 / March / 2021, 02:51:19
Interesting article...

Quote
In this short post I will show how good Helicon Focus is at focus merging a deep stack of test images

What about focus breathing?
I thought you use Photoshop CC

I usually find if Helicon Focus can’t handle the focus breathing, believe it or not, Photoshop CC can.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 20 / March / 2021, 03:44:57
Yes, focus breathing will always be an issue, but my experience is HF seems to do a good job in handling it.


If one of the three methods in HF doesn’t work, I try one of the other two. If I’m still not happy, like you, I’ll go to PS, or try one of my other stacking pieces of software, eg Zerene. 


BTW just added an additional user feedback item, ie estimated number of brackets so the user can interrupt the script if they believe it is too high.


The M3 Brackets scripts is not the fastest script, but it does the job for me, ie ‘perfect’ deep focus stacks, plus exposure bracketing, on an M3, for scape photography, ie on a tripod and when we are also slowing down to enjoy the scenery ;-)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 21 / March / 2021, 13:03:47
I thought some may be interested in the latest feature I've added to my M3 Brackets script:
https://photography.grayheron.net/2021/03/sky-bracketing-in-deep-focus-photography.html (https://photography.grayheron.net/2021/03/sky-bracketing-in-deep-focus-photography.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 29 / March / 2021, 08:27:03
Another tweak to the M3 deep focus bracketing script and a demo of its abilities:

https://photography.grayheron.net/2021/03/more-on-canon-m3-focus-bracketing.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 03 / April / 2021, 12:05:39
Some may be interested in this post/video of the M3 Bracketing script in use:
https://photography.grayheron.net/2021/04/m3-brackets-release-2.html
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 05 / April / 2021, 13:14:32
Don't you have an EF-M 15-45?
I am amazed that it cannot be found in lens_info.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 05 / April / 2021, 13:48:57
15-45  :haha


I love wide angles and deep focus  :D



Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / April / 2021, 12:52:03
Latest bit of the M3 Brackets story: using pupil magnification as a focus bracketing overlap control:
https://photography.grayheron.net/2021/04/m3-brackets-pupil-magnification-update.html (https://photography.grayheron.net/2021/04/m3-brackets-pupil-magnification-update.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / April / 2021, 04:39:32
Learn from my 'mistakes'  :haha

https://photography.grayheron.net/2021/04/m3-brackets-tweaked-to-address-chdk.html (https://photography.grayheron.net/2021/04/m3-brackets-tweaked-to-address-chdk.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 01:47:32
A change to the UI.


IMHO, if you have an M3 and love scape captures, M3 Bracketing works really well.


https://photography.grayheron.net/2021/04/m3-brackets-change-to-ui.html (https://photography.grayheron.net/2021/04/m3-brackets-change-to-ui.html)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 06:37:23
The rate of change in your scripts is pretty high. I am probably lagging behind a lot  :)

What is the workflow like when combining focus bracket and exposure bracket? First calculate HDR and then stacking?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 06:45:15
Yes, I'm afraid that's how I work, ie get an idea, test/publish it, get another idea, test publish it............ ;)

Remember I wrote the M3 Bracketing script for leisurely deep focus 'scape' photography. When I'm in no hurry.

The script is not fast, but that's why I developed the idea of sky exposure bracketing, ie only carry out exposure brackets at infinity. I think this works pretty good.

BTW, I'm just tweaking the code again, to giv you two options for the DoF feedback, ie near-DoF / far-DoF vs near-DoF / Infinity-blur.

I personally always use the second approach in my workflow, ie focus for the foreground and set a blur for the background.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 07:10:40
I love wide angles and deep focus  :D
That's why the EF-M18-55mm and EF-M55-200mm are now also available in lens_info ;)
I love my EF-M 15-45. It's a good compromise.

I find the lens_info() function very confusing. There the same code is simply copied several times. Fmax could also be generated from the lens_name. Is MFD only required for the maximum wide angle and not for the other focal lengths?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 07:17:28
I could be bothered to tidy things up in lens info, after all you only need enter your data once.


In the Magic Lantern DOFIS script, I explicitly register MFD, magnification and pupil mag at the two extremes of a zoom, and do a linear interpolation for in between focal lengths.


In M3 Brackets I assume the same MFD at the two extremes and adopt a thin lens model to estimate the mag at other focal lengths. Pupil mag is handled as a user menu item.


I may revisit the M3 approach, but to be fair, it’s most probably not worth it when doing non-macro stuff.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 08:22:17
@c_joerg

Because it's a lazy Sunday  :)

https://gist.github.com/pigeonhill/cdf25239bae6a4343e6431fb4c10c849

Have added in an option to display DoFs as near/far or near/blur.

Plus tidied up the lens_info() function  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 09:37:52
Plus tidied up the lens_info() function  ;)
8)

So for the "EF-M15-45mm f/3.5-5.6 IS STM"

Fmax = 45000
MFD = 250
and Mmax?
Mmax = 250 ?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 09:41:52
Looks like it’s 250mm, so try that.


Once it’s up and running, see what the script reports as minimum.


If it’s not 250, then change MFD to what’s reported.


Max mag is 0.25 I think, ie at 45mm.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 10:04:12
Yes 250 for max mag, ie max mag x1000
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 10:05:01
I add

Code: [Select]
    elseif lens_name() == "EF-M15-45mm f/3.5-6.3 IS STM" then
        Fmax = 45000 -- Longest focal length (mm) * 1000
        Mmax = 250 -- Max magnification * 1000
        MFD = 250 -- Minimum Focus Distance in mm
        t = hiatus() -- distance between front and rear principals in mm
        return true

It looks like it works...

"Get lens name? = Yes" is only for printing correct lens name?

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 10:37:38
Yes, that’s all it does, so you switch it off as soon as you know your lens name for registering.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 10:39:06
Just looked at your log and see an error in the last image. I’ll check the code.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 10:47:21
@c_joerg

Fixed: silly error on my part.

Plus added your lens into the pre registered set ;-)

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 11:02:41
@c_joerg

There is no need for that. I habe  enabled notification of new replies for this topic...

Fixed: silly error on my part.

But only prints or?


Plus added your lens into the pre registered set ;-)

Thanks  :)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 11:30:32
Could you try the latest version.

I've also fixed the LCD vs EVF  :)

Cheers

Garry


Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 11 / April / 2021, 13:08:37
At the bottom, where the line with Set / Reset is, I only see a gray bar with EVF.
Everything is OK with LCD.

I'm on the road for a few days now and will probably not be able to answer for the time being ...
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 13:15:18
Yes I know about that 'feature'  :D

The problem is you can't switch off the console.

If you try and resize it, the screen flashes.

I need to think a bit  ;)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / April / 2021, 13:40:05
Quote
At the bottom, where the line with Set / Reset is, I only see a gray bar with EVF.

I've introduced a palliative 'fix' for now.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / April / 2021, 10:02:24
I believe the latest version of M3 Bracketing is now available and, I hope, pretty stable  ;)

https://photography.grayheron.net/2021/04/m3-bracketing-update.html (https://photography.grayheron.net/2021/04/m3-bracketing-update.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / April / 2021, 04:42:26
@c_joerg

I think M3 Bracketing is now as stable as I can get it, see my latest post at: https://photography.grayheron.net/2021/04/m3-bracketing-fighting-canon-ui.html (https://photography.grayheron.net/2021/04/m3-bracketing-fighting-canon-ui.html)

I'll carry on looking at code refinements, and update the script as needed, but, for me and my objectives, ie deep focus photography, M3 Bracketing is working well.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 14 / April / 2021, 11:57:00
For those lucky enough to own an M3 running CHDK, you should be pleased with the latest version of my M3 Bracketing script, that now supports manual focus bracketing from near to far or far to near, as well as auto focus bracketing from near to infinity:

https://photography.grayheron.net/2021/04/m3-bracketing-now-with-manual-focus.html (https://photography.grayheron.net/2021/04/m3-bracketing-now-with-manual-focus.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 18 / April / 2021, 04:12:26
I’ve now added an augmented info field to the traffic light mode, that shows the overlap blur as you refocus; thus helping you nail your perfect deep focus manual bracketed images on the Canon M3.

https://photography.grayheron.net/2021/04/m3-bracketing-overlap-blur-augmented.html (https://photography.grayheron.net/2021/04/m3-bracketing-overlap-blur-augmented.html)

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 19 / April / 2021, 12:29:36
Hopefully to complete the story of deep focus, high dynamic range photography, I’ve just posted the following on my blog:

https://photography.grayheron.net/2021/04/post-processing-for-deep-focus-high.html (https://photography.grayheron.net/2021/04/post-processing-for-deep-focus-high.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 26 / April / 2021, 10:33:05
Just to say that I've added HAMSTTR Ev feedback to M3 Bracketing:

https://photography.grayheron.net/2021/04/m3-bracketing-now-supports-hamsttr.html (https://photography.grayheron.net/2021/04/m3-bracketing-now-supports-hamsttr.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 28 / April / 2021, 16:37:23
Thanks to @philmoz I'm pleased to release a version of my M3 Bracketing script that runs in a floating point version of Lua.

The script only runs on an M3 with the fmath library and tests for this.

You can download the fmath CHDK build (M3 120f) from: https://chdk.setepontos.com/index.php?action=dlattach;topic=14305.0;attach=17061 (https://chdk.setepontos.com/index.php?action=dlattach;topic=14305.0;attach=17061)

The script may be downloaded from https://gist.github.com/pigeonhill/e40b415b8f751e8369c0edc9d09003c6 (https://gist.github.com/pigeonhill/e40b415b8f751e8369c0edc9d09003c6)

Once again, many thanks to Phil for his efforts.

Cheers

Garry

PS Script update on 29/4/2021 to correct a minor error
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 29 / April / 2021, 04:54:36
I thought some may be interested in my latest post:

https://photography.grayheron.net/2021/04/technology-technology-impressive-results.html (https://photography.grayheron.net/2021/04/technology-technology-impressive-results.html)

Once again: thanks @philmoz
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 11 / May / 2021, 05:16:20
I thought some may be interested in my latest M3 Bracketing script developments:

https://photography.grayheron.net/2021/05/wind-bracketing-for-landscape.html (https://photography.grayheron.net/2021/05/wind-bracketing-for-landscape.html)

UPDATE: a test image:

https://photography.grayheron.net/2021/05/test-of-wind-bracketing.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 17 / May / 2021, 10:24:01
The latest on my M3 Bracketing script:

https://photography.grayheron.net/2021/05/m3-bracketing-beta-of-next-release.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / June / 2021, 09:34:55
Just updated the CHDK Scripts link:

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

Plus made this post:

https://photography.grayheron.net/2021/06/new-lightroom-updates-and-new-focus.html (https://photography.grayheron.net/2021/06/new-lightroom-updates-and-new-focus.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 12 / June / 2021, 02:34:36
Just a quick post to say I've added a few 'error' checks to make the non-M3 version of the code more 'robust'. I've tested it on the S95, G7X, G5X and G1X.

For example, the script will terminate with a message if:
* Camera not in M mode
* Camera not in MF mode (use the C mode if you have one to lock in the right modes for the script)
* Aperture changed after script has started
* Focal length changed after script has started

You can always get the latest version of the script from:

https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets (https://chdk.fandom.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets)
 
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 16 / June / 2021, 05:56:52
Just updated the CHDK scripts page related to my Landscape Bracketing Script, as I've added a new feature to the no-M3 version.

Instead of only allowing you to take an ETTR sky bracket at infinity, the script now allows you to also carry out a simulated ND capture at infinity.

The use case being, say, wishing to have blurred flowing water.

The script allows you to simulate either a 2, 3, 4 or 5 ND filter, ie with 2, 4, 8, 16 or 32 images.
You can read more here: https://photography.grayheron.net/2021/06/chdk-landscape-bracking-script-latest.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 01 / July / 2021, 16:57:03
Just an update, with a test image, to reflect the latest histogram 'fixes' by @reyalp.

But note check to see you have the correct build  ;)

https://photography.grayheron.net/2021/07/auto-ettr-on-m3.html
Title: Re: Landscape Focus Bracketing Script
Post by: SX720 on 04 / July / 2021, 20:31:55
I just tried the script and it seems to work well on my SX230 HS. The only thing is when zoomed out and close to infinity you don't get a lot of granularity in the focus point so the script reports different distances but they end up at what I think is the same focus. I don't think this is the fault of the script but rather something maybe with the camera.

When zoomed in more and looking at closer objects it works well.

I'm not sure if there is any way to make finder focus adjustments for the SX230 HS, it might be just the way the camera is. With that said it would be cool if possible. Sometimes I think the images from the camera can be a little soft and I'd assume if it were possible to make slight focus adjustments I could end up with a merged sharper picture.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 05 / July / 2021, 02:11:30
@SX720

Thanks for the feedback on the script.

I'm afraid you are experiencing the limitations that exist on the Canon side.

Canon's reporting of distance varies through the focus range, with the greatest granularity at the macro end.

This becomes more apparent in the far field at longer focal lengths.

This is why I recommend the script is best suited as a script for wide angle lenses and for focus control/reporting up to the hyperfocal.

Focusing beyond the hyperfocal is really all about setting the infinity blur. For example, focus at 2*H and the infinity blur is half the CoC etc.

BTW you may wish to play around with my focus simulators on my blog at photography.grayheron.net. These are designed to help you visualize focusing and focus bracketing.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / July / 2021, 08:01:08
I thought some may be interested in my latest M3 post, that shows the 'exposure survey' mode:

https://photography.grayheron.net/2021/07/m3-bracketing-exposure-survey-mode.html (https://photography.grayheron.net/2021/07/m3-bracketing-exposure-survey-mode.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 31 / July / 2021, 09:05:10
I thought some may be interested in my latest M3 Landscape Bracketing Script tweaks:

https://photography.grayheron.net/2021/07/m3-landscape-bracketing-script-latest.html (https://photography.grayheron.net/2021/07/m3-landscape-bracketing-script-latest.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 01 / August / 2021, 09:47:11
Another UI tweak  :)

https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-even.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 06 / August / 2021, 06:12:07
As I've just got a manual fisheye for my M3, I've tweaked my Landscape Bracketing Script to allow the fisheye to access exposure survey, auto-ETTR and all exposure bracketing modes.

You can read about the lens here: https://photography.grayheron.net/2021/08/new-lens-ttartisan-75mm-f2.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 07 / August / 2021, 11:39:36
Another test with the 7.5mm fisheye on the M3. This one a focus stack example:

https://photography.grayheron.net/2021/08/defishing-for-visual-impact.html (https://photography.grayheron.net/2021/08/defishing-for-visual-impact.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / August / 2021, 03:33:13
A final test with my new 7.5mm fisheye lens:

https://photography.grayheron.net/2021/08/defishing-for-visual-impact-take-2.html (https://photography.grayheron.net/2021/08/defishing-for-visual-impact-take-2.html)
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 08 / August / 2021, 05:26:15
Another UI tweak  :)

https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-even.html

I’m using now M3 with 121a. Maybe you could update your script to 121a. Address can be found here:
https://chdk.setepontos.com/index.php?topic=13756.0

Not sure about get_lens_name.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / August / 2021, 05:55:05
@c_joerg

Quote
Maybe you could update your script to 121a.

The script is already 121a ready, so the latest version should run ok.

The only a vs f issue is lens focus.

Obviously, let me know if it doesn’t work and I’ll fix it.

Also, let me know if you don’t get the script ;-), as I wrote it for my use.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / August / 2021, 06:01:57
@c_joerg

Forgot to say, you need to load the philmoz XIMR version from https://drive.google.com/drive/folders/1drk1xi6kMMIeF5xSqXgnpjGCffF8CVkd
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 08 / August / 2021, 07:05:45
The script is already 121a ready, so the latest version should run ok.

Version from 07.08.21 did not include 121a

example:

Code: [Select]
function get_focus_distance_lower() -- returns lower focus distance in mm, but note 'accuracy' is 1cm from Canon
    local x = -1
    if (bi.platsub == "101a") then
        x = peek(0x00244918, 2)
    elseif (bi.platsub == "120f") then
        x = peek(0x0024495C, 2)
    else
        error('Not 101a or 120f')
    end
    if x == -1 then return -1 else return x*10 end
end
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / August / 2021, 07:16:12
@c_joerg

Sorry, didn’t spot that.

Do you know the peek values?

If you do, I’ll update the script.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 08 / August / 2021, 07:21:13
Do you know the peek values?

For focus you found values in my script
https://chdk.setepontos.com/index.php?topic=13756.0

for get_lens_name_fn I don't know...
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 08 / August / 2021, 07:38:26
@c_joerg

Quote
for get_lens_name_fn I don't know...

I guess we need to wait until someone can get me the peek code for the 121a to put here:

Quote
local get_lens_name_fn = 0xfc2f3fd5
 if (bi.platsub == "101a") then get_lens_name_fn = 0xfc2f3fc3 end

@reyalp  or @philmoz can you help?
Title: Re: Landscape Focus Bracketing Script
Post by: philmoz on 08 / August / 2021, 18:08:43
I guess we need to wait until someone can get me the peek code for the 121a to put here:


For 1.21a the address would be 0xfc2f4005


However you could simplify your lens_name function by accessing the values directly in memory.
Code: [Select]

function lens_name()
    local pname = 0x002449ad
    if (bi.platsub == "101a") then pname = 0x00244969 end
    local len = peek(pname-1,1)
    local i = 0
...


If you decide to stay with the function call and local memory alloc in lens_name then you should probably fix the tests after the call to FreeMemory. After calling FreeMemory on ppname value you then test the ppname value (which had already been done earlier) - this test should probably be on the pname variable instead.


Phil.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 00:48:57
@philmoz

Many thanks for the 1.21a address.

Quote
However you could simplify your lens_name function by accessing the values directly in memory.


I’m afraid I won’t know how to do this.
Title: Re: Landscape Focus Bracketing Script
Post by: philmoz on 09 / August / 2021, 00:59:46
I’m afraid I don’t have the knowledge or wherewithal to take this approach, so, for now, I’ll just add the address to the function that is already there. I’m also not clear what you were suggesting regarding FreeMemory.


The code I included replaces lines 187 - 205 in your script.


In your script line 204 is a duplicate of line 195 and IMO should be testing the value of pname not ppname.

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 01:25:57
Quote
In your script line 204 is a duplicate of line 195 and IMO should be testing the value of pname not ppname.

Yes, I spotted that just after posting, but we crossed in our postings, ie I withdrew my commit and you commented on it ;-)

I'll rework my script now.

Many thanks.

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 01:38:28
@philmoz

Assuming I've understood you, could you look at the following and confirm all is OK and fill in the ??? ?? address for 121a

Code: [Select]
function lens_name()
    local pname = 0
    if (bi.platsub == "120f") then
        pname = 0x002449ad
    elseif (bi.platsub == "101a") then
        pname = 0x00244969
    elseif (bi.platsub == "121a") then
        --pname =?
    end
    local len = peek(pname-1,1)
    local i = 0
    local t = {}
    while i < len do
        local c = peek(pname + i, 1)
        if c == 0 then break end
        table.insert(t, string.char(c))
        i = i + 1
    end
    local name = table.concat(t)
    return name
end

Once again, thanks for all your support.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: philmoz on 09 / August / 2021, 02:13:34
Assuming I've understood you, could you look at the following and confirm all is OK and fill in the ??? ?? address for 121a



121a is the same as 120f which is why I wrote the code the way I did - 101a is the odd one out.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 02:16:17
Quote
121a is the same as 120f which is why I wrote the code the way I did - 101a is the odd one out.

I was always taught to never trust Microsoft  :), it now looks like I need to also say, never trust Canon ::)

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 02:23:56
@c_joerg

Thanks to @philmoz I've updated the script and hopefully it should run on all M3 CHDK versions.

As mentioned in the post on my blog, I've also changed the code to be accessed by non-EFM lenses, albeit only in exposure bracketing or survey modes. You can also auto ETTR a non-EFM lens.

I would welcome you confirming the script runs OK.

Download the latest script version from my blog link.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 09 / August / 2021, 02:54:20
Forgot to say, you need to load the philmoz XIMR version

At the moment I would not like to change the CHDK Version of my M3.
What happens if you don't use the philmoz version?
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / August / 2021, 02:58:07
Quote

What happens if you don't use the philmoz version?


The script wouldn’t work and/or crash.

Use a separate card ;)

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: c_joerg on 09 / August / 2021, 05:26:58
Use a separate card ;)
I already have so many SD cards with different versions ;)
Give me time...

Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / August / 2021, 10:30:56
Some may be interested in the latest tweak to the M3 LBS.

You can now select to use the lower, upper or harmonic mean of the focus distance, and register non-EF-M lenses.

https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-where.html (https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-where.html)
Title: Re: Landscape Focus Bracketing Script
Post by: Caefix on 16 / August / 2021, 13:55:30
...register non-EF-M lenses.
Need or how to include cropfactor?  ???
Code: [Select]
    elseif lens_name() == "EF-M22mm f/2.0 MACRO STM" then
        Fmax = 22000 -- Longest focal length (mm) * 1000
        Mmax = 217 -- Max magnification * 100
        MFD = 150 -- Minimum Focus Distance in mm
        t = hiatus() -- distance between front and rear principals
        return true
    elseif lens_name() == "EF-M18-150mm f/3.5-6.3 IS STM" then
        Fmax = 150000 -- Longest focal length (mm) * 1000
        Mmax = 259 -- Max magnification * 100
        MFD = 450 -- Minimum Focus Distance in mm
        t = hiatus() -- distance between front and rear principals
        return true
    elseif lens_name() == "EF-S18-200mm f/3.5-5.6 IS" then
        Fmax = 320000 -- Longest focal length (mm) * 1000
        Mmax = 592 -- Max magnification * 100
        MFD = 450 -- Minimum Focus Distance in mm
        t = hiatus() -- distance between front and rear principals
        return true
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 16 / August / 2021, 15:30:33
Quote
Need or how to include cropfactor?

No you don’t  :)

The script is controlled by specifying the overlap blur in microns.
Title: Re: Landscape Focus Bracketing Script
Post by: Caefix on 16 / August / 2021, 15:42:22
Quote
... blur in microns.
Whenever I read this, I "see" a bug running up the tripod at long exposure...  :haha
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 16 / August / 2021, 16:34:02
Quote
Whenever I read this, I "see" a bug running up the tripod at long exposure...

As usual I have no idea what you are saying...sorry.
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 30 / August / 2021, 12:27:14
I thought some may be interested in my latest M3 Landscape Bracketing Script feature: auto focus bracketing from the minimum focus distance to a set focus position.

Also, there are a few posts on my blog related to macro photography that some may wish to read.

https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-minimum.html (https://photography.grayheron.net/2021/08/m3-landscape-bracketing-script-minimum.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 20 / September / 2021, 11:38:44
Just a quick post to say I’ve brought the M3 version of my Landscape Bracketing Script into alignment with the non M3 version, in that the M3 script now includes simulated ND bracketing.

You can read about the latest version here:

https://photography.grayheron.net/2021/09/landscape-bracketing-script-m3-now-with.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 15 / October / 2021, 11:34:05
I thought some, ie those lucky enough to have an M3 ;-), would be interested in the latest version of my M3 Landscape Bracketing Script.
The latest version now allows LE simulation, via ND number or time, and Super-Resolution simulated pixel shifting.
https://photography.grayheron.net/2021/10/m3-landscape-bracketing-script-now-with.html (https://photography.grayheron.net/2021/10/m3-landscape-bracketing-script-now-with.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 19 / October / 2021, 10:11:50
A minor tweak to the UI and functionality that some may be interested in:

https://photography.grayheron.net/2021/10/m3-lbs-minor-update.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 18 / April / 2022, 11:26:46
I thought some may be interested in the latest addition to my M3 Landscape Bracketing Script. which now includes 'optimised' handheld bracketing.
https://photography.grayheron.net/2022/04/an-over-due-update.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 25 / April / 2022, 01:11:07
Another example of what you can achieve handholding the M3 in a high DR environment.


https://photography.grayheron.net/2022/04/i-still-believe-canon-m3-with-chdk-is.html (https://photography.grayheron.net/2022/04/i-still-believe-canon-m3-with-chdk-is.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 09 / May / 2022, 10:36:54
I thought some may be interested in my attempt at introducing an ETTR Meter on the M3.

https://photography.grayheron.net/2022/05/canon-m3-ettr-meter.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / May / 2022, 02:49:53
@reyalp

As you may have spotted in the post above, I’ve made a first attempt at an ‘ETTR Meter’.

In attempting to understand the CHDK histogram, but not being a c programmer, I believe we might wish to tweak some of the CHDK manual…but I could be wrong ;-)

My understanding is that the CHDK histogram, eg see https://photopxl.com/a-better-histogram/ (https://photopxl.com/a-better-histogram/), does not show a stops based view, but a linear view, as shown  in figure 4 in the link. Or does it show a gamma view?

If I look at the drawing code in the histogram.c, I come across this:

Code: [Select]
if (conf.histo_show_ev_grid) for (i=1;i<=4;i++) draw_line(x+(1+w)*i/5, y, x+(1+w)*i/5, y+h, FG_COLOR(conf.histo_color2));

That is, as I’ve speculated in my blog post, CHDK, like the Canon Histo, doesn’t divide the Histo into stops, but simply linearly across the Histo range, ie 0-255. Thus the right most divider line, is at 1/5 of the Histo range, which is at about 1/3 Ev down from highlight saturation.

If I’m right we may wish to make this clearer to the user, that the vertical grid lines are not stops.

But, as I say, I may be totally wrong ;-)

As usual I welcome your insight.

Cheers

Garry
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / May / 2022, 03:48:10
@reyalp

After pushing out the last post, I've tried to educate myself on gamma vs linear, eg https://www.imatest.com/2021/07/tonal-response-gamma/ (https://www.imatest.com/2021/07/tonal-response-gamma/)

I've convinced myself than the viewport based CHDK (and Canon?) histogram are gamma encoded at 2.2.

Thus the top 1/3 stops look like this: 255-229, 228-206, 205-185.

This follows from: 256*2^(-(n-1)*(1/2.2))
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 10 / May / 2022, 06:16:49
The final 'corrected' post on the M3 ETTR Meter.

https://photography.grayheron.net/2022/05/canon-m3-ettr-meter.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 01 / June / 2022, 10:57:24
I thought some may be interested in the latest version of the Landscape Bracketing Script for non-M3 CHDK cameras:
https://photography.grayheron.net/2022/06/landscape-bracketing-script-update.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 13 / June / 2022, 04:18:28
Anyone running LBS on the CHDK M series cameras may be interested in this quick read:

https://photography.grayheron.net/2022/06/using-landscape-bracketing-script-on-m.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 17 / June / 2022, 10:45:00
Some, especially M3 and M10 owners, may be interested on my latest post on deep focus bracketing:

https://photography.grayheron.net/2022/06/low-level-auto-deep-focus-bracketing.html
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 24 / June / 2022, 02:45:29
Another test I thought some may be interested in, especially if you wish to do some close up photography.
https://photography.grayheron.net/2022/06/close-up-photography-with-landscape.html
Title: Landscape Focus Bracketing Script M3 / M10
Post by: pigeonhill on 02 / April / 2023, 08:38:10
Some may be interested in the latest version of my Landscape Bracketing Script for the M3 and M10:


https://photography.grayheron.net/2023/04/latest-tweaks-to-m3m10-landscape.html (https://photography.grayheron.net/2023/04/latest-tweaks-to-m3m10-landscape.html)
Title: Re: Landscape Focus Bracketing Script
Post by: pigeonhill on 07 / April / 2023, 14:22:26
Another update, this one to the ETTR meter.

https://photography.grayheron.net/2023/04/ettr-exposure-meter-update.html