-
Notifications
You must be signed in to change notification settings - Fork 28
/
events.scm
75 lines (54 loc) · 2.04 KB
/
events.scm
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;; File: events.scm
;; ;; Author: Eskender Besrat <[email protected]>
;; License: AGPL
;; Date: May, 2018
;;; -------------------------------------------------
;;; This file contains all events and their callbacks
;;; -------------------------------------------------
;; --------------------------------------------------
;; Create events
; Face detection event
(define-public event-face (psi-create-monitored-event "face-detected?"))
; Smile detection event
(define-public event-smile (psi-create-monitored-event "smile-detected?"))
; Saliency detection event
(define-public event-saliency (psi-create-monitored-event "saliency?"))
;; ----------------------------------------------------
;; Create event monitoring functions
;; Currently the functions check global variables updated from C++ detectors
;; FIXME: Need to query the atomspace instead
; Monitor face detection in 10 sec interval (for the time being)
(define face-last (current-time))
(define-public (monitor-face-detection)
(if (and (defined? 'global-face) (< (- (current-time) (hash-ref global-face 'update-time)) 3)
(> (- (current-time) face-last) 5))
(begin
;(display "face detected in monitor")
(psi-set-event-occurrence! event-face)
(set! face-last (current-time))
)
)
)
; Monitor smile
;(define-public (monitor-smile-detection)
; (if (and (defined? 'global-smile) (< (- (current-time) (hash-ref global-smile 'update-time)) 3))
; (psi-set-event-occurrence! event-smile)
;
; )
;)
; Monitor saliency
;(define salient-last (current-time))
;(define-public (monitor-saliency)
; (if (and (defined? 'global-salient) (< (- (current-time) (hash-ref global-salient 'update-time)) 5)
; (> (- (current-time) salient-last) 10))
; (begin
; (psi-set-event-occurrence! event-saliency)
; (set! salient-last (current-time))
; )
; )
;)
;; ----------------------------------------------------
;; Register the monitoring functions here
(psi-set-event-callback! monitor-face-detection)
;(psi-set-event-callback! monitor-smile-detection)
;(psi-set-event-callback! monitor-saliency)