MF-DOF: Manual Focus DOF bracketing/stacking script - Completed and Working Scripts - CHDK Forum  

MF-DOF: Manual Focus DOF bracketing/stacking script

  • 10 Replies
  • 12932 Views
*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
MF-DOF: Manual Focus DOF bracketing/stacking script
« on: 26 / January / 2011, 13:00:09 »
Advertisements
« Last Edit: 19 / April / 2011, 17:53:10 by SkyWalker9 »

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #1 on: 28 / January / 2011, 12:34:56 »
Update: I forgot to include a check for the Image Stabilization (IS) status. When I write scripts that are usually used with tripods, I normally incorporate an IS check. Here is an updated script that includes the check:

Code: [Select]
rem Author SkyWalker9
@title MFDOF
@param b Step size [x5]
@default b 8
@param c #Photos
@default c 10
@param h Save log (0=No)
@default h 0

if c<1 then c=1
if b<1 then b=1
b=b*5
d=b/2
sleep 500
get_focus f
e=f

x=get_IS_mode
  select x
    case 0; print "Caution: IS enabled"
    case 1; print "Caution: IS enabled"
    case 2; print "Caution: IS enabled"
  end_select
  
press "shoot_half"
sleep 1000

x=get_near_limit
y=get_far_limit

print "Adjust Near Pt"
print "Focus Limits: "x"-"y
print "focus:"f
gosub "tweak_loop"
a=f
cls

f=e
set_focus f

print "Adjust Far Pt"
print "Focus Limits: "x"-"y
print "focus:"f
gosub "tweak_loop"
z=f
cls

if z>a then goto "Bracket_DOF"
  d=a
  a=z
  z=d

goto "Bracket_DOF"

:tweak_loop
     wait_click 10000
     is_key k "zoom_out"
     if k=1 then f=f-b
     is_key k "zoom_in"
     if k=1 then f=f+b
     is_key k "left"
     if k=1 then f=f-d
     is_key k "right"
     if k=1 then f=f+d
     is_key k "set"
     if k=1 then goto "exit_loop"
     set_focus f
     print "focus:"f
  goto "tweak_loop"
:exit_loop
return

:Bracket_DOF
  if h=0 then goto "Continue"

  y=get_time 0
  x=get_time 1
  w=get_time 2
  m=get_time 3
  n=get_time 4
  p=get_time 5
  g=w*100+x
  if g<1 then g=1
  if g>9999 then g=9999

  print_screen g

  print "Date: "m"/"n"/"p
  print "Time: "w":"x":"y

  print " "

  x=get_hyp_dist
  print "Hyperfocal_dist: "x

  x=get_dof
  print "DOF Sharpness: "x

  x=get_near_limit
  y=get_far_limit
  print "Focus Limits: "x"-"y

  print "Start focus: ", e
  print " "

  print "Selected:", a"-"z

  v=((z-a)/2)+a
  w=(((z-a)/2)+a)*3937/100000
  n=(((z-a)/2)+a)*3937/1000
  m=n/10
  n=n-(m*10)
  m=m-(w*10)
  if n>5 then let m=m+1
  print "Est Subj Dist: "v" mm ("w"."m" inches)"
  print " "

:Continue
    release "shoot_half"
    sleep 1000
    g=a
    if c>1 then d=(z-a)/(c-1)
    for s=1 to c
      print "Photo "s":", g
      set_focus g
      sleep 500
      shoot
      g=g+d
    next s

    if h=0 then print_screen 0

    set_focus e
end

Update 4-19-11: When using the wait_click statements, some cameras require the timeout be specified; recommend starting with "wait_click 10000" (10secs). The script has been updated to reflect the change.
« Last Edit: 19 / April / 2011, 17:53:53 by SkyWalker9 »

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #2 on: 30 / May / 2011, 22:57:00 »
« Last Edit: 31 / May / 2011, 09:14:32 by SkyWalker9 »

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #3 on: 30 / May / 2011, 22:57:50 »
Code: [Select]
rem Author SkyWalker9
@title MFDOF
@param b Tweak step size [x5]
@default b 8
@param t #Photos (1=max)
@default t 1
@param r Max #Photos
@default r 50
@param h Save log (0=No)
@default h 1

x=get_IS_mode
if x<3 then print "IS not disabled"

rem ------- camera specific section / omit if you are not using SX20 -------
y=0
get_prop 50 x
if x=-32767 or x=-32766 then y=y+1 else print "Camera mode not Av or M"
get_prop 133 x
if x=1 then y=y+1 else print "Not in MF mode"
get_prop 281 x
if x=0 then y=y+1 else print "Safety MF not disabled"
if y=3 then goto "okay"
 end
