Author Topic: Video zoom and focus script  (Read 4663 times)

Offline kamil

  • Rookie
  • *
  • Posts: 21
  • G7
Video zoom and focus script
« on: 29 / January / 2008, 16:38:13 »
  • Publish
  • Hi

    I wrote script for G7 cameras (and G9 i suppose) with zoom jumping and manual focus. G7 don't have autofocus in video mode. Maybe others cameras have it. I hope that this script will help somebody.

    I know that it is not best solution for zooming and focusing. It's complicated and noisy. But i didnt found simillar script for video. For fast zoom changing and focus is possible by presets.

    If you want any changes please report.

    Nice standard zooming and autofocusing is impossible at now i think so. CHDK must change (add better zoom in, zoom out operations like get_zoom_in_press, get_zoom_in_release, something for autofocus)

    Sorry for my english  :-X
    Its my first script so sorry also for errors if they are (i haven't bugs in my allbest CHDK). Please test it on other cameras and report how it's work (change focus algorithm and zoom extremal values to fit Your camera)
    Code: [Select]
    rem Author kamil, v.1.0
    @title zoom and focus in video for g7
    @param a zoom jump \erase\ (std)
    @default a 7
    @param b zoom jump \left\
    @default b 1
    @param c zoom jump \set\
    @default c 3
    @param d zoom jump \right\
    @default d 5
    @param e zoom jump \display\
    @default e 11
    @param g focus at start (1-11)
    @default g 5
    @param f focus jump to \menu\ (*100)
    @default f 13
    @param h help (1-on)

    if h=1 then gosub "help"

    get_prop 12 q
    if q=0 then set_prop 12 1

    z=a
    v=g

    press "shoot_half"
    sleep 800
    click "shoot_full"

    :loop
    wait_click
    if is_key "zoom_in" then goto "in"
    if is_key "zoom_out" then goto "out"
    if is_key "up" then goto "add_focus"
    if is_key "down" then goto "min_focus"
    if is_key "display" then z=e
    if is_key "erase" then z=a
    if is_key "left" then z=b
    if is_key "set" then z=c
    if is_key "right" then z=d
    if is_key "menu" then goto "focus_extra"
    if is_key "shoot_half" then goto "end"
    print "zoom jump", z
    goto "loop"

    :in
    if z<0 then let z=1
    if z>13 then let z=13
    set_zoom_rel z
    get_zoom r
    print "zoom", r
    goto "loop"

    :out
    if z<0 then let z=1
    if z>13 then let z=13
    set_zoom_rel -z
    get_zoom r
    print "zoom", r
    goto "loop"

    :add_focus
    v=v+1
    gosub "focus_dance"
    goto "loop"

    :min_focus
    v=v-1
    gosub "focus_dance"
    goto "loop"

    :focus_dance
    if v<1 then let v=1
    if v>11 then let v=11
    u=(v*v*v*v)+80
    if v=11 then u=65535
    print "focus", u; "mm"
    set_focus u
    return

    :focus_extra
    u=f*100
    set_focus u
    goto "loop"

    :end
    click "shoot_full"
    end

    :help
    print "When You need a special"
    print "functions in camera..."
    print "Use with CAUTION"
    print " - [ click ANY KEY ] - "
    wait_click
    print "written for G7"
    print "You must change script"
    print "of ZOOM and FOCUSING"
    print "data for your camera"
    print " - [ click ANY KEY ] - "
    wait_click
    print "KEYS:"
    sleep 1000
    print "- up/down - focus (11)"
    print "- left/set/right/disp"
    print "  /erase - ZOOM PRESETS"
    print "- menu - FOCUS PRESET"
    print " - [ click ANY KEY ] - "
    wait_click
    print "Feel free in modify this"
    print "script to make it more"
    print "comfortable"
    print " "
    print " - [ click ANY KEY ] - "
    wait_click
    print "press SHOOT HALF"
    print "to end recording"
    print "Because of zoom and"
    print "focusing noises"
    print " - [ click ANY KEY ] - "
    wait_click
    print "i suggest record the"
    print "sound with another"
    print "recorder and join with"
    print "nandub for example"
    print " - [ click ANY KEY ] - "
    wait_click
    print "enter 0 in param help"
    print "Now set camera to video"
    print "Script will start"
    print "recording..."
    print " - [ click ANY KEY ] - "
    wait_click
    cls
    return

    end
    « Last Edit: 29 / January / 2008, 17:19:01 by kamil »

    Offline kamil

    • Rookie
    • *
    • Posts: 21
    • G7
    Re: Video zoom and focus script
    « Reply #1 on: 07 / February / 2008, 19:43:26 »
  • Publish
  • Version 2.0  :)

    News:
    - exp_cor button in g7 camera
    - display & menu keys can change zoom and focus rapidly. They are also configurable, you can disable zoom or focus on it by enter 0 param
    - better focus
    - other small changes

    Other cameras:
    If your camera dont have 13 zoom stops then you can change value of "k" in 31 line of code.
    If you have different focus numbers then you must change math expression :(

    I'm waiting for report bugs and suggestions

    [add 21.02.2008:]

    ver. 2.5

    News:
    - there was na error in "menu" focusing"
    - nice visualisation of important parameters

    Code: [Select]
    rem Author kamil, script ver. 2.5, allbuild, works on g7,a710is,...
    @title zoom and focus in video
    @param a auto focus /erase/
    @default a 3
    @param b auto focus /expo_corr/
    @default b 10
    @param c step zoom /left/
    @default c 4
    @param d step zoom /set/ - at start
    @default d 7
    @param e step zoom /right/
    @default e 13
    @param f auto zoom /display/
    @default f 1
    @param g auto focus /display/
    @default g 2
    @param h auto zoom /menu/
    @default h 11
    @param i auto focus /menu/
    @default i 10
    @param j help (1-on)
    @default j 1

    if j=1 then gosub "help"

    get_prop 12 q
    if q=0 then set_prop 12 1

    z=d

    rem zoom range, change this value if your zoom is different
    k=13

    get_zoom t
    get_focus u
    o=0

    do
    o=o+1
    p=o*o*(o+1)*(o+1)+90
    until u<p

    v=o
    if v>11 then let v=11

    press "shoot_half"
    sleep 800
    click "shoot_full"

    :loop
    cls
    print "        ", z, "|"
    print t; "/" k, "-zoom |","focus-", v; "/11"
    wait_click
    cls
    if is_key "zoom_in" then goto "in"
    if is_key "zoom_out" then goto "out"
    if is_key "up" then goto "add_focus"
    if is_key "down" then goto "min_focus"
    if is_key "left" then z=c
    if is_key "set" then z=d
    if is_key "right" then z=e
    if is_key "erase" then goto "focus_1"
    if is_key "expo_corr" then goto "focus_2"
    if is_key "display" then goto "zoom_focus_1"
    if is_key "menu" then goto "zoom_focus_2"
    if is_key "shoot_half" then goto "end"
    goto "loop"

    :in
    if z<0 then let z=1
    if z>k then let z=k
    set_zoom_rel z
    get_zoom t
    print "zoom", t; "/" k
    goto "loop"

    :out
    if z<0 then let z=1
    if z>k then let z=k
    set_zoom_rel -z
    get_zoom t
    print "zoom", t; "/" k
    goto "loop"

    :focus_1
    v=a
    gosub "focus_dance"
    goto "loop"

    :focus_2
    v=b
    gosub "focus_dance"
    goto "loop"

    :zoom_focus_1
    if g>0 then gosub "focus_zoom_focus_1"
    if f>0 then gosub "zoom_zoom_focus_1"
    if g>0 then gosub "focus_zoom_focus_1"
    goto "loop"

    :focus_zoom_focus_1
    v=g
    gosub "focus_dance"
    return

    :zoom_zoom_focus_1
    set_zoom f
    t=f
    return

    :zoom_focus_2
    if i>0 then gosub "focus_zoom_focus_2"
    if h>0 then gosub "zoom_zoom_focus_2"
    if i>0 then gosub "focus_zoom_focus_2"
    goto "loop"

    :focus_zoom_focus_2
    v=i
    gosub "focus_dance"
    return

    :zoom_zoom_focus_2
    set_zoom h
    t=h
    return

    :add_focus
    v=v+1
    gosub "focus_dance"
    goto "loop"

    :min_focus
    v=v-1
    gosub "focus_dance"
    goto "loop"

    :focus_dance
    u=(v*v*v*v)+90
    if v>=11 then u=65535
    if v<1 then let v=1
    if v>11 then let v=11
    set_focus u
    return

    :end
    click "shoot_full"
    end

    end

    :help
    print "Use with CAUTION"
    print "working on G7,A710is"
    print "maybe others too"
    print "or you need modify this"
    print " - [ click ANY KEY ] - "
    wait_click
    print "script. Zoom and focus"
    print "values could be different"
    print "lines to modify:"
    print "31,132,133"
    print " - [ click ANY KEY ] - "
    wait_click
    print "keys:"
    print "UP/DOWN - focusing"
    print "ZOOM IN/ZOOM OUT -zooming"
    print "LEFT/SET/RIGHT - zoom set"
    print " - [ click ANY KEY ] - "
    wait_click
    print "ERASE/EXP - focus set"
    print "DISPL/MENU - zoom & focus"
    print "You can disable focus"
    print "or zoom setting by enter"
    print " - [ click ANY KEY ] - "
    wait_click
    print "0 parameter"
    print "focus has 11 steps"
    print "zoom has 13 steps"
    print "Use DISPLAY & MENU"
    print " - [ click ANY KEY ] - "
    wait_click
    print "for best & fast results."
    print "Press SHOOT HALF"
    print "to stop recording"
    print "Because of zoom and"
    print " - [ click ANY KEY ] - "
    wait_click
    print "focusing noises"
    print "i suggest record the"
    print "sound with another"
    print "recorder and join with"
    print " - [ click ANY KEY ] - "
    wait_click
    print "nandub for example"
    print "enter 0 in help param"
    print "and play the game :)"
    print " - [ click ANY KEY ] - "
    wait_click
    cls
    return
    « Last Edit: 21 / February / 2008, 18:15:53 by kamil »

    Offline obsidian

    • Rookie
    • *
    • Posts: 31
    • A710IS
    Re: Video zoom and focus script
    « Reply #2 on: 12 / February / 2008, 20:37:43 »
  • Publish
  • A710IS + 4GB SanDisk Ultra II

    Offline kamil

    • Rookie
    • *
    • Posts: 21
    • G7
    Re: Video zoom and focus script
    « Reply #3 on: 14 / February / 2008, 17:28:08 »
  • Publish
  • wow  :)
    it's nice

    good job obsidian  ::)

    You choose a different way of manipulation and it have sense. Very simple and useful is this half_shot zoom step changing. I think you have right, it's not to good using half_shot for stoping. It's working very fast and silent as zoom set changer. I must think about this in next version of my script.

    I suggest You change minimal zoom step from 1 to 2. 1 step is really useless in my opinion.

    Have you allbest #31? He wrote that focusing in zoom script is better. I dont see any improvment in practice. Do you?

    Offline dzsemx

    • Sr. Member
    • ****
    • Posts: 302
    • [SX40HS][A650][A630]
    Re: Video zoom and focus script
    « Reply #4 on: 29 / February / 2008, 02:56:34 »
  • Publish
  • here's my script port for a630(a640), maybe it works on a620 and a610, too.
    i had to restart my camera several times because of "lens errors"  :blink: and ugly noises :'(

    but it looks safe now, before zooming, sets focus to infinite after zoom restores focus... the original firmware does something like this

    for me it works without problems
    tested with allbest's build 37
    i suggest for other script writers to make these focusing operations when zooming

    it's almost like the original one above, but:
    /delete/ button is for focusing at cca 35 cm by default
    /display/- 1X zoom - cca 2,6 meter focus by default
    /menu/-4X zoom - infinite focus by default
    zoom step by default is 4 by default so you can zoom in and out fully in two steps
    /up/-/down/ is for manual focusing
    /left/-/func/-/right/ modifies zoom stepping(2,4,8 by default)

    Code: [Select]
    rem Author kamil, adapted for A630(A640) by dzsemx, script ver. 2.1 or what
    rem some help:
    rem /delete/ button is for focusing at cca 35 cm by default
    rem /display/- 1X zoom - cca 2,6 meter focus by default
    rem /menu/-4X zoom - infinite focus by default
    rem /up/-/down/ is for manual focusing
    rem /left/-/func/-/right/ modifies zoom stepping(2,4,8 by default)
    rem zoom step by default is 4 so you can zoom in or out fully in two steps
    rem every parameter can be modified from the script menu to fit your needs
    @title zoom and focus in video
    @param a auto focus /erase/ 0=off
    @default a 4
    @param c step zoom /left/
    @default c 2
    @param d step zoom /set/ - at start
    @default d 4
    @param e step zoom /right/
    @default e 8
    @param f auto zoom /display/ -1=off
    @default f 0
    @param g auto focus /display/ 0=off
    @default g 7
    @param h auto zoom /menu/ -1=off
    @default h 8
    @param i auto focus /menu/ 0=off
    @default i 11

    get_prop 12 q
    if q=0 then set_prop 12 1

    z=d
    rem used for safe zoom
    x=11

    rem zoom range, change this value if your zoom is different
    k=8

    get_focus u
    o=0

    do
    o=o+1
    p=o*o*(o+1)*(o+1)+90
    until u<p

    v=o

    press "shoot_half"
    sleep 800
    click "shoot_full"
    print "HALF SHOOT - stop record"
    :loop
    wait_click
    if is_key "zoom_in" then goto "in"
    if is_key "zoom_out" then goto "out"
    if is_key "up" then goto "add_focus"
    if is_key "down" then goto "min_focus"
    if is_key "left" then let z=c
    if is_key "set" then let z=d
    if is_key "right" then let z=e
    if is_key "erase" then goto "focus_1"
    if is_key "display" then goto "zoom_focus_1"
    if is_key "menu" then goto "zoom_focus_2"
    if is_key "shoot_half" then goto "end"
    goto "loop"

    :in
    if z<0 then let z=1
    if z>k then let z=k
    gosub "safe_focus"
    set_zoom_rel z
    get_zoom t
    print "zoom", t; "/" k
    gosub "focus_dance"
    goto "loop"

    :out
    if z<0 then let z=1
    if z>k then let z=k
    gosub "safe_focus"
    set_zoom_rel -z
    get_zoom t
    print "zoom", t; "/" k
    gosub "focus_dance"
    goto "loop"

    :focus_1
    v=a
    gosub "focus_dance"
    goto "loop"

    :zoom_focus_1
    if f>-1 then gosub "zoom_zoom_focus_1"
    if g>0 then gosub "focus_zoom_focus_1"
    goto "loop"

    :focus_zoom_focus_1
    v=g
    gosub "focus_dance"
    return

    :zoom_zoom_focus_1
    gosub "safe_focus"
    set_zoom f
    print "zoom", f; "/" k
    return

    :zoom_focus_2
    if h>-1 then gosub "zoom_zoom_focus_2"
    if g>0 then gosub "focus_zoom_focus_2"
    goto "loop"

    :focus_zoom_focus_2
    v=i
    gosub "focus_dance"
    return

    :zoom_zoom_focus_2
    gosub "safe_focus"
    set_zoom h
    print "zoom", h; "/" k
    return

    :add_focus
    v=v+1
    gosub "focus_dance"
    goto "loop"

    :min_focus
    v=v-1
    gosub "focus_dance"
    goto "loop"

    :focus_dance
    u=(v*v*v*v)+90
    if v>=11 then u=65535
    if v<1 then let v=1
    if v>11 then let v=11
    set_focus u
    get_focus t
    print "focus", v; "/11 ("t; " mm)"
    return

    :safe_focus
    x=v
    v=11
    print "Safe focusing"
    gosub "focus_dance"
    v=x
    sleep 10
    return

    :end
    click "shoot_full"
    end

    end

    if i wrote something wrong, excuse me, i'm a little bit sick and tired :'(
    « Last Edit: 29 / February / 2008, 02:59:46 by dzsemx »

    Offline amatos

    • Rookie
    • *
    • Posts: 28
      • My Blog
    Re: Video zoom and focus script
    « Reply #5 on: 03 / March / 2008, 10:39:57 »
  • Publish
  • thanks for the script to both of you, obsidian's worked on my A720 like a charm :D
    --
    Alejandro

    Offline yunxiang

    • Rookie
    • *
    • Posts: 23
    Re: Video zoom and focus script
    « Reply #6 on: 25 / March / 2008, 21:05:46 »
  • Publish
  • thanks for the script!!!!!!!!!!!!!!!!!!!

    now the  new allbest have the ablility to     
    Video zoom , but the focus can not change

    we need a auto focus script

    Offline amatos

    • Rookie
    • *
    • Posts: 28
      • My Blog
    Re: Video zoom and focus script
    « Reply #7 on: 27 / March / 2008, 06:17:22 »
  • Publish
  • but the focus can not change
    Yes you can, or at least you can using an A720...
    --
    Alejandro

    Offline yunxiang

    • Rookie
    • *
    • Posts: 23
    Re: Video zoom and focus script
    « Reply #8 on: 27 / March / 2008, 21:06:00 »
  • Publish
  • now the new allbest have the ablility to     
    Video zoom , but the focus can not change during the taking the video without the scrips
    « Last Edit: 28 / March / 2008, 06:26:14 by yunxiang »

    CHDK Forum

    Re: Video zoom and focus script
    « Reply #8 on: 27 / March / 2008, 21:06:00 »

    Offline kamil

    • Rookie
    • *
    • Posts: 21
    • G7
    Re: Video zoom and focus script
    « Reply #9 on: 27 / March / 2008, 23:55:35 »
  • Publish
  • Yes i know, guys makes a good work :) . But there is a small bug on my camera. I can't escape from digital zoom and make an optical zoom. Maybe in the future it will be corrected. BTW my script is useless in a big part. So i must correct it.

    Offline awake

    • Newbie
    • *
    • Posts: 3
    Re: Video zoom and focus script
    « Reply #10 on: 28 / December / 2008, 20:41:04 »
  • Publish
  • but, why with enabled CHDK, video very poor ? I use G9.

    Offline amatos

    • Rookie
    • *
    • Posts: 28
      • My Blog
    Re: Video zoom and focus script
    « Reply #11 on: 28 / December / 2008, 20:45:26 »
  • Publish
  • video quality is the same (A720)
    --
    Alejandro

    Offline c2thew

    • Rookie
    • *
    • Posts: 29
    Re: Video zoom and focus script
    « Reply #12 on: 31 / December / 2008, 05:36:08 »
  • Publish
  • so your problem is fixed correct?  the sunset4.bas works for me.

     


    SimplePortal 2.3.3 © 2008-2010, SimplePortal