Can I detect external light level? - Script Writing - CHDK Forum

Can I detect external light level?

  • 10 Replies
  • 6299 Views
Can I detect external light level?
« on: 15 / March / 2011, 08:10:42 »
Advertisements
Can I detect the light levels outside the camera? I've got some computer controlled lights I turn on to take a photo and I'm wondering if an SDM ubasic script could discover for itself that the lights are on? Maybe by doing a half click and detecting the exposure time and/or ISO setting the camera picked?

*

Offline reyalp

  • ******
  • 13456
Re: Can I detect external light level?
« Reply #1 on: 15 / March / 2011, 15:55:18 »
Use the Bv propcase. Needs a half shoot to update. See http://chdk.wikia.com/wiki/PropertyCase

Bv is the APEX bv, multiplied by 96
Don't forget what the H stands for.

Re: Can I detect external light level?
« Reply #2 on: 15 / March / 2011, 16:15:12 »
I did look at that propcase earlier today.

In very dark conditions you get values of about 65000.

Is this a signed value ?
« Last Edit: 15 / March / 2011, 17:03:05 by Microfunguy »

Re: Can I detect external light level?
« Reply #3 on: 15 / March / 2011, 17:10:50 »
Seems to work. I just plugged in this test script:

@title Bv test
:loop
 press "shoot_half"
 sleep 500
 get_prop 34 a
 print "Bv is", a
 release "shoot_half"
 sleep 500
 goto "loop"
end

and I can watch the value go up to about 800/850 with bright lights illuminating the scene and drop down to around 600/650 with the lights off and just a moderately dim room providing ambient light. Thanks.


Re: Can I detect external light level?
« Reply #4 on: 15 / March / 2011, 17:42:39 »
I will add a get_brightness command to SDM.

I tested the above propcase on an S95 so maybe the propcase number in the CHDK port is not correct.

Re: Can I detect external light level?
« Reply #5 on: 15 / March / 2011, 18:20:52 »
I think I also saw a value that was something like 65000 when I first turned it on, but after running for a while, I was consistently getting the 800 to 600 range numbers. Not sure where the one strange number came from.

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Can I detect external light level?
« Reply #6 on: 15 / March / 2011, 20:19:52 »
I happened to be experimenting with the APEX UBasic statements over the weekend using my SX20 and got even different results. My values varied from:
    a very dark room with no lights & dark overcast night (-908)
    room using daylight (207)
    same room at night using Tunsten lighting (250)
I haven't been able to test outside during sunlight yet since it's been raining with a heavy overcast the last few days. You'll see in the script that I was using the following UBasic statements: get_user_av96,  get_user_tv96, get_bv96, and get_sv96

The script does have one PropCas statement for the SX20 that I use to indicate which mode I was using for the test at the time (just rem the statement or remove). The only parameter is for saving the results to a file for later so that I could compare results (1=log results, anything else just display to OSD). The LOG file is created in the CHDK/LOGS folder and the name uses the hour/minute to keep multiple log files separate. The logged data looks like:
Code: [Select]
Date: 15/3/2011
Time: 18:47:46
 
Mode:Av
Av:F/2.8
Tv:1/30
ISO:AutoISO
av96=294 tv96=480
bv96=138 sv96=603

When you aren't saving the data to a log file, the script will wait for you to press the set button at the end. This keeps the displayed info for review until you are done. Here's the script I used when testing:

Code: [Select]
@title APEX_96
@param a Save results (1=yes)
@default a 0

if a<>1 then goto "skip_save"
z=get_time 0
y=get_time 1
x=get_time 2
m=get_time 3
n=get_time 4
p=get_time 5
g=x*100+y
if g<1 then g=1
if g>9999 then g=9999
print_screen g
print "Date: "m"/"n"/"p
print "Time: "x":"y":"z
print " "

:skip_save
 rem *** SX20 ***
 get_prop 50 B
 if B=8228 then print "Mode:Custom"
 if B=-32767 then print "Mode:Manual"
 if B=-32766 then print "Mode:Av"
 if B=-32765 then print "Mode:Tv"
 if B=-32764 then print "Mode:Program"
 if B=-32768 then print "Mode:Auto"
 if B=-32755 then print "Mode:Portrait"
 if B=-32756 then print "Mode:Landscape"
 if B=-32757 then print "Mode:Night Snapshot"
 if B=-32249 then print "Mode:Sports"    
 if B=16402 then print "Mode:Sunset"  
 if B=-32246 then print "Mode:Stitch Assist"    
 if B=2600 then print "Mode:Movie"
 rem *** SX20 ***
 press "shoot_half"
 sleep 600
 x=get_user_av_id
 gosub "prnt_av"
 x=get_user_tv_id
 gosub "prnt_time"
 x=get_iso
 gosub "prnt_iso"
 get_user_av96 A
 get_user_tv96 T
 print "av96="A" tv96="T
 get_bv96 B
 get_sv96 S
 print "bv96="B" sv96="S
 if a=1 then goto "done"
 gosub "wait_loop"
 goto "done"

