From a062d60747dfd8ece94457e4fe8230bc16e9c8dd Mon Sep 17 00:00:00 2001 From: raag Date: Sat, 7 May 2022 17:48:51 -0500 Subject: [PATCH 1/4] Compatibility with fedora added --- CMakeLists.txt | 19 ++++++++++++---- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29905b18..f537ed1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,9 +103,11 @@ set(PLUGIN_HEADERS # --- Platform-independent build settings --- add_library(${CMAKE_PROJECT_NAME} MODULE ${PLUGIN_SOURCES} ${PLUGIN_HEADERS}) -find_package(libobs REQUIRED) -find_package(obs-frontend-api REQUIRED) -include(external/ObsPluginHelpers.cmake) +if (NOT EXTRA_LIBRARY_PATH) + find_package(libobs REQUIRED) + find_package(obs-frontend-api REQUIRED) + include(external/ObsPluginHelpers.cmake) +endif() find_package(Onnxruntime REQUIRED) @@ -117,14 +119,23 @@ include_directories( ${LIBOBS_INCLUDE_DIRS} ${Onnxruntime_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} + ${EXTRA_LIBRARY_PATH} ) +if (NOT EXTRA_LIBRARY_PATH) target_link_libraries(${CMAKE_PROJECT_NAME} OBS::libobs OBS::obs-frontend-api ${Onnxruntime_LIBRARIES} ${OpenCV_LIBRARIES} + ) - +else() +target_link_libraries(${CMAKE_PROJECT_NAME} + ${LIBOBS_LIBRARIES} + ${Onnxruntime_LIBRARIES} + ${OpenCV_LIBRARIES} +) +endif() # --- End of section --- # --- Windows-specific build settings and tasks --- diff --git a/README.md b/README.md index fe028a72..55bdc963 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [Windows](#windows) ## Download + Check out the [latest releases](https://github.com/royshil/obs-backgroundremoval/releases) for downloads and install instructions. ## Introduction @@ -20,6 +21,7 @@ a transparent color. The models used for background detection are SINet: https://arxiv.org/abs/1911.09099 and MODNet: https://arxiv.org/pdf/2011.11961.pdf The pre-trained model weights were taken from: + - https://github.com/anilsathyan7/Portrait-Segmentation/tree/master/SINet - https://github.com/ZHKKKe/MODNet @@ -30,6 +32,7 @@ Some more information about how I built it: https://www.morethantechnical.com/20 The plugin was built and tested on Mac OSX, Windows and Ubuntu Linux. Help is appreciated in building on other OSs and formalizing the one-click installers. ### Prerequisites for building + - OpenCV v4.2+: https://github.com/opencv/opencv/ - ONNXRuntime: https://github.com/microsoft/onnxruntime - CMake v3.20+: https://cmake.org/download/ @@ -39,15 +42,18 @@ The plugin was built and tested on Mac OSX, Windows and Ubuntu Linux. Help is ap #### Install dependencies You may use homebrew: + ``` $ brew install opencv onnxruntime ``` Or - you may also build a (very minimal) version of OpenCV and ONNX Runtime for static-linking, instead of the homebrew ones: + ``` /build/ $ ../scripts/makeOpenCV_osx.sh /build/ $ ../scripts/makeOnnxruntime_osx.sh ``` + Static linking should be more robust across versions of OSX, as well as building for 10.13. #### Finding libobs @@ -57,6 +63,7 @@ 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 27.2.4 git@github.com:obsproject/obs-studio.git` (match the version number to your OBS install. Right now on OSX it's 27.2.4) #### Build + ``` $ mkdir -p build && cd build $ cmake .. -DobsLibPath=/Applications/OBS.app/Contents/Frameworks -DobsIncludePath=~/Downloads/obs-studio/libobs @@ -65,6 +72,7 @@ $ cpack ``` #### Install + Unpack the package to the plugins directory of the system's Library folder (which is Apple's preferred way but requires admin privileges) ```sh @@ -74,6 +82,7 @@ sudo unzip -j obs-backgroundremoval-macosx.zip "Resources/data/obs-plugins/obs-b ``` or directly to your OBS install directory, e.g. + ```sh $ unzip -o obs-backgroundremoval-macosx.zip -d /Applications/OBS.app/Contents/ ``` @@ -91,6 +100,7 @@ $ sudo tar xzvf onnxruntime-linux-x64-1.7.0.tgz --strip-components=1 -C /usr/loc ``` Clone this repo into a directory of your choice, then build and install, e.g.: + ```sh $ cd obs-backgroundremoval $ mkdir build && cd build @@ -112,6 +122,7 @@ $ sudo tar xzvf onnxruntime-linux-x64-gpu-${ONNX_VERSION}.tgz --strip-components ``` Then build and install: + ```sh $ sudo ldconfig # required if you have previously had a different version of onnxruntime installed $ mkdir build && cd build @@ -125,16 +136,20 @@ $ mkdir -p ~/.config/obs-studio/plugins/obs-backgroundremoval/bin/64bit $ ln -s /usr/local/lib/obs-plugins/obs-backgroundremoval.so ~/.config/obs-studio/plugins/obs-backgroundremoval/bin/64bit/ $ ln -s /usr/local/share/obs/obs-plugins/obs-backgroundremoval ~/.config/obs-studio/plugins/obs-backgroundremoval/data ``` + If you wish to install this system-wide, change obs-studio path from `~/.config/obs-studio/plugins` to `/usr/share/obs/obs-plugins`. #### Archlinux + A `PKGBUILD` file is provided for making the plugin package + ```sh $ cd scripts $ makepkg -s ``` Building for Arch in Docker (host OS e.g. MacOSX): + ```sh $ docker pull archlinux:latest $ docker run -it -v $(pwd):/src archlinux:latest /bin/bash @@ -145,12 +160,52 @@ $ docker run -it -v $(pwd):/src archlinux:latest /bin/bash # sudo -u builduser bash -c 'cd /src/scripts && makepkg -s' ``` +### Fedora + +```sh +$ sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm +$ sudo dnf groupinstall "Development Tools" "Development Libraries" +$ sudo dnf install obs-studio obs-studio-devel obs-studio-libs opencv-devel opencv american-fuzzy-lop-clang kernel-devel cmake +$ wget https://github.com/microsoft/onnxruntime/releases/download/v1.7.0/onnxruntime-linux-x64-1.7.0.tgz +$ sudo tar xzvf onnxruntime-linux-x64-1.7.0.tgz --strip-components=1 -C /usr/local/ --wildcards "*/include/*" "*/lib*/" +``` + +Clone this repo into a directory of your choice, then build and install, e.g.: + +```sh +$ cd obs-backgroundremoval +$ mkdir build && cd build +$ cmake -DLIBOBS_INCLUDE_DIR=$LIBOBS_INCLUDE_DIR -DEXTRA_LIBRARY_PATH=/usr/include/obs -DWITH_CUDA=ON .. && cmake --build . && sudo cmake --install . +``` + +Fix installation. + +```sh +sudo cp /usr/local/share/obs/obs-plugins/obs-backgroundremoval -R /usr/share/obs/obs-plugins/ +sudo cp /usr/local/lib64/obs-plugins/obs-backgroundremoval.so /usr/lib64/obs-plugins/ +``` + +Add `/usr/local/lib` to `LD_LIBRARY_PATH` + +```sh +echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" > ~/.bash_profile +source ~/.bash_profile +``` + +To test execute obs from terminal + +``` +obs +``` + ### Windows We will use static linking (as much as possible) to aviod having to lug around .DLLs with the plugin. #### Install Prerequisites + Install OpenCV via `vcpkg`: + ```powershell $ mkdir build $ cd build @@ -161,6 +216,7 @@ $ .\vcpkg.exe install opencv[core]:x64-windows-static ``` Install Onnxruntime with NuGet: + ```powershell $ cd build $ mkdir nuget @@ -170,12 +226,14 @@ $ .\nuget.exe install Microsoft.ML.OnnxRuntime.Gpu -Version 1.11.0 ``` ##### Build OBS Studio from source + Clone the OBS repo, `$HOME\Downloads\ $ git clone --recursive git@github.com:obsproject/obs-studio.git`, to e.g. Downloads. Use OBS scripts to build: `$HOME\Downloads\obs-studio $ .\CI\build-windows.ps1` Find the complete instructions here: https://obsproject.com/wiki/build-instructions-for-windows #### Build and install the plugin + ```powershell $ cmake .. -Dlibobs_DIR="$HOME\Downloads\obs-studio\build64\libobs" $ cmake --build . --config Release @@ -184,8 +242,10 @@ $ Expand-Archive .\obs-backgroundremoval-0.4.0-win64.zip -DestinationPath 'C:\Pr ``` To build with CUDA support, tell cmake to use the CUDA version of OnnxRuntime + ```powershell $ cmake .. -Dlibobs_DIR="$HOME\Downloads\obs-studio\build64\libobs" -DWITH_CUDA=ON ``` + The rest of the build process is similar, but the result archive will be `obs-backgroundremoval-win64-cuda.zip`. From c2f98caad4db7ea8ca8f53ae1bcb2f5dbc0fb1c5 Mon Sep 17 00:00:00 2001 From: raag Date: Sat, 7 May 2022 17:52:20 -0500 Subject: [PATCH 2/4] Readme fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55bdc963..b01ef08f 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ Clone this repo into a directory of your choice, then build and install, e.g.: ```sh $ cd obs-backgroundremoval $ mkdir build && cd build -$ cmake -DLIBOBS_INCLUDE_DIR=$LIBOBS_INCLUDE_DIR -DEXTRA_LIBRARY_PATH=/usr/include/obs -DWITH_CUDA=ON .. && cmake --build . && sudo cmake --install . +$ cmake -DLIBOBS_INCLUDE_DIR=/usr/share/obs/libobs -DEXTRA_LIBRARY_PATH=/usr/include/obs -DWITH_CUDA=ON .. && cmake --build . && sudo cmake --install . ``` Fix installation. From e56987207e574d75c80a0a72b8ab68811a2e025f Mon Sep 17 00:00:00 2001 From: raag Date: Sat, 7 May 2022 17:54:33 -0500 Subject: [PATCH 3/4] Readme note --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b01ef08f..b2f2ac6c 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,8 @@ To test execute obs from terminal obs ``` +Finally logout and login to be able to run obs from your desktop icon + ### Windows We will use static linking (as much as possible) to aviod having to lug around .DLLs with the plugin. From 3c3830f118b11f1887d5d992950839126508087c Mon Sep 17 00:00:00 2001 From: raag Date: Mon, 23 May 2022 21:13:47 -0500 Subject: [PATCH 4/4] fedora installation instructions fix --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2f2ac6c..031bcc68 100644 --- a/README.md +++ b/README.md @@ -185,10 +185,19 @@ sudo cp /usr/local/share/obs/obs-plugins/obs-backgroundremoval -R /usr/share/obs sudo cp /usr/local/lib64/obs-plugins/obs-backgroundremoval.so /usr/lib64/obs-plugins/ ``` -Add `/usr/local/lib` to `LD_LIBRARY_PATH` +Add `/usr/local/lib` to `LD_LIBRARY_PATH` environment variable editing `~/.bash_profile` and adding the code below at the end. + +```sh +if [ -n "${LD_LIBRARY_PATH}" ]; then + export LD_LIBRARY_PATH=:/usr/local/lib/ +else + export LD_LIBRARY_PATH=/usr/local/lib/ +fi +``` + +source your `.bash_profile` ```sh -echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" > ~/.bash_profile source ~/.bash_profile ```