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

Adding simple mode for settings #443

Merged
merged 12 commits into from
Dec 15, 2023
2 changes: 1 addition & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
draft: true
prerelease: ${{ fromJSON(steps.check.outputs.prerelease) }}
tag_name: ${{ steps.check.outputs.version }}
name: OBS Studio ${{ steps.check.outputs.version }}
name: obs-backgroundremoval ${{ steps.check.outputs.version }}
body_path: ${{ github.workspace }}/CHECKSUMS.txt
files: |
${{ github.workspace }}/*.exe
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
!CMakePresets.json
!LICENSE
!README.md
!patch_libobs.diff

# Exclude lock files
*.lock.json
Expand Down
1 change: 1 addition & 0 deletions data/locale/ar-EG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="تحسين موجّه بالدليل الدلالي"
ZERODCE="Zero-DCE"
EnableThreshold="تمكين الحد"
Advanced="إعدادات متقدمة"
1 change: 1 addition & 0 deletions data/locale/bn-IN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="টিনেক্সএন-নেট"
SGLLIE="সেমান্টিক গাইডেড উন্নয়ন"
ZERODCE="শূন্য-DCE"
EnableThreshold="থ্রেসহোল্ড সক্ষম করুন"
Advanced="উন্নত সেটিংস"
3 changes: 3 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ BlurFocusPoint="Blur focus point"
TCMonoDepth="TCMonoDepth (Depth)"
EnableFocalBlur="Enable focal blur"
BlurFocusDepth="Blur focus depth"
Advanced="Advanced settings"
FocalBlurGroup="Focal blur settings"
ThresholdGroup="Threshold settings"
1 change: 1 addition & 0 deletions data/locale/es-SP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="Mejora guiada semántica"
ZERODCE="Zero-DCE"
EnableThreshold="Habilitar umbral"
Advanced="Configuración avanzada"
1 change: 1 addition & 0 deletions data/locale/fr-FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="Amélioration Guidée par la Sémantique"
ZERODCE="Zero-DCE"
EnableThreshold="Activer le seuil"
Advanced="Paramètres avancés"
1 change: 1 addition & 0 deletions data/locale/hi-IN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="यूरेटिनेक्स-नेट"
SGLLIE="सेमांटिक गाइडेड एन्हांसमेंट"
ZERODCE="ज़ीरो-डीसीई"
EnableThreshold="थ्रेसहोल्ड सक्षम करें"
Advanced="उन्नत सेटिंग्स"
1 change: 1 addition & 0 deletions data/locale/it-IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="Miglioramento semantico guidato"
ZERODCE="Zero-DCE"
EnableThreshold="Abilita soglia"
Advanced="Impostazioni avanzate"
14 changes: 14 additions & 0 deletions data/locale/ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ RobustVideoMatting="Robust Video Matting"
CalculateMaskEveryXFrame="Xフレーム毎にマスクを計算"
BlurBackgroundFactor0NoBlurUseColor="背景ぼかし係数(0でぼかさず背景色を使用)"
EnableThreshold="しきい値を有効にする"
Advanced="詳細設定"
BlurFocusPoint="ぼかし焦点点"
EnableFocalBlur="焦点ぼかしを有効にする"
BlurFocusDepth="ぼかし焦点深度"
EffectStrengh="効果強度(0で効果なし)"
EnhancementModel="強化モデル"
NumThreads="# CPUスレッド"
TCMonoDepth="TCMonoDepth(深度)"
TBEFN="TBEFN"
URETINEX="URetinex-Net"
SGLLIE="Semantic Guided Enhancement"
ZERODCE="Zero-DCE"
FocalBlurGroup="焦点ぼかし設定"
ThresholdGroup="しきい値設定"
3 changes: 3 additions & 0 deletions data/locale/ko-KR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ URETINEX="URetinex-Net"
SGLLIE="시맨틱 가이드 개선"
ZERODCE="Zero-DCE"
EnableThreshold="임계값 활성화"
Advanced="고급 설정"
FocalBlurGroup="초점 블러 설정"
ThresholdGroup="임계값 설정"
7 changes: 7 additions & 0 deletions data/locale/pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ URETINEX="URetinex-Net"
SGLLIE="Aprimoramento Guiado Semântico"
ZERODCE="Zero-DCE"
EnableThreshold="Ativar Limiar"
Advanced="Configurações Avançadas"
FocalBlurGroup="Configurações de desfoque focal"
BlurFocusPoint="Ponto de foco desfocado"
EnableFocalBlur="Ativar desfoque focal"
BlurFocusDepth="Profundidade de foco desfocada"
TCMonoDepth="TCMonoDepth (Profundidade)"
ThresholdGroup="Configurações de Limiar"
1 change: 1 addition & 0 deletions data/locale/ru-RU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="Семантическое улучшение"
ZERODCE="Zero-DCE"
EnableThreshold="Включить порог"
Advanced="Расширенные настройки"
1 change: 1 addition & 0 deletions data/locale/ta-IN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="பரிமாற்றத்தை உதர்வுபடுத்திய மேம்படுத்தல்"
ZERODCE="பூஜிய மேற்கோளிக் குறியீடு"
EnableThreshold="அளவுருக்கு அனுமதி"
Advanced="மேம்படுத்தப்பட்ட அமைப்புகள்"
1 change: 1 addition & 0 deletions data/locale/tr-TR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="Semantik Rehberli İyileştirme"
ZERODCE="Zero-DCE"
EnableThreshold="Eşik Değerini Etkinleştir"
Advanced="Gelişmiş Ayarlar"
1 change: 1 addition & 0 deletions data/locale/zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ URETINEX="URetinex-Net"
SGLLIE="语义引导增强"
ZERODCE="Zero-DCE"
EnableThreshold="启用阈值"
Advanced="高级设置"
132 changes: 96 additions & 36 deletions src/background-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <new>
#include <mutex>

#include <QString>

#include <plugin-support.h>
#include "models/ModelSINET.h"
#include "models/ModelMediapipe.h"
Expand Down Expand Up @@ -55,18 +57,49 @@ const char *background_filter_getname(void *unused)

/** PROPERTIES */