rem ------- camera specific section / omit if you are not using SX20 -------

:okay
cls
T=0
rem Displays the disk space/free disk space in MB & percent
x=get_disk_size
x=x/1000
y=get_free_disk_space
y=y/1000
z=(y*100)/x
print "Free Space "y"MB ("z"%)"
if t=1 then print "Shots in series "r else print "Shots in series "t
x=get_jpg_count
y=get_raw_count
print "Space: "x" JPGs/"y" DNGs"
print "press Set to proceed"
print "press Shutter to exit"
wait_click
cls
c=t
if c<1 then c=1
if b<1 then b=1
b=b*5
d=b/2
print "waiting for camera"
print "vibrations to stop"
print " "
print " "
sleep 2500
get_focus f
e=f
 
press "shoot_half"
sleep 1000

x=get_near_limit
y=get_far_limit
cls

if c>1 then goto "manually_tweak"
a=x
z=y
c=r
goto "Bracket_DOF"

:manually_tweak
print "Adjust Near Pt"
print "Near/Far Limits: "x"-"y
print "focus:"f
print "Left/Right to change"
print "press Set when done"
gosub "tweak_loop"
a=f
cls

f=e
set_focus f

print "Adjust Far Pt"
print "Near/Far Limits: "x"-"y
print "focus:"f
print "Left/Right to change"
print "press Set when done"
gosub "tweak_loop"
cls
z=f
print "waiting for camera"
print "vibrations to stop"
print " "
print " "
rem allow time for camera movement/vibrations to stop
sleep 2500
cls

if z>a then goto "Bracket_DOF"
  d=a
  a=z
  z=d
goto "Bracket_DOF"

:tweak_loop
     wait_click
     is_key k "zoom_out"
     if k=1 then f=f-b
     is_key k "zoom_in"
     if k=1 then f=f+b
     is_key k "left"
     if k=1 then f=f-d
     is_key k "right"
     if k=1 then f=f+d
     is_key k "set"
     if k=1 then goto "exit_loop"
     set_focus f
     gosub "prnt_focus_value"     
  goto "tweak_loop"
:exit_loop
return

:prnt_focus_value
  if T=0 then print "Focus Limits: "x"-"y
  if f=e then goto "same"
  if f<e then goto "minus"
   W=((f-e)*10000)/e
   M=W%100
   W=W/100
   print "Focus: "f" (+"W"."M"%)"
   goto "tweaking_check"
:minus
   W=((e-f)*10000)/e
   M=W%100
   W=W/100
   print "Focus: "f" (-"W"."M"%)"
   goto "tweaking_check"
:same
   F=100
   print "Focus: "f" (same)"
:tweaking_check
   if T=1 then goto "done"
   print " "
   print "Left/Right to change"
   print "press Set when done"
:done
return

:Bracket_DOF
  if h=0 then goto "Continue"
  y=get_time 0
  x=get_time 1
  w=get_time 2
  m=get_time 3
  n=get_time 4
  p=get_time 5
  g=w*100+x
  if g<1 then g=1
  if g>9999 then g=9999
  print_screen g
  print "Date: "n"/"m"/"p
  print "Time: "w":"x":"y
  print " "
  x=get_hyp_dist
  print "Hyperfocal_dist: "x
  x=get_dof
  print "DOF Sharpness: "x
  print "Start focus: ", e
  x=get_near_limit
  y=get_far_limit
  print "Near/Far Limits: "x"-"y
  print " "
  v=((z-a)/2)+a
  w=(((z-a)/2)+a)*3937/100000
  n=(((z-a)/2)+a)*3937/1000
  m=n/10
  n=n-(m*10)
  m=m-(w*10)
  if n>5 then let m=m+1
  print "Est Subj Dist: "v" mm ("w"."m" in)"
  print " "

:Continue
    cls
    T=1
    release "shoot_half"
    sleep 1000
    set_focus a
    sleep 500
    g=a
    x=z-a+1
    if c>1 then d=x/(c-1)
    if c>x then c=x
    print "Tweaked Range:", a"-"z
    print "Max #shots possible: "x
    print "Taking "c" photos"
    print " "
    for s=1 to c
      f=g
      cls
      print "Photo: "s" of "c
      gosub "prnt_focus_value"
      print " "
      set_focus g
      sleep 500
      shoot
      sleep 1000
      g=g+d
    next s

    if h=0 then print_screen 0

    set_focus e
