Skip to content

Commit

Permalink
feat: New Confidence settings for Privacy filter and Dog Bark Filter,…
Browse files Browse the repository at this point in the history
… also add remeber time limit setting for Dog Bark filter
  • Loading branch information
tphakala committed Jun 1, 2024
1 parent 15f6d48 commit 42fc858
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
2 changes: 1 addition & 1 deletion internal/analysis/processor/dogbarkfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Assuming a predefined time limit for filtering detections after a dog bark.
const DogBarkFilterTimeLimit = 15 * time.Minute
var DogBarkFilterTimeLimit = time.Duration(conf.Setting().Realtime.DogBarkFilter.Remember) * time.Minute

// DogBarkFilter contains a list of species to be filtered within the time limit after a dog bark.
type DogBarkFilter struct {
Expand Down
16 changes: 11 additions & 5 deletions internal/analysis/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,21 @@ func (p *Processor) processResults(item *queue.Results) []Detections {
speciesLowercase := strings.ToLower(commonName)

// Dog detection handling
if strings.Contains(speciesLowercase, "dog") && result.Confidence > 0.1 {
if strings.Contains(speciesLowercase, "dog") && result.Confidence > p.Settings.Realtime.DogBarkFilter.Confidence {
log.Printf("Dog detected, updating last detection timestamp for potential owl false positives")
p.LastDogDetection = time.Now()
}

// Human detection handling for privacy filter
if p.Settings.Realtime.PrivacyFilter.Enabled {
if strings.Contains(speciesLowercase, "human") && result.Confidence > 0.05 {
// if debug is enabled print results
if p.Settings.Realtime.PrivacyFilter.Debug {
log.Printf("[Privacy filter] species: %s, confidence: %.2f\n", speciesLowercase, result.Confidence)
}
if strings.Contains(speciesLowercase, "human") && result.Confidence > p.Settings.Realtime.PrivacyFilter.Confidence {
log.Printf("Human detected, updating last detection timestamp for privacy filtering")
// now minus 2 seconds
p.LastHumanDetection = time.Now().Add(-3 * time.Second)
// now minus 4 seconds
p.LastHumanDetection = time.Now().Add(-4 * time.Second)
}
}

Expand Down Expand Up @@ -312,7 +316,9 @@ func (p *Processor) pendingDetectionsFlusher() {

// Check dog bark filter
if p.Settings.Realtime.DogBarkFilter.Enabled {
log.Printf("Last dog detection: %s\n", p.LastDogDetection)
if p.Settings.Realtime.DogBarkFilter.Debug {
log.Printf("Last dog detection: %s\n", p.LastDogDetection)
}
// Check against common name
if p.DogBarkFilter.Check(item.Detection.Note.CommonName, p.LastDogDetection) {
log.Printf("Discarding detection of %s due to recent dog bark\n", item.Detection.Note.CommonName)
Expand Down
9 changes: 7 additions & 2 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ type Settings struct {
}

PrivacyFilter struct {
Enabled bool // true to enable privacy filter
Debug bool // true to enable debug mode
Enabled bool // true to enable privacy filter
Confidence float32 // confidence threshold for human detection
}

DogBarkFilter struct {
Enabled bool // true to enable dog bark filter
Debug bool // true to enable debug mode
Enabled bool // true to enable dog bark filter
Confidence float32 // confidence threshold for dog bark detection
Remember int // how long we should remember bark for filtering?
}

RTSP struct {
Expand Down
67 changes: 34 additions & 33 deletions internal/conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ birdnet:

# Realtime processing settings
realtime:
interval: 15 # duplicate prediction interval in seconds
processingtime: false # true to report processing time for each prediction
interval: 15 # duplicate prediction interval in seconds
processingtime: false # true to report processing time for each prediction

audio:
source: "sysdefault" # audio source to use for analysis
Expand All @@ -43,8 +43,8 @@ realtime:
minclips: 10 # minumum number of clips per species to keep before starting evictions

log:
enabled: false # true to enable OBS chat log
path: birdnet.txt # path to OBS chat log
enabled: false # true to enable OBS chat log
path: birdnet.txt # path to OBS chat log

birdweather:
enabled: false # true to enable birdweather uploads
Expand All @@ -53,54 +53,55 @@ realtime:
id: 00000 # birdweather ID

rtsp:
url: # RTSP stream URL
transport: tcp # RTSP Transport Protocol
url: # RTSP stream URL
transport: tcp # RTSP Transport Protocol

mqtt:
enabled: false # true to enable MQTT
enabled: false # true to enable MQTT
broker: tcp://localhost:1883 # MQTT (tcp://host:port)
topic: birdnet # MQTT topic
username: birdnet # MQTT username
password: secret # MQTT password
topic: birdnet # MQTT topic
username: birdnet # MQTT username
password: secret # MQTT password

privacyfilter: # Privacy filter prevents audio clip saving if human voice
enabled: true # is detected durin audio capture
privacyfilter: # Privacy filter prevents audio clip saving if human voice
enabled: true # is detected durin audio capture
threshold: 0.05 # threshold for human voice detection

dogbarkfilter:
enabled: true
condidence: 0.1 # confidence threshold for dog bark detection
remember: 5 # number of minutes to remember dog barks

telemetry:
enabled: false # true to enable Prometheus compatible telemetry endpoint
listen: "0.0.0.0:8090" # IP address and port to listen on



webserver:
enabled: true # true to enable web server
port: 8080 # port for web server
autotls: false # true to enable auto TLS
enabled: true # true to enable web server
port: 8080 # port for web server
autotls: false # true to enable auto TLS
log:
enabled: true # true to enable log file
path: webui.log # path to log file
rotation: daily # daily, weekly or size
maxsize: 1048576 # max size in bytes for size rotation
rotationday: 0 # day of the week for weekly rotation, 0 = Sunday
enabled: false # true to enable log file
path: webui.log # path to log file
rotation: daily # daily, weekly or size
maxsize: 1048576 # max size in bytes for size rotation
rotationday: 0 # day of the week for weekly rotation, 0 = Sunday

# Ouput settings
output:
file:
enabled: true # true to enable file output for file and directory analysis
path: output/ # path to output directory
type: table # ouput format, Raven table or csv
enabled: true # true to enable file output for file and directory analysis
path: output/ # path to output directory
type: table # ouput format, Raven table or csv
# Only one database is supported at a time
# if both are enabled, SQLite will be used.
sqlite:
enabled: true # true to enable sqlite output
path: birdnet.db # path to sqlite database
enabled: true # true to enable sqlite output
path: birdnet.db # path to sqlite database
mysql:
enabled: false # true to enable mysql output
username: birdnet # mysql database username
password: secret # mysql database user password
database: birdnet # mysql database name
host: localhost # mysql database host
port: 3306 # mysql database port
enabled: false # true to enable mysql output
username: birdnet # mysql database username
password: secret # mysql database user password
database: birdnet # mysql database name
host: localhost # mysql database host
port: 3306 # mysql database port
7 changes: 6 additions & 1 deletion internal/conf/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ func setDefaultConfig() {
viper.SetDefault("realtime.mqtt.password", "secret")

viper.SetDefault("realtime.privacyfilter.enabled", true)
viper.SetDefault("realtime.privacyfilter.debug", false)
viper.SetDefault("realtime.privacyfilter.threshold", 0.05)

viper.SetDefault("realtime.dogbarkfilter.enabled", false)
viper.SetDefault("realtime.dogbarkfilter.debug", false)
viper.SetDefault("realtime.dogbarkfilter.remember", 5)

viper.SetDefault("realtime.telemetry.enabled", false)
viper.SetDefault("realtime.telemetry.listen", "0.0.0.0:8090")
Expand All @@ -73,7 +78,7 @@ func setDefaultConfig() {
viper.SetDefault("webserver.port", "8080")
viper.SetDefault("webserver.autotls", false)

viper.SetDefault("webserver.log.enabled", true)
viper.SetDefault("webserver.log.enabled", false)
viper.SetDefault("webserver.log.path", "webui.log")
viper.SetDefault("webserver.log.rotation", RotationDaily)
viper.SetDefault("webserver.log.maxsize", 1048576)
Expand Down

0 comments on commit 42fc858

Please sign in to comment.