Check-in [36b5f24ce8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Working example and correction to _setAttribute logic (fix for [ff08074318]).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | Release_0.5.3
Files: files | file ages | folders
SHA3-256:36b5f24ce8cb834cd6933a7d31008f20b9be50e931fb6fb3c28bbe87f76016bc
User & Date: gwlester 2018-02-05 21:09:03
Original Comment: Working example and correction to _setAttribute logic.
Context
2018-02-06
02:47
Initial cut of documentation. check-in: 86310cbcdc user: gwlester tags: trunk
2018-02-05
21:09
Working example and correction to _setAttribute logic (fix for [ff08074318]). check-in: 36b5f24ce8 user: gwlester tags: trunk, Release_0.5.3
05:26
Reimplement _attributes. Start example. check-in: 7dbfdf9c42 user: gwlester tags: trunk
Changes

Changes to examples/pistill.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
65
66
67
68
69
70
71
72



















73
74
75
76



77




















78
79
80
81
82









83
84
85
86
87
88
89
90
91
92
93
94
95
96



97

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}

##
## Emit help message and exit
##
proc EmitHelp {} {
    puts stderr {

Runs camera for specific time, and take JPG capture at end if requested

usage: pistill.tcl [options] outputFileName

Image parameter commands:
    -?, --help	: This help information
    -w, --width	: Set image width <size>
    -h, --height	: Set image height <size>
    -q, --quality	: Set jpeg quality <0 to 100>
    -r, --raw	: Add raw bayer data to jpeg metadata
    -t, --timeout	: Time (in ms) before takes picture and shuts down (if not specified, set to 5s)
    -th, --thumb	: Set thumbnail parameters (x:y:quality) or none
    -e, --encoding	: Encoding to use for output file (jpg, bmp, gif, png)
    -x, --exif	: EXIF tag to apply to captures (format as 'key=value') or none
    -md, --mode	: Force sensor mode. 0=auto. See docs for other modes available
    -sh, --sharpness	: Set image sharpness (-100 to 100)
    -co, --contrast	: Set image contrast (-100 to 100)
    -br, --brightness	: Set image brightness (0 to 100)
    -sa, --saturation	: Set image saturation (-100 to 100)
    -ISO, --ISO	: Set capture ISO
    -vs, --vstab	: Turn on video stabilisation
    -ev, --ev	: Set EV compensation - steps of 1/6 stop
    -ex, --exposure	: Set exposure mode (see below)
    -fli, --flicker	: Set flicker avoid mode (see below)
    -awb, --awb	: Set AWB mode (see Notes)
    -ifx, --imxfx	: Set image effect (see below)
    -cfx, --colfx	: Set colour effect (U:V)
    -mm, --metering	: Set metering mode (see below)
    -rot, --rotation	: Set image rotation (0-359)
    -hf, --hflip	: Set horizontal flip
    -vf, --vflip	: Set vertical flip
    -roi, --roi	: Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
    -ss, --shutter	: Set shutter speed in microseconds
    -awbg, --awbgains	: Set AWB gains - AWB mode must be off
    -drc, --drc	: Set DRC Level (see below)
    -st, --stats	: Force recomputation of statistics on stills capture pass
    -ag, --analoggain	: Set the analog gain (floating point)
    -dg, --digitalgain	: Set the digtial gain (floating point)

Exposure mode options :
    off, auto, night, nightpreview, backlight, spotlight, sports, snow, beach,
    verylong, fixedfps, antishake or fireworks

Flicker avoid mode options :
    off, auto, 50hz or 60hz
................................................................................

Metering Mode options :
    average, spot, backlit or matrix

Dynamic Range Compression (DRC) options :
    off, low, med or high

    }



















    exit 1
}

proc ProcessOptions {argList} {
























}

package require pyman
pyman import -namespace ::picamera picamera










switch -exact $argc {
    0 {
        EmitHelp
    }
    1 {
        set ofn [lindex $argv 0]
    }
    default {
        set ofn [lindex $argv end]
        ProcessOptions [lrnage $argv 0 end-1]
    }
}

set camera [::picamera::PiCamera new]



$camera capture $ofn





|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>
|








|



|
>
>
>

>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40








41
42
43
44
45
46
47
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}

