From 6e2a4d9247554544e26b66fe3d042349202d4f28 Mon Sep 17 00:00:00 2001 From: Nikolay Dimitrov Date: Fri, 6 Dec 2024 11:31:05 +0900 Subject: [PATCH] Add FACE_DETECT boolean environment variable --- README.md | 1 + config/config.go | 2 ++ faces/faces.go | 4 ++++ processing/detectfaces.go | 3 +++ 4 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 07d1d75..5590350 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Current configuration environment variables: - `DEFAULT_BUCKET_DIR` - a directory that will be used as default bucket if no other buckets exist (i.e. the first time you run the server) - `DEFAULT_ASSET_PATH_PATTERN` - the default path pattern to create subdirectories and file names based on asset info. Defaults to `//` - `PUSH_SERVER` - the push server URL. Defaults to `https://push.circled.me` +- `FACE_DETECT` - enable/disable face detection. Defaults to `yes` - `FACE_DETECT_CNN` - use Convolutional Neural Network for face detection (as opposed to HOG). Much slower, but more accurate at different angles. Defaults to `no` - `FACE_MAX_DISTANCE_SQ` - squared distance between faces to consider them similar. Defaults to `0.11` diff --git a/config/config.go b/config/config.go index 2ca0992..53298ef 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ var ( TMP_DIR = "/tmp" // Used for temporary video conversion, etc (in case of S3 bucket) DEFAULT_BUCKET_DIR = "" // Used for creating initial bucket DEBUG_MODE = true + FACE_DETECT = true // Enable/disable face detection FACE_DETECT_CNN = false // Use Convolutional Neural Network for face detection (as opposed to HOG). Much slower, supposedly more accurate at different angles FACE_MAX_DISTANCE_SQ = 0.11 // Squared distance between faces to consider them similar ) @@ -30,6 +31,7 @@ func init() { readEnvString("DEFAULT_BUCKET_DIR", &DEFAULT_BUCKET_DIR) readEnvString("DEFAULT_ASSET_PATH_PATTERN", &DEFAULT_ASSET_PATH_PATTERN) readEnvBool("DEBUG_MODE", &DEBUG_MODE) + readEnvBool("FACE_DETECT", &FACE_DETECT) readEnvBool("FACE_DETECT_CNN", &FACE_DETECT_CNN) readEnvFloat("FACE_MAX_DISTANCE_SQ", &FACE_MAX_DISTANCE_SQ) } diff --git a/faces/faces.go b/faces/faces.go index a44700b..58aa62b 100644 --- a/faces/faces.go +++ b/faces/faces.go @@ -14,6 +14,10 @@ var ( ) func init() { + if !config.FACE_DETECT { + log.Println("Face detection is disabled") + return + } log.Println("Loading face recognition models...") // Init the recognizer. var err error diff --git a/processing/detectfaces.go b/processing/detectfaces.go index 75bb292..11d42cf 100644 --- a/processing/detectfaces.go +++ b/processing/detectfaces.go @@ -22,6 +22,9 @@ func (t *detectfaces) requiresContent(asset *models.Asset) bool { } func (t *detectfaces) process(asset *models.Asset, storage storage.StorageAPI) (status int, clean func()) { + if !config.FACE_DETECT { + return Skipped, nil + } if asset.ThumbPath == "" { return Failed, nil