Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds filtering of partial matches to classifications/detections #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,25 @@ You can say either classify an image and only sync some, or look for object in a

https://app.viam.com/module/erh/filtered-camera

### Example Config

```
"name": "filter",
"model": "erh:camera:filtered-camera",
"type": "camera",
"namespace": "rdk",
"attributes" : {
"camera": "my-cam",
"vision": "my-vision-service",
"classifications": {
"COUNTDOWN*": 0.6,
"ALARM": 0.5
},
"detections": {
"*": 0.85
}
}
```
For example, this config would save all images with a classification label that exactly matched "ALARM" with greater than 0.5 confidence, or partially matched "COUNTDOWN", e.g. "COUNTDOWN: 10 s remain!" with greater than 0.6 confidence. It would also save all images that had any detection with a confidence above 0.85.


25 changes: 24 additions & 1 deletion cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"image"
"sort"
"strings"
"regexp"
"sync"
"time"

Expand Down Expand Up @@ -53,6 +55,17 @@ func (cfg *Config) keepClassification(c classification.Classification) bool {
if has && c.Score() > min {
return true
}
// check for substring match
for key, _ := range cfg.Classifications {
if strings.Contains(key, "*") {
if match, err := regexp.MatchString(key, c.Label()); match {
if err != nil {
continue
}
return true
}
}
}

return false
}
Expand All @@ -77,7 +90,17 @@ func (cfg *Config) keepObject(d objectdetection.Detection) bool {
if has && d.Score() > min {
return true
}

// check for substring match
for key, _ := range cfg.Objects {
if strings.Contains(key, "*") {
if match, err := regexp.MatchString(key, d.Label()); match {
if err != nil {
continue
}
return true
}
}
}
return false
}

Expand Down