Check-in [46906b74b4]
Not logged in

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

Overview
Comment:improve topcua webcam example
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 46906b74b403b4bf8ec3071a3b4292e138d5e50a
User & Date: chw 2019-05-25 08:41:38
Context
2019-05-25
16:34
add selected SDL2 upstream changes check-in: c0bc624ec8 user: chw tags: trunk
08:41
improve topcua webcam example check-in: 46906b74b4 user: chw tags: trunk
03:43
add tk upstream changes check-in: a6dff1b79a user: chw tags: trunk
Changes

Changes to jni/topcua/examples/uacam.tcl.

2
3
4
5
6
7
8

9
10
11
12
13
14
15
..
36
37
38
39
40
41
42

43









44
45
46
47
48
49
50
..
99
100
101
102
103
104
105



106
107
108
109
110
111
#
# Requires Linux, MacOSX, or FreeBSD, due to tcluvc support,
# but can be easily modified for Windows to use tclwmf instead.

package require Tk
package require topcua
package require tcluvc


# hide Tk toplevel
wm withdraw .

# get first available camera
set cam [lindex [uvc devices] 0]
if {$cam eq {}} {
................................................................................

# image capture callback
proc capture {cam} {
    # limit frame rate, otherwise it consumes too much CPU for
    # image processing and the OPC/UA server part starves
    lassign [uvc counters $cam] all done dropped
    if {$all % 20 == 0} {

	uvc image $cam $::img









	set ::png [$::img data -format png]
    }
}

# create OPC/UA server
opcua new server 4840 S

................................................................................

# create variable in our folder to return last photo image
set att [opcua attrs default VariableAttributes]
dict set att dataType $IT	;# Image data type
dict set att valueRank -1	;# 1-dimensional array
opcua add S Variable "ns=$ns;s=Image" $obj HasComponent "$ns:Image" {} $att \
    ::opcua::S::_lastimg




# start server using Tk's event loop
opcua start S

# start camera
uvc start $cam 







>







 







>

>
>
>
>
>
>
>
>
>







 







>
>
>





|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#
# Requires Linux, MacOSX, or FreeBSD, due to tcluvc support,
# but can be easily modified for Windows to use tclwmf instead.

package require Tk
package require topcua
package require tcluvc
package require tkpath

# hide Tk toplevel
wm withdraw .

# get first available camera
set cam [lindex [uvc devices] 0]
if {$cam eq {}} {
................................................................................

# image capture callback
proc capture {cam} {
    # limit frame rate, otherwise it consumes too much CPU for
    # image processing and the OPC/UA server part starves
    lassign [uvc counters $cam] all done dropped
    if {$all % 20 == 0} {
	set ts [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]
	uvc image $cam $::img
	set surf [::tkp::surface new 320 240]
	$surf create pimage 0 0 -image $::img
	$surf create ptext 160 225 -text $ts -textanchor c \
	    -fontfamily Courier -fontweight bold -fontsize 22 \
	    -stroke white -strokewidth 1 -strokeopacity 0.6 \
	    -fill black -fillopacity 0.3
	$::img configure -width 320 -height 240
	$surf copy $::img
	$surf destroy
	set ::png [$::img data -format png]
    }
}

# create OPC/UA server
opcua new server 4840 S

................................................................................

# create variable in our folder to return last photo image
set att [opcua attrs default VariableAttributes]
dict set att dataType $IT	;# Image data type
dict set att valueRank -1	;# 1-dimensional array
opcua add S Variable "ns=$ns;s=Image" $obj HasComponent "$ns:Image" {} $att \
    ::opcua::S::_lastimg

# start with empty image data
set png {}

# start server using Tk's event loop
opcua start S

# start camera
uvc start $cam