diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 9e768551..5847ece1 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 853f8a77..cf2b987c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ !CMakePresets.json !LICENSE !README.md +!patch_libobs.diff # Exclude lock files *.lock.json diff --git a/data/locale/ar-EG.ini b/data/locale/ar-EG.ini index 158bc327..52191b32 100644 --- a/data/locale/ar-EG.ini +++ b/data/locale/ar-EG.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="تحسين موجّه بالدليل الدلالي" ZERODCE="Zero-DCE" EnableThreshold="تمكين الحد" +Advanced="إعدادات متقدمة" diff --git a/data/locale/bn-IN.ini b/data/locale/bn-IN.ini index f02ce807..082c2326 100644 --- a/data/locale/bn-IN.ini +++ b/data/locale/bn-IN.ini @@ -28,3 +28,4 @@ URETINEX="টিনেক্সএন-নেট" SGLLIE="সেমান্টিক গাইডেড উন্নয়ন" ZERODCE="শূন্য-DCE" EnableThreshold="থ্রেসহোল্ড সক্ষম করুন" +Advanced="উন্নত সেটিংস" diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index f228c90c..d12206c7 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -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" diff --git a/data/locale/es-SP.ini b/data/locale/es-SP.ini index ce65901d..4a6f865d 100644 --- a/data/locale/es-SP.ini +++ b/data/locale/es-SP.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="Mejora guiada semántica" ZERODCE="Zero-DCE" EnableThreshold="Habilitar umbral" +Advanced="Configuración avanzada" diff --git a/data/locale/fr-FR.ini b/data/locale/fr-FR.ini index 73b041f4..c3434509 100644 --- a/data/locale/fr-FR.ini +++ b/data/locale/fr-FR.ini @@ -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" diff --git a/data/locale/hi-IN.ini b/data/locale/hi-IN.ini index 3bbc01c0..d2170267 100644 --- a/data/locale/hi-IN.ini +++ b/data/locale/hi-IN.ini @@ -28,3 +28,4 @@ URETINEX="यूरेटिनेक्स-नेट" SGLLIE="सेमांटिक गाइडेड एन्हांसमेंट" ZERODCE="ज़ीरो-डीसीई" EnableThreshold="थ्रेसहोल्ड सक्षम करें" +Advanced="उन्नत सेटिंग्स" diff --git a/data/locale/it-IT.ini b/data/locale/it-IT.ini index c0c256b9..5b5bc915 100644 --- a/data/locale/it-IT.ini +++ b/data/locale/it-IT.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="Miglioramento semantico guidato" ZERODCE="Zero-DCE" EnableThreshold="Abilita soglia" +Advanced="Impostazioni avanzate" diff --git a/data/locale/ja-JP.ini b/data/locale/ja-JP.ini index a1a39d21..af91c670 100644 --- a/data/locale/ja-JP.ini +++ b/data/locale/ja-JP.ini @@ -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="しきい値設定" diff --git a/data/locale/ko-KR.ini b/data/locale/ko-KR.ini index 0c3d22a4..a0c34a4f 100644 --- a/data/locale/ko-KR.ini +++ b/data/locale/ko-KR.ini @@ -28,3 +28,6 @@ URETINEX="URetinex-Net" SGLLIE="시맨틱 가이드 개선" ZERODCE="Zero-DCE" EnableThreshold="임계값 활성화" +Advanced="고급 설정" +FocalBlurGroup="초점 블러 설정" +ThresholdGroup="임계값 설정" diff --git a/data/locale/pt-BR.ini b/data/locale/pt-BR.ini index 7011b47d..9ca034b4 100644 --- a/data/locale/pt-BR.ini +++ b/data/locale/pt-BR.ini @@ -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" diff --git a/data/locale/ru-RU.ini b/data/locale/ru-RU.ini index 96cf402b..5e3d4602 100644 --- a/data/locale/ru-RU.ini +++ b/data/locale/ru-RU.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="Семантическое улучшение" ZERODCE="Zero-DCE" EnableThreshold="Включить порог" +Advanced="Расширенные настройки" diff --git a/data/locale/ta-IN.ini b/data/locale/ta-IN.ini index 7c4ceb24..43edb50c 100644 --- a/data/locale/ta-IN.ini +++ b/data/locale/ta-IN.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="பரிமாற்றத்தை உதர்வுபடுத்திய மேம்படுத்தல்" ZERODCE="பூஜிய மேற்கோளிக் குறியீடு" EnableThreshold="அளவுருக்கு அனுமதி" +Advanced="மேம்படுத்தப்பட்ட அமைப்புகள்" diff --git a/data/locale/tr-TR.ini b/data/locale/tr-TR.ini index 6fd9c3f8..aaabf5f8 100644 --- a/data/locale/tr-TR.ini +++ b/data/locale/tr-TR.ini @@ -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" diff --git a/data/locale/zh-CN.ini b/data/locale/zh-CN.ini index 5cdecce4..b01701c0 100644 --- a/data/locale/zh-CN.ini +++ b/data/locale/zh-CN.ini @@ -28,3 +28,4 @@ URETINEX="URetinex-Net" SGLLIE="语义引导增强" ZERODCE="Zero-DCE" EnableThreshold="启用阈值" +Advanced="高级设置" diff --git a/src/background-filter.cpp b/src/background-filter.cpp index 89519575..09ee2b89 100644 --- a/src/background-filter.cpp +++ b/src/background-filter.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include "models/ModelSINET.h" #include "models/ModelMediapipe.h" @@ -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; } @@ -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( @@ -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); @@ -208,6 +257,7 @@ void background_filter_update(void *data, obs_data_t *settings) { struct background_removal_filter *tf = reinterpret_cast(data); + tf->enableThreshold = (float)obs_data_get_bool(settings, "enable_threshold"); tf->threshold = (float)obs_data_get_double(settings, "threshold"); @@ -596,19 +646,25 @@ void background_filter_video_render(void *data, gs_effect_t *_effect) reinterpret_cast(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; } @@ -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; } } @@ -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; diff --git a/src/consts.h b/src/consts.h index 554993fe..60c6617b 100644 --- a/src/consts.h +++ b/src/consts.h @@ -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 = + "Background Removal (%1) by OCC AI"; + #endif /* CONSTS_H */ diff --git a/src/enhance-filter.cpp b/src/enhance-filter.cpp index a944e1b2..ec6b66fb 100644 --- a/src/enhance-filter.cpp +++ b/src/enhance-filter.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include "consts.h" #include "obs-utils/obs-utils.h" @@ -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; }