static bool visible_on_bool(obs_properties_t *ppts, obs_data_t *settings,
const char *bool_prop, const char *prop_name)
{
const bool enabled = obs_data_get_bool(settings, bool_prop);
obs_property_t *p = obs_properties_get(ppts, prop_name);
obs_property_set_visible(p, enabled);
return true;
}

static bool enable_threshold_modified(obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings)
{
const bool enabled = obs_data_get_bool(settings, "enable_threshold");
p = obs_properties_get(ppts, "threshold");
obs_property_set_visible(p, enabled);
p = obs_properties_get(ppts, "contour_filter");
obs_property_set_visible(p, enabled);
p = obs_properties_get(ppts, "smooth_contour");
obs_property_set_visible(p, enabled);
p = obs_properties_get(ppts, "feather");
obs_property_set_visible(p, enabled);
UNUSED_PARAMETER(p);
return visible_on_bool(ppts, settings, "enable_threshold",
"threshold_group");
}

static bool enable_focal_blur(obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings)
{
UNUSED_PARAMETER(p);
return visible_on_bool(ppts, settings, "enable_focal_blur",
"focal_blur_group");
}

static bool enable_advanced_settings(obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings)
{
const bool enabled = obs_data_get_bool(settings, "advanced");
p = obs_properties_get(ppts, "blur_background");
obs_property_set_visible(p, true);

for (const char *prop_name :
{"model_select", "useGPU", "mask_every_x_frames", "numThreads",
"enable_focal_blur", "enable_threshold"}) {
p = obs_properties_get(ppts, prop_name);
obs_property_set_visible(p, enabled);
}

if (enabled) {
enable_threshold_modified(ppts, p, settings);
enable_focal_blur(ppts, p, settings);
}

return true;
}
Expand All @@ -75,28 +108,41 @@ obs_properties_t *background_filter_properties(void *data)
{
obs_properties_t *props = obs_properties_create();

obs_property_t *advanced = obs_properties_add_bool(
props, "advanced", obs_module_text("Advanced"));

// If advanced is selected show the advanced settings, otherwise hide them
obs_property_set_modified_callback(advanced, enable_advanced_settings);

/* Threshold props */
obs_property_t *p_enable_threshold = obs_properties_add_bool(
props, "enable_threshold", obs_module_text("EnableThreshold"));
obs_property_set_modified_callback(p_enable_threshold,
enable_threshold_modified);

obs_properties_add_float_slider(props, "threshold",
// Threshold props group
obs_properties_t *threshold_props = obs_properties_create();

obs_properties_add_float_slider(threshold_props, "threshold",
obs_module_text("Threshold"), 0.0, 1.0,
0.025);

obs_properties_add_float_slider(
props, "contour_filter",
threshold_props, "contour_filter",
obs_module_text("ContourFilterPercentOfImage"), 0.0, 1.0,
0.025);

obs_properties_add_float_slider(props, "smooth_contour",
obs_properties_add_float_slider(threshold_props, "smooth_contour",
obs_module_text("SmoothSilhouette"),
0.0, 1.0, 0.05);

obs_properties_add_float_slider(
props, "feather", obs_module_text("FeatherBlendSilhouette"),
0.0, 1.0, 0.05);
threshold_props, "feather",
obs_module_text("FeatherBlendSilhouette"), 0.0, 1.0, 0.05);

obs_properties_add_group(props, "threshold_group",
obs_module_text("ThresholdGroup"),
OBS_GROUP_NORMAL, threshold_props);

/* GPU, CPU and performance Props */
obs_property_t *p_use_gpu = obs_properties_add_list(
Expand Down Expand Up @@ -154,34 +200,37 @@ obs_properties_t *background_filter_properties(void *data)

obs_property_t *p_enable_focal_blur = obs_properties_add_bool(
props, "enable_focal_blur", obs_module_text("EnableFocalBlur"));
obs_property_set_modified_callback(
p_enable_focal_blur,
[](obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings) {
UNUSED_PARAMETER(p);
const bool enabled = obs_data_get_bool(
settings, "enable_focal_blur");
obs_property_t *prop =
obs_properties_get(ppts, "blur_focus_point");
obs_property_set_visible(prop, enabled);
prop = obs_properties_get(ppts, "blur_focus_depth");
obs_property_set_visible(prop, enabled);
return true;
});

obs_properties_add_float_slider(props, "blur_focus_point",
obs_property_set_modified_callback(p_enable_focal_blur,
enable_focal_blur);

obs_properties_t *focal_blur_props = obs_properties_create();

obs_properties_add_float_slider(focal_blur_props, "blur_focus_point",
obs_module_text("BlurFocusPoint"), 0.0,
1.0, 0.05);
obs_properties_add_float_slider(props, "blur_focus_depth",
obs_properties_add_float_slider(focal_blur_props, "blur_focus_depth",
obs_module_text("BlurFocusDepth"), 0.0,
0.3, 0.02);

obs_properties_add_group(props, "focal_blur_group",
obs_module_text("FocalBlurGroup"),
OBS_GROUP_NORMAL, focal_blur_props);

// Add a informative text about the plugin
obs_properties_add_text(props, "info",
QString(PLUGIN_INFO_TEMPLATE)
.arg(PLUGIN_VERSION)
.toStdString()
.c_str(),
OBS_TEXT_INFO);

UNUSED_PARAMETER(data);
return props;
}

void background_filter_defaults(obs_data_t *settings)
{
obs_data_set_default_bool(settings, "advanced", false);
obs_data_set_default_bool(settings, "enable_threshold", true);
obs_data_set_default_double(settings, "threshold", 0.5);
obs_data_set_default_double(settings, "contour_filter", 0.05);
Expand All @@ -208,6 +257,7 @@ void background_filter_update(void *data, obs_data_t *settings)
{
struct background_removal_filter *tf =
reinterpret_cast<background_removal_filter *>(data);

tf->enableThreshold =
(float)obs_data_get_bool(settings, "enable_threshold");
tf->threshold = (float)obs_data_get_double(settings, "threshold");
Expand Down Expand Up @@ -596,19 +646,25 @@ void background_filter_video_render(void *data, gs_effect_t *_effect)
reinterpret_cast<background_removal_filter *>(data);

if (tf->isDisabled) {
obs_source_skip_video_filter(tf->source);
if (tf->source) {
obs_source_skip_video_filter(tf->source);
}
return;
}

uint32_t width, height;
if (!getRGBAFromStageSurface(tf, width, height)) {
obs_source_skip_video_filter(tf->source);
if (tf->source) {
obs_source_skip_video_filter(tf->source);
}
return;
}

if (!tf->effect) {
// Effect failed to load, skip rendering
obs_source_skip_video_filter(tf->source);
if (tf->source) {
obs_source_skip_video_filter(tf->source);
}
return;
}

Expand All @@ -620,7 +676,9 @@ void background_filter_video_render(void *data, gs_effect_t *_effect)
1, (const uint8_t **)&tf->backgroundMask.data, 0);
if (!alphaTexture) {
obs_log(LOG_ERROR, "Failed to create alpha texture");
obs_source_skip_video_filter(tf->source);
if (tf->source) {
obs_source_skip_video_filter(tf->source);
}
return;
}
}
Expand All @@ -631,7 +689,9 @@ void background_filter_video_render(void *data, gs_effect_t *_effect)

if (!obs_source_process_filter_begin(tf->source, GS_RGBA,
OBS_ALLOW_DIRECT_RENDERING)) {
obs_source_skip_video_filter(tf->source);
if (tf->source) {
obs_source_skip_video_filter(tf->source);
}
gs_texture_destroy(alphaTexture);
gs_texture_destroy(blurredTexture);
return;
Expand Down
3 changes: 3 additions & 0 deletions src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ const char *const EFFECT_PATH = "effects/mask_alpha_filter.effect";
const char *const KAWASE_BLUR_EFFECT_PATH = "effects/kawase_blur.effect";
const char *const BLEND_EFFECT_PATH = "effects/blend_images.effect";

const char *const PLUGIN_INFO_TEMPLATE =
"<a href=\"https://github.com/occ-ai/obs-backgroundremoval/\">Background Removal</a> (%1) by <a href=\"https://github.com/occ-ai\">OCC AI</a>";

#endif /* CONSTS_H */
11 changes: 11 additions & 0 deletions src/enhance-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <new>
#include <mutex>

#include <QString>

#include <plugin-support.h>
#include "consts.h"
#include "obs-utils/obs-utils.h"
Expand Down Expand Up @@ -73,6 +75,15 @@ obs_properties_t *enhance_filter_properties(void *data)
obs_property_list_add_string(p_use_gpu, obs_module_text("CoreML"),
USEGPU_COREML);
#endif

// Add a informative text about the plugin
obs_properties_add_text(props, "info",
QString(PLUGIN_INFO_TEMPLATE)
.arg(PLUGIN_VERSION)
.toStdString()
.c_str(),
OBS_TEXT_INFO);

return props;
}

Expand Down