Skip to content

Commit

Permalink
win64 build
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Jun 17, 2021
1 parent 96aee3b commit 8e4b5a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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 [email protected]:obsproject/obs-studio.git` (match the version number to your OBS install. Right now on OSX it's 27.0.1)

#### Build
```
Expand Down Expand Up @@ -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 [email protected]:obsproject/obs-studio.git`, to e.g. Downloads.
Clone the OBS repo, `Downloads\ $ git clone --single-branch -b 27.0.1 [email protected]:obsproject/obs-studio.git`, to e.g. Downloads.

#### Build and install the plugin
```
Expand Down
35 changes: 20 additions & 15 deletions src/background-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ort::Session> session;
std::unique_ptr<Ort::Env> env;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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<float>(),
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e4b5a8

Please sign in to comment.