Setting focus from scripts or menus - page 56 - General Discussion and Assistance - CHDK Forum

Setting focus from scripts or menus

  • 601 Replies
  • 211985 Views
*

Offline Sdack

  • ***
  • 195
Re: Setting focus from scripts or menus
« Reply #550 on: 29 / November / 2017, 19:05:31 »
Advertisements
set_prop.AF_LOCK(1)
The function is set_aflock(1)
From the script output, it looks like set_mf(1) should also work.

I realized that set_mf(1) does in fact work for my IXUS160 cause it's in my script.

However I went ahead with the test you suggest below:

Quote
You can test this by aiming the camera at a subject it doesn't have trouble focusing on, and then using set_focus() to set the opposite extreme. So if your test object is nearby, you could do something like the following in chdkptp

=set_focus(50000) shoot()

and the resulting image should be badly out of focus if SD override worked, or in focus if it didn't.
And my resulting image was sharp on an object less than a meter away, so I hope that is useful
information

Here's my results from a get_dofinfo() command

Code: [Select]
con 1> =return get_dofinfo()
2:return:table:{hyp_valid=false,eff_focal_length=28000,coc=5,aperture=3268,near=-1,min_stack_dist=28,dof=-1,focal_length=5000,hyp_dist=1535,far=-1,focus=-1,focus_valid=false,}


I am wondering what hyp_valid=false might mean?  Every camera has a hyperfocal distance, right?

I'm simply looking for the command to set my focal length at it's hyperfocal distance, for maximum depth of field.

Any suggetions welcome
Sdack
« Last Edit: 29 / November / 2017, 19:49:27 by Sdack »

Re: Setting focus from scripts or menus
« Reply #551 on: 29 / November / 2017, 22:26:08 »
And my resulting image was sharp on an object less than a meter away,
Repeat the test but use this command string instead :
Code: [Select]
=set_mf(1) set_focus(2000) shoot()
Quote from: Sdack link=topic=11078.msg135482#msg13548
I'm simply looking for the command to set my focal length at it's hyperfocal distance, for maximum depth of field.
Assuming you can put your camera into a mode where CHDK SD override works correctly, (i.e. call set_mf(1) first) then use :
Code: [Select]
set_focus(get_dofinfo().hyp_dist)

Incidentally, I reverted your recent wiki edit that said
Quote
or maybe try
=return get_dofinfo()
chdkptp command syntax does not belong on a page that describes scripting functions.
« Last Edit: 29 / November / 2017, 22:36:34 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline Sdack

  • ***
  • 195
Re: Setting focus from scripts or menus
« Reply #552 on: 29 / November / 2017, 23:59:05 »
And my resulting image was sharp on an object less than a meter away,
Repeat the test but use this command string instead :
Code: [Select]
=set_mf(1) set_focus(2000) shoot()
Quote from: Sdack link=topic=11078.msg135482#msg13548
I'm simply looking for the command to set my focal length at it's hyperfocal distance, for maximum depth of field.
Assuming you can put your camera into a mode where CHDK SD override works correctly, (i.e. call set_mf(1) first) then use :
Code: [Select]
set_focus(get_dofinfo().hyp_dist)

Hi, using the full command sequence now ie.
=set_mf(1)
=set_focus(XXX)
=shoot()

I shot several focal lengths, from 300mm to 10,000mm, plus the hyperfocal formula you suggested above.  The 300mm version was very clearly blurry for distant objects but it seems there's no visible difference, over 3000mm.  I guess that's just the normal state of the Canon lens on this model.

Quote
Incidentally, I reverted your recent wiki edit that said
Quote
or maybe try
=return get_dofinfo()
chdkptp command syntax does not belong on a page that describes scripting functions.

Thanks for that.  I was trying to be helpful but I'm obviously not up to speed yet.
Sdack

*

Offline reyalp

  • ******
  • 14121
Re: Setting focus from scripts or menus
« Reply #553 on: 30 / November / 2017, 01:47:43 »
Hi, using the full command sequence now ie.
=set_mf(1)
=set_focus(XXX)
=shoot()
A general warning: If you are setting overrides in chdkptp, you should do it all in one command, like
=set_mf(1)  set_focus(XXX) shoot()

because many overrides only take effect for the duration of a script. Your example should be OK because focus stays at whatever you set it to after set_mf(), but for cameras that allow focus override in AF mode, this would not work. Exposure overrides will also be ignored if they are a separate command from the shoot.

