Set focus question - General Help and Assistance on using CHDK stable releases - CHDK Forum supplierdeeply

Set focus question

  • 29 Replies
  • 843 Views
Set focus question
« on: 03 / August / 2020, 04:05:43 »
Advertisements
@reyalp


Can you or someone throw a little knowledge my way.


When I play around with DoF reporting, eg use EXIF etc, I see the DoF subject distance change.


The question I have is, when I use set focus in a Lua, what is its reference? The sensor plane or some other plane?


I’ve tried to work it out myself,  but the ‘jitter’ in the system isn’t giving me a consistent view.


Cheers


Garry

*

Offline Caefix

  • ****
  • 282
  • Sorry, busy deleting test shots...
Re: Set focus question
« Reply #1 on: 03 / August / 2020, 11:36:16 »
 ::) ...found a poem...
Code: [Select]
gui_osd lines 891,896
                shooting_set_focus(shooting_get_subject_distance_override_value(),SET_NOW);


shooting.c lines 1010++
//-------------------------------------------------------------------
// Get override values

int shooting_get_subject_distance_override_value()
{
    if (conf.subj_dist_override_koef != SD_OVERRIDE_INFINITY)
        return (conf.subj_dist_override_value < shooting_get_lens_to_focal_plane_width()?0:(conf.subj_dist_override_value - shooting_get_lens_to_focal_plane_width()));
    else
        return INFINITY_DIST;
}
All lifetime is a loan from eternity.

Re: Set focus question
« Reply #2 on: 03 / August / 2020, 11:57:05 »
@Caefix

Many thanks for the 'poem' and a reminder I have tried to understand this before ;-)

The issue, when I look at shooting.c, is trying to work out where shooting_get_lens_to_focal_plane_width comes from, ie is it extracted from the Canon side and thus represents the front principal plane relative to the sensor plan: which it infers it does. Or is it mysteriously calculated from a CHDK side assumption.

Then the 'problem' is, how do I tap into shooting_get_lens_to_focal_plane_width in Lua?

The bottom line for me is that I'm trying to convince myself that a modified thin lens model can be used, ie http://photography.grayheron.net/2020/07/a-credit-card-based-generalised-focus.html


*

Offline Caefix

  • ****
  • 282
  • Sorry, busy deleting test shots...
Re: Set focus question
« Reply #3 on: 03 / August / 2020, 13:14:47 »
 :o 0xffdec420,GetFocusLensSubjectDistance_FW

One of ~3400 hits of searching for GetFocusLensSubjectDistance in trunkfiles I would never look at...

Btw. No easy way from 'shooting.c' to Lua... (Modification of Luascript.c failed here)
Quote
/*
static int luaCB_get_lens_to_focal_plane_width( lua_State* L )
{
    lua_pushnumber( L, shooting_get_lens_to_focal_plane_width() );
    return 1;
}
//   FUNC(get_lens_to_focal_plane_width)
*/

In file .o/lua.elf:
elf2flt unknown symbol: 'shooting_get_lens_to_focal_plane_width'
gmake[1]: *** [.o/lua.flt] Error 5
gmake: *** [all-recursive] Error 1
All lifetime is a loan from eternity.


*

Offline reyalp

  • ******
  • 12736
Re: Set focus question
« Reply #4 on: 03 / August / 2020, 13:18:50 »
The issue, when I look at shooting.c, is trying to work out where shooting_get_lens_to_focal_plane_width comes from, ie is it extracted from the Canon side and thus represents the front principal plane relative to the sensor plan: which it infers it does.


Code: [Select]
int shooting_get_lens_to_focal_plane_width()
{
    return (int)(lens_get_focus_pos()-lens_get_focus_pos_from_lens());
lens_get_focus_pos and lens_get_focus_pos_from_lens are platform specific, defined in each platform wrappers.c. Typically they call firmware functions named _GetFocusLensSubjectDistance() and _GetFocusLensSubjectDistanceFromLens() respectively.

Determining the extent to which those functions do what the names suggest, and to what accuracy if so is left as an exercise to the reader ;)

My recollection is the values seem "reasonable" on normal cameras. The EOS M cameras use different functions and I have no information about how they work.

Quote
The question I have is, when I use set focus in a Lua, what is its reference? The sensor plane or some other plane?
IIRC, with the default settings ("Canon Subj. Dist. as Near Limit."  and "Use EXIF Subj. Dist. (PC65)" off) the values from get_focus() are compatible with set_focus(). That is, if you do set_focus(x), get_focus() will return x (assuming x is one of the focus values set_focus can land on)

The full impact of the two options is unclear to me, although "Use EXIF Subj. Dist. (PC65)" looks like it should affect both getting and setting (despite being in the OSD section, it affects the override values and script).

I made a comparison of the different SD values in https://chdk.setepontos.com/index.php?topic=11078.msg130083#msg130083
From those results, it looks like the default get_focus()/set_focus() is a few cm lower than the prop value, suggesting it's the "from lens" distance while the propcase distance is from the sensor. "Use EXIF Subj. Dist. (PC65)" would presumably make them the same or similar.

If the option is off, you could get the with from the difference.
Don't forget what the H stands for.

Re: Set focus question
« Reply #5 on: 03 / August / 2020, 13:22:03 »
@reyalp

Quote
If the option is off, you could get the with from the difference.

I was thinking along those lines.

I’ll try some experiments.

Cheers

Garry

*

Offline reyalp

  • ******
  • 12736
Re: Set focus question
« Reply #6 on: 03 / August / 2020, 14:21:41 »
Btw. No easy way from 'shooting.c' to Lua... (Modification of Luascript.c failed here)
Code: [Select]
In file .o/lua.elf:
elf2flt unknown symbol: 'shooting_get_lens_to_focal_plane_width'
gmake[1]: *** [.o/lua.flt] Error 5
gmake: *** [all-recursive] Error 1
Exports from the core to modules need to appear in modules/module_exportlist.c
That said, it might be better to include this in dofinfo rather than adding a new function.
Don't forget what the H stands for.

Re: Set focus question
« Reply #7 on: 03 / August / 2020, 14:51:15 »
Quote
That said, it might be better to include this in dofinfo rather than adding a new function.


And accessible in Lua ;-)


+1
« Last Edit: 03 / August / 2020, 15:00:08 by pigeonhill »


*

Offline Caefix

  • ****
  • 282
  • Sorry, busy deleting test shots...
Re: Set focus question
« Reply #8 on: 03 / August / 2020, 15:24:50 »
 :D The retriangulation of the wheel was successfull, too
No drums there, nice to play with, back to the didgeridoo...
Code: [Select]
--[[--
@title jogdial.Lua
@chdk_version 1.4
@param J Use Jogdial
@default J 1
@range J 0 1
--]]--

repeat
print(-is_wheel_left(),is_wheel_right())
sleep( 111)
print("", is_wheel_right(),-is_wheel_left())
sleep( 222)
until is_key "set"

c=0; j=0
repeat
if J==1 then
   j=get_wheel(); c=c+j;
   if j==-1 then print( j, "wheel_left",c) end
   if j==1  then print( j, "wheel_right",c) end
   sleep(111) end
until 1>2


--[[--
    FUNC(get_wheel)
    FUNC(is_wheel_left)
    FUNC(is_wheel_right)

static int luaCB_get_wheel( lua_State * L )
{
  short r=get_jogdial_direction();
  jogdial=0;
  if (r==0) {
     lua_pushnumber( L, 0 );
     return 1;
  }
  r=r==JOGDIAL_LEFT ? -1:1; // left=-1 | right=1
  lua_pushnumber( L, r );
    return 1;
}
static int luaCB_is_wheel_right( lua_State* L )
{
  if (jogdial==1) {jogdial=0;
         lua_pushnumber( L, 1 );
return 1;}
  if (jogdial==-1) {
         lua_pushnumber( L, 0 );
return 1;}
      short r=get_jogdial_direction();
  jogdial=r==JOGDIAL_LEFT ? -1:0; //
  if (r==0) {
         lua_pushnumber( L, 0 );
return 1;}
  r=r==JOGDIAL_RIGHT ? 1:0;
      lua_pushnumber( L, r );
  return 1;
}

static int luaCB_is_wheel_left( lua_State* L )
{
  if (jogdial==-1) {jogdial=0;
         lua_pushnumber( L, 1 );
return 1;}
  if (jogdial== 1) {
         lua_pushnumber( L, 0 );
return 1;}
      short r=get_jogdial_direction();
  jogdial=r==JOGDIAL_RIGHT ? 1:0; //
  if (r==0) {
         lua_pushnumber( L, 0 );
return 1;}
  r=r==JOGDIAL_LEFT ? 1:0;
      lua_pushnumber( L, r );
  return 1;
}
--]]--
All lifetime is a loan from eternity.

Re: Set focus question
« Reply #9 on: 04 / August / 2020, 01:08:13 »
Quote
The retriangulation of the wheel was successfull
Was this meant to be posted here?

 

Related Topics