diff --git a/CMakeLists.txt b/CMakeLists.txt index c83b9bb9..1825dd71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,11 @@ target_link_libraries(${CMAKE_PROJECT_NAME} # --- Windows-specific build settings and tasks --- if(WIN32) - find_library(OBS_FRONTEND_LIB obs-frontend-api PATHS ${obsPath}/build/UI/obs-frontend-api/Release) + find_library(OBS_FRONTEND_LIB obs-frontend-api + PATHS + ${obsPath}/build/UI/obs-frontend-api/Release + ${obsPath}/build64/UI/obs-frontend-api/Release + ) if(NOT DEFINED OBS_FRONTEND_LIB) set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library") diff --git a/README.md b/README.md index aeb226df..40af8cc1 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Static linking should be more robust across versions of OSX, as well as building If you install the desktop OBS app (https://obsproject.com/download) you already have the binaries for libobs (e.g. `/Applications/OBS.app/Contents/Frameworks/libobs.0.dylib`) -But you don't have the headers - so clone the main obs repo e.g. `git clone --single-branch -b 26.1.2 git@github.com:obsproject/obs-studio.git` (match the version number to your OBS install. Right now on OSX it's 26.1.2) +But you don't have the headers - so clone the main obs repo e.g. `git clone --single-branch -b 27.0.1 git@github.com:obsproject/obs-studio.git` (match the version number to your OBS install. Right now on OSX it's 27.0.1) #### Build ``` @@ -132,7 +132,7 @@ $ Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe $ nuget.exe install Microsoft.ML.OnnxRuntime.DirectML ``` -Clone the OBS repo, `Downloads\ $ git clone --single-branch -b 26.1.2 git@github.com:obsproject/obs-studio.git`, to e.g. Downloads. +Clone the OBS repo, `Downloads\ $ git clone --single-branch -b 27.0.1 git@github.com:obsproject/obs-studio.git`, to e.g. Downloads. #### Build and install the plugin ``` diff --git a/src/background-filter.cpp b/src/background-filter.cpp index 4acf2c38..a5492d30 100644 --- a/src/background-filter.cpp +++ b/src/background-filter.cpp @@ -22,6 +22,13 @@ #include "plugin-macros.generated.h" + +const char* MODEL_SINET = "SINet_Softmax_simple.onnx"; +const char* MODEL_MODNET = "modnet_simple.onnx"; +const char* MODEL_MEDIAPIPE = "mediapipe.onnx"; +const char* MODEL_SELFIE = "selfie_segmentation.onnx"; + + struct background_removal_filter { std::unique_ptr session; std::unique_ptr env; @@ -40,7 +47,7 @@ struct background_removal_filter { float smoothContour = 0.5f; float feather = 0.0f; bool useGPU = false; - std::string modelSelection; + std::string modelSelection = MODEL_MEDIAPIPE; // Use the media-io converter to both scale and convert the colorspace video_scaler_t* scalerToBGR; @@ -53,11 +60,6 @@ struct background_removal_filter { #endif }; -const char* MODEL_SINET = "SINet_Softmax_simple.onnx"; -const char* MODEL_MODNET = "modnet_simple.onnx"; -const char* MODEL_MEDIAPIPE = "mediapipe.onnx"; -const char* MODEL_SELFIE = "selfie_segmentation.onnx"; - static const char *filter_getname(void *unused) { UNUSED_PARAMETER(unused); @@ -172,6 +174,7 @@ static void createOrtSession(struct background_removal_filter *tf) { sessionOptions.SetExecutionMode(ExecutionMode::ORT_SEQUENTIAL); } + blog(LOG_INFO, "tf->modelSelection %s", tf->modelSelection); char* modelFilepath_rawPtr = obs_module_file(tf->modelSelection.c_str()); blog(LOG_INFO, "Model location %s", modelFilepath_rawPtr); @@ -273,12 +276,15 @@ static void filter_update(void *data, obs_data_t *settings) tf->feather = (float)obs_data_get_double(settings, "feather"); const bool newUseGpu = (bool)obs_data_get_bool(settings, "useGPU"); - const std::string newModel(obs_data_get_string(settings, "model_select")); + const std::string newModel = obs_data_get_string(settings, "model_select"); - if (tf->modelSelection.empty() or tf->modelSelection != newModel or newUseGpu != tf->useGPU) + blog(LOG_INFO, "newModel %s tf->modelSelection %s", newModel, tf->modelSelection); + + if (tf->modelSelection.empty() || tf->modelSelection != newModel || newUseGpu != tf->useGPU) { // Re-initialize model if it's not already the selected one - tf->modelSelection = newModel; + tf->modelSelection = std::string(newModel); + blog(LOG_INFO, "newModel %s tf->modelSelection %s", newModel, tf->modelSelection); tf->useGPU = newUseGpu; destroyScalers(tf); createOrtSession(tf); @@ -386,9 +392,8 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra cv::cvtColor(imageBGR, imageRGB, cv::COLOR_BGR2RGB); // Resize to network input size - cv::Mat resizedImageRGB; uint32_t inputWidth, inputHeight; - if (tf->modelSelection == MODEL_SINET or tf->modelSelection == MODEL_MODNET) { + if (tf->modelSelection == MODEL_SINET || tf->modelSelection == MODEL_MODNET) { // BCHW inputWidth = (int)tf->inputDims[3]; inputHeight = (int)tf->inputDims[2]; @@ -398,6 +403,7 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra inputHeight = (int)tf->inputDims[1]; } + cv::Mat resizedImageRGB; cv::resize(imageRGB, resizedImageRGB, cv::Size(inputWidth, inputHeight)); // Prepare input to nework @@ -414,7 +420,7 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra preprocessedImage = resizedImage / 255.0; } - if (tf->modelSelection == MODEL_SINET or tf->modelSelection == MODEL_MODNET) { + if (tf->modelSelection == MODEL_SINET || tf->modelSelection == MODEL_MODNET) { hwc_to_chw(resizedImage, preprocessedImage); tf->inputTensorValues.assign( preprocessedImage.begin(), @@ -432,7 +438,7 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra uint32_t outputWidth, outputHeight; int64_t outputChannels; - if (tf->modelSelection == MODEL_SINET or tf->modelSelection == MODEL_MODNET) { + if (tf->modelSelection == MODEL_SINET || tf->modelSelection == MODEL_MODNET) { // BCHW outputWidth = (int)tf->outputDims.at(3); outputHeight = (int)tf->outputDims.at(2); @@ -466,7 +472,7 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra } cv::Mat backgroundMask; - if (tf->modelSelection == MODEL_SINET or tf->modelSelection == MODEL_MEDIAPIPE) { + if (tf->modelSelection == MODEL_SINET || tf->modelSelection == MODEL_MEDIAPIPE) { backgroundMask = outputImage > tf->threshold; } else { backgroundMask = outputImage < tf->threshold; @@ -518,7 +524,6 @@ static struct obs_source_frame * filter_render(void *data, struct obs_source_fra catch(const std::exception& e) { blog(LOG_ERROR, "%s", e.what()); } - // Put masked image back on frame convertBGRToFrame(imageBGR, frame, tf); return frame;