end

<part 2 of 2>


Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #4 on: 22 / August / 2011, 06:25:27 »
Thank you Skywalker9 for the MF-DOF script AND the very clear explanation on how to use it. much appreciated. I am using SX10IS.

Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #5 on: 06 / November / 2011, 07:40:38 »
Here is my attempt to making the DOF a bit more flexible as you control the amounts of focus back and forth and set the range in cm and the script calculates all the needed focus settings. Also includes a possible infinity shot to catch the background.

Code: [Select]
rem arne182
rem G12 specific code
@title FocusRange
@param a Number of +steps
@default a 3
@param b Number of -steps
@default b 3
@param c Focus range in cm
@default c 10
@param d Infinity included, yes = 1
@default d 0

if a<0 then let a=0
if b<0 then let b=0
if c<1 then let c=1
if c>50 then let c=1

rem ------- camera specific section / omit if you are not using G12 -------
y=0
get_prop 133 x
if x=1 then y=y+1 else print "Not in MF mode"
get_prop 12 x
if x=0 then y=y+1 else print "Continuous AF is on!"
if y=2 then goto "continue"
set_focus f
 end
rem ------- camera specific section / omit if you are not using G12 -------

:continue
sleep 500
cls
get_focus f
if f<0 then let f=65530
if f<69 then let b=0
if f>17590 then let a=0
p=b
if f-b*c*10/(a+b)<68 then let b=(f-68)*(a+p)/(10*c) else goto "shoot"
if b<0 then let b=0
if p=b then print "" else let a= a+p-b
print "b adjusted to ", b
print "press Set to proceed"
print "press Shutter to exit"
wait_click

:shoot
x=get_near_limit
y=get_far_limit

g=f-b*c*10/(a+b)
set_focus g
sleep 100
print "Near focus check"
print "press Set to proceed"
print "press Shutter to exit"
wait_click

g=f+a*c*10/(a+b)
set_focus g
sleep 100
print "Far focus check"
print "press Set to proceed"
print "press Shutter to exit"
wait_click

print "waiting for camera"
print "vibrations to stop"
sleep 2000

for s=-b to a
  g=f+s*c*10/(a+b)
  set_focus g
  sleep 100
  get_focus g
  print "Shoot", s, "(", g, ")"
  shoot
next s
  if d=1 then gosub "infinity"

set_focus f

end

:infinity
  g = 65530
  print "Shoot infinity", "(", g, ")"
  set_focus g
  sleep 100
  shoot
return
« Last Edit: 06 / November / 2011, 09:33:35 by arne182 »
G12 1.00g

Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #6 on: 30 / January / 2012, 05:01:39 »
May i ask what's this for?. To get everything in the shot focuseD/?

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #7 on: 31 / January / 2012, 16:15:18 »
May i ask what's this for?. To get everything in the shot focuseD/?
The initial script info seems to have been deleted, possibly during one of the server updates. Here is the original info:

MF-DOF: Manual Focus DOF bracketing/stacking script
(Originally designed and tested on SX20 - script has 'rem' statements indicating SX20 specific statements)

During macro photography it is common to come across objects/subjects that require DOF bracketing/stacking to capture the detail of the object. I have used several DOF scripts but it was sometimes "challenging" to set the parameters and capture the details of more difficult objects. The only DOF scripts I found relied on the camera to set the initial focus point. I wanted more control, so I wrote this script to allow selecting the focus range visually using the magnified focus view of Manual Focus (MF) mode. I find this handy when focusing from the back to the front of an object. As you focus in and out on an object, this script will keep track of the "selected" range of focus for DOF bracketing/stacking.

Parameters
- Step size. This parameter allows you to increase the change in focus so that you can make changes quicker when manually focusing (MF) during Super macro, Macro, or normal modes. The camera can actually vary the focus much finer that your eyes can detect. (if set to less than 1, then it is changed to 1)
- #Photos. This parameter allows you to choose the number of photos to make for the DOF bracketing/stacking series. (If set less than 1, then it is changed to 1)
- Save log (0=No). Allows saving of DOF Bracket/Stack focus values in a log - anything other than 0 saves a log.

What should you use for a "Step size" value?
For very close macro work like the SX20 is capable of achieving (meaning that the object is only 1 or 2 centimeters away from the front of the lens) a lower "Step size" typically might be about 2 or 3. For something from a few feet and beyond the "Step size" might be higher such as 7 or 8.