:prnt_time
 if x=-12 then print "Tv:15s"
 if x=-11 then print "Tv:13s"
 if x=-10 then print "Tv:10s"
 if x=-9 then print "Tv:8s"
 if x=-8 then print "Tv:6s"
 if x=-7 then print "Tv:5s"
 if x=-6 then print "Tv:4s"
 if x=-5 then print "Tv:3.2s"
 if x=-4 then print "Tv:2.5s"
 if x=-3 then print "Tv:2s"
 if x=-2 then print "Tv:1.6s"
 if x=-1 then print "Tv:1.3s"
 if x=0 then print "Tv:1s"
 if x=1 then print "Tv:0.8s "
 if x=2 then print "Tv:0.6s"
 if x=3 then print "Tv:0.5s"
 if x=4 then print "Tv:0.4s"
 if x=5 then print "Tv:0.3s"
 if x=6 then print "Tv:1/4"
 if x=7 then print "Tv:1/5"
 if x=8 then print "Tv:1/6"
 if x=9 then print "Tv:1/8"
 if x=10 then print "Tv:1/10"
 if x=11 then print "Tv:1/13"
 if x=12 then print "Tv:1/15"
 if x=13 then print "Tv:1/20"
 if x=14 then print "Tv:1/25"
 if x=15 then print "Tv:1/30"
 if x=16 then print "Tv:1/40"
 if x=17 then print "Tv:1/50"
 if x=18 then print "Tv:1/60"
 if x=19 then print "Tv:1/80"
 if x=20 then print "Tv:1/100"
 if x=21 then print "Tv:1/125"
 if x=22 then print "Tv:1/160"
 if x=23 then print "Tv:1/200"
 if x=24 then print "Tv:1/250"
 if x=25 then print "Tv:1/320"
 if x=26 then print "Tv:1/400"
 if x=27 then print "Tv:1/500"
 if x=28 then print "Tv:1/640"
 if x=29 then print "Tv:1/800"
 if x=30 then print "Tv:1/1000"
 if x=31 then print "Tv:1/1250"
 if x=32 then print "Tv:1/1600"
 if x=33 then print "Tv:1/2000"
 if x=34 then print "Tv:1/2500"
 if x=35 then print "Tv:1/3200"
 return

:prnt_iso
 if x=0 then print "ISO:AutoISO"
 if x=1 then print "ISO:50(80)"
 if x=2 then print "ISO:100"
 if x=3 then print "ISO:200"
 if x=4 then print "ISO:400"
 if x=5 then print "ISO:800"
 if x=6 then print "ISO:1600"
 if x=7 then print "ISO:3200"
 if x=-1 then print "ISO:HiISO"
 return

:prnt_av
 if x=9 then print "Av:F/2.8"
 if x=10 then print "Av:F/3.2"
 if x=11 then print "Av:F/3.5"
 if x=12 then print "Av:F/4.0"
 if x=13 then print "Av:F/4.5"
 if x=14 then print "Av:F/5.0"
 if x=15 then print "Av:F/5.6"
 if x=16 then print "Av:F/6.3"
 if x=17 then print "Av:F/7.1"
 if x=18 then print "Av:F/8.0"
 return

:wait_loop
 wait_click
 is_key k "set"
 if k=1 then goto "exit_wait"
 goto "wait_loop"
:exit_wait
 return

:done
 release "shoot_half"
 print_screen 0
end

Might be interesting to hear what others get using the script. During the experimenting over the weekend, I found that the av96 and tv96 values were comparable to what shows in the UBasic manual, so I'm hoping that the bv96 an sv96 values also are correct for the SX20. I posted the av96 & tv96 results I found using my SX20 in the SX20 forum here: http://chdk.setepontos.com/index.php?topic=4348.msg62913#msg62913
« Last Edit: 15 / March / 2011, 22:03:45 by SkyWalker9 »

*

Offline reyalp

  • ******
  • 13456
Re: Can I detect external light level?
« Reply #7 on: 15 / March / 2011, 22:21:16 »
I did look at that propcase earlier today.

In very dark conditions you get values of about 65000.

Is this a signed value ?
Yes, it's a signed value, per Douglas Kerr's APEX doc ( http://dougkerr.net/pumpkin/articles/APEX.pdf ) , Bv values less than one foot-lambert would be negative.

In CHDK script propcase code, this should be properly sign extended.
Don't forget what the H stands for.


*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Can I detect external light level?
« Reply #8 on: 16 / March / 2011, 10:57:55 »
The sun finally can out this morning and I was able to take some sunlight readings at 11 am with the script above using my SX20.

- for standard landscape shot bv was 785
- pointed at a white stairway railing bv was 799
- bright, clear sky while pointed 90 degrees from the sun the bv was 1057 (at noon, bv was 1114)
« Last Edit: 16 / March / 2011, 11:58:32 by SkyWalker9 »

*

Offline reyalp

  • ******
  • 13456
Re: Can I detect external light level?
« Reply #9 on: 16 / March / 2011, 16:53:35 »
The sun finally can out this morning and I was able to take some sunlight readings at 11 am with the script above using my SX20.

- for standard landscape shot bv was 785
- pointed at a white stairway railing bv was 799
- bright, clear sky while pointed 90 degrees from the sun the bv was 1057 (at noon, bv was 1114)
The meaning of the Bv value is described in the PDF I linked. The Canon Bv values is simply the APEX value multiplied by 96 (to avoid floating point math.) The exact conversion to real depends on Canons choice of "correct" exposure, but this should not matter for most purposes.

The APEX equation also tells you how this relates to your chose exposure parameters, for a "correct" exposure: Av+Tv=Bv+Sv

If you use the get/set_*96 script functions, you can very easily use the above to calculate correct exposure while varying any of the exposure parameters.
Don't forget what the H stands for.

 

Related Topics