set OptionDef {
    -?, --help | EmitHelp | This help information
    -r, --raw | $camera _setAttribute raw_format %1$s | Add raw bayer data to jpeg metadata (see below)
    -t, --timeout | after %1$s | Time (in ms) before takes picture and shuts down (if not specified, set to 5s)
    -x, --exif | $camera _setAttribute exif_tags %1$s | EXIF tag to apply to captures (format as 'key value' list)
    -md, --mode | $camera _setAttribute sensor_mode %1$s | Force sensor mode. 0=auto. See docs for other modes available
    -sh, --sharpness | $camera _setAttribute sharpness %1$s | Set image sharpness (-100 to 100)
    -co, --contrast | $camera _setAttribute contrast %1$s | Set image contrast (-100 to 100)
    -br, --brightness | $camera _setAttribute brightness %1$s | Set image brightness (0 to 100)
    -sa, --saturation | $camera _setAttribute saturation %1$s | Set image saturation (-100 to 100)
    -ISO, --ISO | $camera _setAttribute iso %1$s | Set capture ISO
    -ev, --ev | $camera _setAttribute exposure_compensation %1$s | Set EV compensation - steps of 1/6 stop
    -ex, --exposure | $camera _setAttribute exposure_mode %1$s | Set exposure mode (see below)
    -awb, --awb | $camera _setAttribute awb_mode %1$s | Set AWB mode (see below)
    -ifx, --imxfx | $camera _setAttribute image_effect %1$s  | Set image effect (see below)
    -cfx, --colfx | $camera _setAttribute color_effects %1$s | Set colour effect (U:V)
    -mm, --metering | $camera _setAttribute meter_mode %1$s | Set metering mode (see below)
    -rot, --rotation | $camera _setAttribute rotation %1$s | Set image rotation (0-359)
    -hf, --hflip | $camera _setAttribute hflip  [expr {%1$s?1:0}] | Set horizontal flip (boolean)
    -vf, --vflip | $camera _setAttribute vflip [expr {%1$s?1:0}] | Set vertical flip (boolean)
    -roi, --roi | $camera _setAttribute crop %1$s | Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
    -ss, --shutter | $camera _setAttribute shutter_speed %1$s | Set shutter speed in microseconds
    -awbg, --awbgains | $camera _setAttribute awb_gains %1$s | Set AWB gains - AWB mode must be off
    -drc, --drc | $camera _setAttribute drc_strength [%1$s | Set DRC Level (see below)
    -st, --stats | $camera _setAttribute still_stats [expr {%1$s?1:0}] | Force recomputation of statistics on stills capture pass (boolean)
    -dg, --digitalgain | $camera _setAttribute digital_gain %1$s | Set the digtial gain (floating point)
}

set HelpFmt {

Runs camera for specific time, and take JPG capture at end if requested

usage: pistill.tcl [options] outputFileName

Image parameter commands:
%1$s









Exposure mode options :
    off, auto, night, nightpreview, backlight, spotlight, sports, snow, beach,
    verylong, fixedfps, antishake or fireworks

Flicker avoid mode options :
    off, auto, 50hz or 60hz
................................................................................

Metering Mode options :
    average, spot, backlit or matrix

Dynamic Range Compression (DRC) options :
    off, low, med or high

}

##
## Emit help message and exit
##
proc EmitHelp {} {
    global HelpFmt
    global OptionDef

    set paramSection {}
    foreach paramDef [split $OptionDef "\n"] {
        set paramList [split $paramDef "|"]
        if {[llength $paramList] ne 3} {
            continue
        }
        lassign $paramList options command description
        append paramSection [format {%25.25s} [string trim $options]] "\t: " $description "\n"
    }

    puts stderr [format $HelpFmt $paramSection]
    exit 1
}

proc ProcessOptions {argList} {
    global OptionDef
    global SymbolicDict
    global camera

    set optionDict {}

    foreach paramDef [split $OptionDef "\n"] {
        set paramList [split $paramDef "|"]
        if {[llength $paramList] ne 3} {
            continue
        }
        lassign $paramList options command description
        set command [string trim $command]
        foreach option [split $options ","] {
            dict set optionDict [string trim $option] $command
        }
    }
    foreach {option value} $argList {
        if {![dict exists $optionDict $option]} {
            puts stderr "unkown option: $option"
            EmitHelp
        }
        eval [format [dict get $optionDict $option] $value]
    }
}

package require pyman
pyman import -namespace ::picamera picamera

set camera [::picamera::PiCamera new]

##
## Get the numerics for symbolics
##
foreach symbolSet {AWB_MODES CLOCK_MODES DRC_STRENGTHS EXPOSURE_MODES FLASH_MODES IMAGE_EFFECTS METER_MODES STEREO_MODES} {
    set SymbolicDict($symbolSet) [$camera _getAttribute $symbolSet]
}

switch -exact -- $argc {
    0 {
        EmitHelp
    }
    1 {
        set ofn [lindex $argv 0]
    }
    default {
        set ofn [lindex $argv end]
        ProcessOptions [lrange $argv 0 end-1]
    }
}

if {$ofn in {"-?" "--help"}} {
    EmitHelp
}

$camera capture $ofn
$camera close

Changes to src/pyman.tcl.

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
                            }
                            switch -exact [dict get $Attributes type $attribute] {
                                constant {
                                    throw [list PYMAN SETCONST $attribute] "can not set constant attribute '$attribute'"
                                }
                                property {
                                    set pymanSetAttrFmt {def pymanSetAttr(newValue):}
                                    append pymanSetAttrFmt "\n\t" {globals()%1$s.%2$s = newValue}
                                    py eval [format $pymanSetAttrFmt $pythonObject $attribute]
                                    py call pymanSetAttr $value
                                }
                            }
                        }
                    }
                    
                    ##
                    ## Get attributes and their defaults
                    ##
                    py eval [format $pymanGetAttributesFmt $moduleName $name]
                    set attrList [py call pymanGetAttributes]
                    $className init $attrList








|






|







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
                            }
                            switch -exact [dict get $Attributes type $attribute] {
                                constant {
                                    throw [list PYMAN SETCONST $attribute] "can not set constant attribute '$attribute'"
                                }
                                property {
                                    set pymanSetAttrFmt {def pymanSetAttr(newValue):}
                                    append pymanSetAttrFmt "\n\t" {%1$s.%2$s = newValue}
                                    py eval [format $pymanSetAttrFmt $pythonObject $attribute]
                                    py call pymanSetAttr $value
                                }
                            }
                        }
                    }

                    ##
                    ## Get attributes and their defaults
                    ##
                    py eval [format $pymanGetAttributesFmt $moduleName $name]
                    set attrList [py call pymanGetAttributes]
                    $className init $attrList