How do I set the "Focus" range for the DOF bracketing/stacking?
The focus points can be adjusted in or out using the Zoom-In, Zoom-Out, Left and Right buttons. The Zoom-In and Zoom-Out buttons allow "rough" adjustments (using "Step size") and the Left and Right buttons allow you to "fine" tune the focus points (uses half of the "Step size"). First you select the near-point focus, then press the Set button. The script then resets the focus back to the start focus and then you do the same for the far-point focus. When you have finished fine tuning the point, press the Set button and the script will then shoot the DOF bracketing/stacking series of photos. As the shots are taken, the amount of offset from the initial "Start" focus is displayed both as "+" or "-" in millimeters & percent.

How many photos should I use for DOF bracketing/stacking?
For focus bracketing/stacking in macro photography, it is usually recommended to use 5 or more photos to get the best results using programs like CombineZM or Zerene Stacker.

Save the DOF Bracket/Stack focus values in a log
This option can be enabled by setting the "Save log (0=No)" parameter to anything other than 0. The logging process of the script starts after you have set the near and far focus points for the stack and press "Set". The script then creates a log in the CHDK/LOGS folder. In order to capture multiple logs, the hour and minute are used as part of the file name. For example, if the log is created at 10:32 the filename would be "LOG_1032.TXT". The script overwrites any log with the same name. The previous log will not be overwritten until the final "Set" button, so if you can press the shutter button to exit the script so that the previous log won't be deleted. A sample log looks like this (LOG_0857.TXT):

Date: 5/31/2011
Time: 8:57:52
 
Hyperfocal_dist: 1579
DOF Sharpness: 1737
Start focus:  569
Near/Far Limits: 578-2157
 
Est Subj Dist: 649 mm (25.5 in)
 
Tweaked Range: 389-909
Max #shots possible: 521
Taking 6 photos
 
Photo: 1 of 6
Focus: 389 (-180 -31.63%)
Photo: 2 of 6
Focus: 493 (-76 -13.35%)
Photo: 3 of 6
Focus: 597 (+28 +4.92%)
Photo: 4 of 6
Focus: 701 (+132 +23.19%)
Photo: 5 of 6
Focus: 805 (+236 +41.47%)
Photo: 6 of 6
Focus: 909 (+340 +59.75%)
 
*** FINISHED ***

Subject distance
This calculation is based upon the near and far focusing distances of the "selected" range and is only provided during logging.

Basic instructions for MF-DOF bracketing/stacking
1 Set Continuous Shooting mode “off”; Review “off”; Flash “off”; MF-Point Zoom "on"; Safety MF "off"
2 Start with the AF-Point Zoom “on” to accurately set the mid-point of focus photos
3 Set script parameters
4 Select Manual Focus Mode (MF), press half shutter to set intial focus
5 Start script, press Zoom-In/Zoom-Out to start stepping the manual focus. Use /Left/Right buttons to fine tune the focus points
6 Press "Set" to start DOF bracketing portion of script
7 After the series is complete be sure to press MF to exit the MF mode.

Tips:
- Install any special purpose lens accessories needed such as close-up lenses, DCR-250, macro focusing rail, etc. before starting this script
- If you only want a quick 3-shot DOF bracket series, there is a built in option for that on the normal Canon SX20 menu.
- For step 4. Position the camera (and zoom if not in super-macro) so  the mid-focus point is mid-way on the MF range scale, otherwise you may not be able to defocus one of the end points for the DOF range that you want.
- For step 5. In order to make this step easier you can actually pan/rotate the camera on the tripod to view specific areas
 of interest and aid in the focus process - just be sure to re-position the camera for the image before taking the photos.
- This script uses wait_click statements. Some cameras require that a timeout be specified. If this script fails to run correctly in your camera, try changing the "wait_click" statements to "wait_click 5000" (5 secs).

Place "MF-DOF.bas" in Scripts folder.


Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #8 on: 31 / January / 2012, 16:53:53 »
Might be worth adding to the wiki?
Ported :   A1200    SD940   G10    Powershot N    G16

Re: MF-DOF: Manual Focus DOF bracketing/stacking script
« Reply #9 on: 31 / January / 2012, 17:30:08 »
Maybe even to CHDK build? We have only simple scripts in CHDK/SCRIPTS, why not such wonderfull?

The only reason to not include this to the CHDK builds would be more questions from new users ("I can see a script *** - what is this for?!). ;)

For me it would be great to have a collection of the best scripts just after installing CHDK.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics