Lapser Script Development - page 4 - LUA Scripting - CHDK Forum

Lapser Script Development

  • 50 Replies
  • 14322 Views
*

Offline lapser

  • *****
  • 1093
Re: Lapser Script Development
« Reply #30 on: 08 / September / 2017, 13:46:19 »
Advertisements
Test script crashed on my M3. Picture attached.
Thanks for testing it. Did you install the special CHDK build that I made for you? It's attached to this message:
https://chdk.setepontos.com/index.php?topic=13194.msg134594#msg134594
I missed this in the script
Code: [Select]
require'hookutil'
require'rawoplib'
I don't use the Lua routines in those libraries, so the "require" statements arent required.
I still have problems to understand the meaning of second 2nd brightest pixel.
The histogram is an array with a size equal to the number of possible pixel brightness values. Each element of the array contains a count of the number of pixels in the image with that particular brightness. So the last (right most) element of the histogram array is the number of pixels in the image that are blown (white level brightness).

So if there are any white level (blown) pixels in the image, they will be counted in the top histogram element. When viewing the histogram in the camera, you'll see a vertical line at the rightmost postion that gets higher the more overexposed you get. Turn down the exposure and the line disappears and the entire histogram shifts to the left. You're underexposed when the right side of the histogram (brightest pixels) shifts too far to the left.

If you know the value of the brightest pixel, the right side of the histogram, you can increase the exposure to move it to the right, but not too close to white level. I try to set the exposure so the brightest pixel value is 1/2 of white level. That way you've exposed as bright as possible without blowing pixels.

This is called ETTR: exposure to the right. It's the optimum exposure to get the most dynamic range, i.e. brightest dark areas of the image without overexposing the bright areas.
nsteps=14212545 white=16383
Shot#  Mean Pmax2 Pmax1 Wh% Wh#
    1 16382 16383 16383 99% 14207056
    2 16382 16383 16383 99% 14206049
I would expect that Pmax would below white….
If there are any white pixels (Wh#>0), Pmax1 is always white. That is, the brightest pixel must be white level. If Wh# is 2 or greater, both Pmax1 and Pmax2 must be white.
I'm hoping reyalp will want to add this to the trunk. If not, I'll continue using my own builds as before.
If I understand correctly, the interface of a function changes. Does that mean all other function calls in scripts has to be changed as well?
Would be interesting to see when I would log them in rawopint as well…
My CHDK build is backwards compatible, so rawopint should work with it. If you'll try re-installing my special build and making sure it works with my test script, then I'd be interested to know that it works with rawopint. Thanks!
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline c_joerg

  • *****
  • 1157
Re: Lapser Script Development
« Reply #31 on: 08 / September / 2017, 14:24:46 »
Did you install the special CHDK build that I made for you?

Yes of course…
I overwrote my Version with your DISKBOOT.BIN and MODULES folder. Correct?
M100 100a, M3 101a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline lapser

  • *****
  • 1093
Re: Lapser Script Development
« Reply #32 on: 08 / September / 2017, 14:40:48 »
Did you install the special CHDK build that I made for you?
Yes of course…
I overwrote my Version with your DISKBOOT.BIN and MODULES folder. Correct?
There should be a log file in CHDK/LOGS. It has the build time for you to confirm that it's the right build.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline c_joerg

  • *****
  • 1157
Re: Lapser Script Development
« Reply #33 on: 08 / September / 2017, 15:05:49 »
There should be a log file in CHDK/LOGS. It has the build time for you to confirm that it's the right build.
M100 100a, M3 101a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd


*

Offline lapser

  • *****
  • 1093
Re: Lapser Script Development
« Reply #34 on: 08 / September / 2017, 15:14:04 »
Thanks!

You did it right. I'm getting the same error on my M3, when it worked on the G1X. I'll let you know when I track it down. Nothing is easy, is it?
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline c_joerg

  • *****
  • 1157
Re: Lapser Script Development
« Reply #35 on: 08 / September / 2017, 16:46:02 »
I'll let you know when I track it down. Nothing is easy, is it?

If it were easy, it could be everyone  ;)
Perhaps it has to do with the sensor size? But no hurry, I'm out the weekend.
M100 100a, M3 101a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline lapser

  • *****
  • 1093
Re: Lapser Script Development - shoot_hook modifications
« Reply #36 on: 09 / September / 2017, 11:12:31 »
I modified script_shoot_hook_run(int hook) to provide an interval timer. Here's how you activate it in Lua:
   hook_shoot.set(-interval)

So to set a 2 second interval, you'd call it like this:
   hook_shoot.set(-2000)

I also added the option to enable the hook without a timeout (infinite timeout):
   hook_raw.set(-1)

To return the enter and exit times for a hook, I modified script_shoot_hook_count(int hook) to return those values in addition to the count. Here's the Lua call:
   count,henter,hexit=hook_shoot.count()

Here are the changes to the file, script_shoot_hook.c
Code: [Select]
//lapser begin
extern int get_tick_count();

void script_shoot_hook_run(int hook)
{
   int timeout=hooks[hook].timeout;
   int tickdone = get_tick_count();
   hooks[hook].enter = tickdone;
   hooks[hook].count++;
   // only mark hook active if it was set
   if(timeout != 0){
        // notify rawop when in raw hook, so it can update valid raw status
        // and values that might change between shots
        if(hook == SCRIPT_SHOOT_HOOK_RAW) {
            rawop_update_hook_status(1);
        }
        hooks[hook].active = 1;
      if(timeout > 0)tickdone += timeout; //normal timeout >0
      else tickdone = hooks[hook].exit - timeout; //interval timeout <0
        while(((timeout==-1)||(get_tick_count()<tickdone)) && hooks[hook].active) {
            msleep(10);
        }
        if(hook == SCRIPT_SHOOT_HOOK_RAW) {
            rawop_update_hook_status(0);
        }
        hooks[hook].active = 0; 
    }
   hooks[hook].exit = get_tick_count();
}
//lapser end

*********** also changed this function at the end of the file

//lapser begin
int icalled=0; //called 3 times from luascript.c
//return number of times hook has been called (for this script),
// plus enter and exit tick counts
int script_shoot_hook_count(int hook)
{
   icalled++;
   if(icalled == 1)return hooks[hook].count;
   if(icalled == 2)return hooks[hook].enter; //tick count entered hook
   icalled=0;
   return hooks[hook].exit; //tick count exited hook (i.e. shutter open tick)
}

I also needed to make a 2 line change in luascript.c
Code: [Select]
static int luaCB_shoot_hook_count( lua_State* L )
{
    int hook = lua_tonumber( L, lua_upvalueindex(1) );
    lua_pushnumber(L,script_shoot_hook_count(hook));
    //return 1;
 
    lua_pushnumber(L,script_shoot_hook_count(hook));//lapser hook enter time
    lua_pushnumber(L,script_shoot_hook_count(hook));//lapser hook exit time
    return 3; //lapser
}
That's all that's needed. All of my changes are backwards compatible, so they won't affect any existing scripts.

Here's the test script, "Itest.lua"
Code: [Select]
--[[
@title Interval Test
@chdk_version 1.5.0
#interval=20 "Interval (sec*10)"
#nshots=15 "# Shots (0: no limit)"
]]

--logger s: one line sent to log file (set fname before first call)
bi=get_buildinfo()
fname="A/CHDK/LOGS/"..bi.platform..os.date("_%y%m%d_%H%M_Itest.log")
function logger(s)
  if slog==nil then -- first call opens file
    if s==nil then return end -- don't open empty file
    flog=io.open(fname,"ab")
    slog={}
    nlog=0
  end
  if s~=nil then
    nlog=nlog+1
    slog[nlog]=s
  else
    for i=1,nlog do
      flog:write(slog[i],"\n")
    end
    flog:close()
    slog=nil
  end
end

function ksleep(t)
  wait_click(t)
  if not is_key("no_key") then
    done=true
  end
end

if(interval<1)then interval=1 end
interval=interval*100 -- convert to msec
--bi=get_buildinfo()
logger("Itest "..os.date())
logger(string.format("Camera:%s f/w:%s platformID:%s bit/pixel:%d",
  bi.platform,bi.platsub,bi.platformid,rawop.get_bits_per_pixel()))
logger(string.format("version:%s %s built on %s %s",
  bi.version,bi.build_number,bi.build_date,bi.build_time))
logger(string.format("Interval=%d",interval))
logger(string.format("Nshots=%d",nshots))
cls()
set_console_autoredraw(-1)
set_draw_title_line(0)
osd=get_config_value(1)
set_config_value(1, 0)
-- don't set hook_shoot until in raw hook after 1st shot (no delay before 2nd shot)
hook_raw.set(-1) -- no timeout
done=false
logger() -- write log so far to SD card
logger("Shot# Interval    Late   Early  Rdelay   Rdiff") -- reopens log file
sleep(1000)
press("shoot_half")
repeat sleep(10) until get_shooting()
press("shoot_full_only")
tlast=get_tick_count()
repeat
  while not hook_raw.is_ready() do ksleep(10) end
  hook_shoot.set(-interval) -- allows changing interval between shots
  tnow1=get_tick_count()
  count,tnow,hexit=hook_raw.count() -- tnow=raw hook enter tick
  count,henter,hexit=hook_shoot.count()

  logger(string.format("%5d%9d%8d%8d%8d%8d",
    count, hexit-tlast, hexit-tlast-interval, hexit-henter, tnow-hexit, tnow1-tnow))
  tlast=hexit
  if done or count==nshots then
    release("shoot_full")
    done=true
  end
  hook_raw.continue()
until done
logger() -- print log and close file
set_config_value(1,osd)
To compile, save the attached files into the modules folder. The Itest.lua test script is attached to my next post.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Lapser Script Development - Itest.lua
« Reply #37 on: 09 / September / 2017, 11:18:40 »
Attached is the Itest.lua script I referred to in my last post.

Here are the log files produced by Itest.lua on the M3 with 0.8, 0.7, and 0.6 intervals.
Code: [Select]
Itest Fri Sep  8 23:13:31 2017
Camera:m3 f/w:120f platformID:12953 bit/pixel:14
version:CHDK 1.5.0 built on Sep  8 2017 23:08:23
Interval=800
Nshots=15
Shot# Interval    Late   Early  Rdelay   Rdiff
    1       40    -760       0     490      10
    2      800       0     290     470      10
    3      800       0     310     470      10
    4      800       0     310     470      10
    5      800       0     310     470      10
    6      800       0     310     470      10
    7      800       0     310     470      10
    8      800       0     310     470      10
    9      800       0     310     470      10
   10      800       0     310     470      10
   11      800       0     310     470      10
   12      800       0     310     470      10
   13      800       0     310     470      10
   14      800       0     310     470      10
   15      800       0     310     470      10

Itest Fri Sep  8 23:13:55 2017
Camera:m3 f/w:120f platformID:12953 bit/pixel:14
version:CHDK 1.5.0 built on Sep  8 2017 23:08:23
Interval=700
Nshots=15
Shot# Interval    Late   Early  Rdelay   Rdiff
    1       40    -660       0     490      10
    2      700       0     190     470      10
    3      700       0     210     470      10
    4      700       0     210     470      10
    5      700       0     210     470      10
    6      700       0     210     470      10
    7      700       0     210     470      10
    8      700       0     210     470      10
    9      700       0     210     500      10
   10      700       0     170     470      10
   11      700       0     200     470      10
   12      700       0      10     480      10
   13      920     220       0     490      10
   14      880     180       0     480      10
   15      930     230       0     500      10

Itest Fri Sep  8 23:14:28 2017
Camera:m3 f/w:120f platformID:12953 bit/pixel:14
version:CHDK 1.5.0 built on Sep  8 2017 23:08:23
Interval=600
Nshots=15
Shot# Interval    Late   Early  Rdelay   Rdiff
    1       60    -540       0     490      10
    2      600       0      90     470      10
    3      600       0     110     470      10
    4      600       0     110     470      10
    5      600       0     110     470      10
    6      600       0     110     470      10
    7      600       0     110     470      10
    8      600       0     100     470      10
    9      610      10       0     480      10
   10      940     340       0     480      10
   11      920     320       0     480      10
   12      940     340       0     490      10
   13      950     350       0     490      10
   14      980     380       0     480      10
   15      860     260       0     500      10
« Last Edit: 09 / September / 2017, 14:38:07 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos


*

Offline reyalp

  • ******
  • 13457
Re: Lapser Script Development
« Reply #38 on: 09 / September / 2017, 17:52:32 »
I moved the discussion of M3 raw dimensions to the development thread: https://chdk.setepontos.com/index.php?topic=12542.msg134625#msg134625
Don't forget what the H stands for.

*

Offline c_joerg

  • *****
  • 1157
Re: Lapser Script Development
« Reply #39 on: 12 / September / 2017, 04:46:08 »
[EDIT] I updated the attached TestRwop.lua to work with the EOS-M3

I checked it and works fine. Attached are 2 results. One log is with massive overexposure, the other one well exposure against a white wall.

 
My CHDK build is backwards compatible, so rawopint should work with it. If you'll try re-installing my special build and making sure it works with my test script, then I'd be interested to know that it works with rawopint.

Rawopint works as well with your build. Made a small test. Log file attached.

If you know the value of the brightest pixel, the right side of the histogram, you can increase the exposure to move it to the right, but not too close to white level. I try to set the exposure so the brightest pixel value is 1/2 of white level. That way you've exposed as bright as possible without blowing pixels.

This is called ETTR: exposure to the right. It's the optimum exposure to get the most dynamic range, i.e. brightest dark areas of the image without overexposing the bright areas.

Ok, now I understand more what you are doing…

I would expect that the brightest pixel and second brightest pixel are floating very much…

Theoretically:
If you would calculate a histogram with 16384 cells, then you would find Pmax1 and Pmax2 also in the histogram. Right?
Not sure how much you lose, if you calculate the histogram for 1024 cells and uses Pmax1 and Pmax2 from this histogram.


If I understand you correctly, even at time-lapse in the sun you exposure to the right with no overexposure at all?

I do the same with rawopint with moon time-lapse by setting the Overexposure threshold to 0.005%. That gives me nearly ETTR.

If I use these parameters for the sun, I got massive underexposed pictures. On my G1x (at focal length 28mm) I set Overexposure threshold to 1%. In this case, approximately only the core of the sun is overexposed. I’m not sure how much EV steps between 0.005%. and 1%.

I’m thinking about of additional logging Pmax1 and Pmax2 in rawopint. In cases of overexposed scene of 1%, Pmax1 and Pmax2 would be always white correct? To see how much there are floating, I have to use a scene with no overexposure or I have set Overexposure threshold to 0.005%.
M100 100a, M3 101a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

 

Related Topics