@title ArchDoco 081119 V=81119 rem rem ArchDoco - Document Archival Motion Detection Script rem rem Author: ArchDoco@Seanster.com rem Website: http://www.seanster.com/archdoco rem rem This script automatically waits for you remove the old document, rem place the new document, and then photographs it. rem No interaction with the camera is required. rem All settings are adjustable as script parameters. rem rem These default settings correspond to my particular physical setup. rem It takes me about 1-2 seconds to remove the page and center the new page. rem The camera waits until it has seen 2 contiguous motions (Actions) rem in a minimum of 1.5 seconds (ActionWindow). rem Actions are checked at intervals of 350 msecs (ActionRez). rem rem Note: The script doesn't run during saving & photo review. rem Be sure to disable or set the standard option for photo review accordingly, rem rem I stop all motion for 2.0 seconds (IdleTimeout) and the camera takes the photo. rem The process repeats, waiting for a new page. rem rem *Shooting is disabled in debug modes above 1* rem You can easily change "if t<2 then shoot" at end of script. rem LogMode parameter is just an argument to the "print_screen" call. See \CHDK\LOGS rem rem By using the "shoot" command I allow the camera to autofocus for every photo. rem This takes some extra time and could be avoided. rem 1. You could set your camera to manual mode and run the script normally? rem 2. You could modify the script to half-press the shutter at the start of the script rem and from then on to take photos press full shutter and release back to half shutter. rem (I bet this uses a ton of battery power) rem 3. Use the remote cable and forget scripts. http://chdk.wikia.com/wiki/USB_Remote_Cable rem 4. You could just not care and use the script as-is, like me :) rem rem *I built this script from: rem *Fudgey's Fast/Slow/Video Motion Detector with masks. rem *See MDFB-080914.txt for documentation. rem *Trunk autobuild 509 or higher (or compatible) required. rem rem doco culled from http://chdk.wikia.com/wiki/UBASIC/TutorialScratchpad rem rem md_detect_motion a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p rem rem a COLUMNS to split picture into rem b ROWS to split picture into rem c MEASURE MODE (Y,U,V R,G,B) - U=0, Y=1, V=2, R=3, G=4, B=5 rem d TIMEOUT rem e COMPARISON INTERVAL (msec) rem f THRESHOLD ( difference in cell to trigger detection) rem g DRAW GRID (0-no, 1-yes) rem h RETURN VARIABLE number of cells with motion detected rem rem OPTIONAL PARAMETERS: rem rem i REGION (masking) mode: 0-no regions, 1-include,2-exclude rem j REGION FIRST COLUMN rem k REGION FIRST ROW rem l REGION LAST COLUM rem m REGION LAST ROW rem rem n PARAMETERS: rem 1-make immediate shoot, rem 2-log debug information into file, rem 4-dump liveview image from RAM to a file, rem 8-on immediate shoot, don't release shutter. rem OR-ed values are accepted, e.g. use 9 for immediate shoot & don't release shutter rem rem o PIXELS STEP - Speed vs. Accuracy adjustments (1-use every pixel,2-use every second pixel, etc) rem p MILLISECONDS DELAY to begin triggering - can be useful for calibration with DRAW-GRID option. rem @param a Columns @default a 4 @param b Rows @default b 4 @param c MeasMode (0U,1Y,2V,3R,4G,5B) @default c 1 rem d - the minimum period of non-motion indicating a new page has been placed (3 secs) rem lower = more false photos ; higher = increased cycle time and growing impatience @param d IdleTimeout (msec) @default d 2000 @param e CompIntvl (msec) @default e 50 @param f Threshold (0-255) @default f 8 @param g ShowGrid (1/0) @default g 0 rem h RETURN VARIABLE number of cells with motion detected rem Masking: the column numbering appears to be '1' based rem I can't make sense of its use in Fudgey's script so it probably doesn't work. rem I'd need to see the source code for md_detect_motion (or use trial and error :) @param i Masking (0=None 1=Inclusive 2=Exclusive) @default i 0 @param j LCol (Mask Left Col) @default j 0 @param k TRow (Mask Top Row) @default k 0 @param l RCol (Mask Right Col) @default l 0 @param m BRow (Mask Bottom Row) @default m 0 @param n BitParams (1Shoot,2Log,4Dump,8KeepHalfShutter) @default n 0 @param o PixelStep (pixels) (speed vs accuracy) @default o 8 @param p TriggerDelay (msec) @default p 25 rem To believe that the old page was removed and a new page has been placed: rem q & r & s - We must have (s) contiguous motion activations in a minimum span of (r) msecs rem with said motion activations every (q) msecs minimum @param q ActionRez (msec) @default q 350 @param r ActionWindow (msec) @default r 1500 @param s Actions (0 to x) @default s 2 @param t DebugMode (0-None,1-Info,2-Verbose,3-Kathy) @default t 1 @param u LogMode (0 Off,1,2+) @default u 0 if u<0 then u=0 print_screen u if t<0 then t=0 if t>3 then t=3 if t>0 then print "ArchDoco", V rem if t=0 then print "DebugMode: Silent" if t=1 then print "DebugMode: Info" if t=2 then print "DebugMode: Verbose" if t=3 then print "DebugMode: Kathy" if a<1 then a=1 if t>1 then print "Columns:", a if b<1 then b=1 if t>1 then print "Rows:", b if c<0 then c=1 if c>5 then c=1 if t>1 and c=0 then print "MeasMode: U chroma" if t>1 and c=1 then print "MeasMode: Luminance" if t>1 and c=2 then print "MeasMode: V chroma" if t>1 and c=3 then print "MeasMode: Red" if t>1 and c=4 then print "MeasMode: Green" if t>1 and c=5 then print "MeasMode: Blue" if d<0 then d=3000 if t>1 then print "IdleTimeout:", d if e<0 then e=0 if t>1 then print "CompIntvl:", e if f<0 then f=0 if t>1 then print "Threshold:", f if g<0 then g=0 if g>1 then g=0 if t>1 and g=0 then print "Grid: On" if t>1 and g=1 then print "Grid: Off" if i<0 then i=0 if i>2 then i=0 if t>1 and i=0 then print "Masking: None" if t>1 and i=1 then print "Masking: Inclusive" if t>1 and i=2 then print "Masking: Exclusive" if j<0 then j=0 if j>a then j=a if t>1 then print "LCol:", j if k<0 then k=0 if k>b then k=b if t>1 then print "TRow:", k if l<0 then l=0 if l>a then l=a if t>1 then print "RCol:", l if m<0 then m=0 if m>b then m=b if t>1 then print "BRow:", m if n<0 then n=0 if t>1 then print "BitParams:", n if o<1 then o=1 if t>1 then print "PixelStep:", o if p<0 then p=0 if t>1 then print "TriggerDelay:", p if q<1 then q=1 if t>1 then print "ActionRez:", q if r<1 then r=1 if t>1 then print "ActionWindow:", r if s<0 then s=0 if t>1 then print "Actions:", s P=get_video_button if P=1 then goto "VideoButtonError" P=get_mode if P=1 then goto "PlayModeError" rem get_mode returns 2 if a we are in video mode (and the camera has no video button) rem if P=2 then p=1 else p=0 P=get_flash_mode if P=2 then goto "SkipFlashWarning" print "WARNING: Flash is not" print "disabled. May cause " print "odd behavior. " :SkipFlashWarning goto "archdoco" :PlayModeError print "Script ERROR:" print "Not in REC mode, exiting." end :VideoButtonError print "Script ERROR:" print "Incompatible camera!" print "See MDFB VideoButtonModels" end :archdoco if t>0 then print "ArchDoco", V rem detect page change by counting (v>=s contiguous events) in minimum (w>=r msecs) :wait_page if t>0 then print "Waiting for Page Change" x=0 v=0 w=0 X=get_tick_count Y=X do h=0 if t>2 then print "wait_page:", v, s, w, r rem if last event was less than q msecs ago, sleep for the remainder of q rem (we aren't concerned about motions less than q msecs apart) if x>0 and x0 then v=v+1 rem determine time elapsed since last event or start of loop if h>0 then x=q-(Z-Y) rem record the time of this event if h>0 then Y=Z until v>=s and w>=r rem page has changed, now wait for idle period if t>0 then print "Waiting for Idle" :wait_idle do h=0 md_detect_motion a, b, c, d, e, f, g, h, i, j+1, k+1, l+1, m+1, n, o, p if t>2 then print "wait_idle:", h until h=0 rem we have our 3 seconds of idle time, take the photo! if t>0 then print "Shooting!" if t<2 then shoot rem loop back to waiting for the page to be changed goto "wait_page"