Quote
I am wondering what hyp_valid=false might mean?  Every camera has a hyperfocal distance, right?
Yes, every camera should have a hyperfocal distance, but it depends on the zoom and aperture.
I'm not sure what the intent of that value is, it seems depend on whether the camera focused successfully (which should be irrelevant to the hyperfocal distance) and whether the camera is ready in half press, which may be required to correctly get the aperture.

To get the values in half press in chdkptp, you can do something like

=press'shoot_half' repeat sleep(10) until get_shooting() return get_dofinfo()
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 14121
Re: Setting focus from scripts or menus
« Reply #554 on: 22 / April / 2018, 17:48:59 »
A random observation:
On sx160, attempting to use set_mf to turn  MF on or off while the camera is in display + sensor off power saving mode crashes
Code: [Select]
ASSERT!! Imager.c Line 1001
Occured Time  2018:04:22 13:41:38
Task ID: 28246079
Task name: WBIntegTask
This isn't really surprising.

It would be nice if there was a way to detect when the camera was in this state though.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 4451
Re: Setting focus from scripts or menus
« Reply #555 on: 24 / April / 2018, 14:43:02 »
It would be nice if there was a way to detect when the camera was in this state though.
The fw variable directly involved in this assert (0x20a4+4) would be a first candidate. I located the equivalent on one of my cameras and found that it is set to 1 when the sensor is active and 0 otherwise (sleep or playback mode *). Entering the rec menu did not affect the variable though, so maybe it's not the best choice. Perhaps some of the other imager related variables could work better...?

edit:
* also 0 in recreview (and recreview hold)
« Last Edit: 24 / April / 2018, 14:58:37 by srsa_4c »

Re: Setting focus from scripts or menus
« Reply #556 on: 09 / April / 2019, 13:48:11 »
Here the results from a Cannon SX280

Re: Setting focus from scripts or menus
« Reply #557 on: 10 / December / 2021, 21:37:01 »
Here are the results for the G7X2.  Crashed with each attempt.


*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: Setting focus from scripts or menus
« Reply #558 on: 04 / February / 2022, 13:30:35 »
i am testing set focus on the G1X in Av mode, but it doesn't seem to work as I expected.
in case you are wondering  :) safety MF is off in the menu.

since i am going for a large distance (40-50 meter) i suspected it not to be exact and was wondering how to narrow that down to less than 2000, the script sets focus somewhere +/-15000 from set_focus(45000) at start....and sometimes even more.
but before i am cracking my head over how to solve that i noticed something else...

after looking at the images had the feeling focus changes between shots although the cam states AFL on display after starting the script.
so i added a get_focus() after each shot and that seemed to confirm my feeling: the values change between shots.

then I tried manual focus, and if i then use set focus the same happens: focus runs away after some shots.

the script uses press'shoot_half' and that might interfere with actual settings, so i tried adding a set_focus(45000) just before click'shoot_full' but no change there in MF or AF....focus value still changes between shots.

Did i overlook some setting or is this common with the G1X?

the code I'm using to set focus is from Ultimate Intervalometer:

Code: [Select]
        local sd_modes = get_sd_over_modes()                            -- get camera's available MF modes - use AFL if possible, else MF if available
        if ( bitand(sd_modes, 0x02) ~= 0 ) then
            set_aflock(true)
        elseif ( bitand(sd_modes, 0x04) ~= 0 ) then
            set_mf(true)
            if (get_prop(props.FOCUS_MODE) ~= 1) then printf("Warning:MF enable failed***") end
        end
        if (sd_modes>0) then
            sleep(1000)
            set_focus(INFINITY)
            sleep(2000)
            printf("First position:Get Focus:"..get_focus())
        end

starting the cam in Av with AF, script locks AFL and sets focus: display shows AFL:
this is a small part of the closest run i got: get_focus() values of first 15 images.
 45500, 45500,  45500,  45500, 45500, 49500, 49500, 61346, 49500, 38636, 49500, 49500, 49500, 49500, 49500 etc

this log was shot in Av priority, but it did not seem to make a difference in the results
« Last Edit: 04 / February / 2022, 13:40:51 by Mlapse »
frustration is a key ingredient in progress

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: Setting focus from scripts or menus
« Reply #559 on: 04 / February / 2022, 14:24:53 »
 :) ?
Code: [Select]
      if ( bitand(sd_modes, 0x04) ~= 0 ) then
            set_mf(true)
            if (get_prop(props.FOCUS_MODE) ~= 1) then printf("Warning:MF enable failed***") end
      elseif ( bitand(sd_modes, 0x02) ~= 0 ) then
            set_aflock(true)
      end
All lifetime is a loan from eternity.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal