This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
generated from obsproject/obs-plugintemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,654 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,14 @@ | |
}, | ||
"platformConfig": { | ||
"macos": { | ||
"bundleId": "com.example.obs-plugintemplate" | ||
"bundleId": "com.royshilkrot.obs-detect" | ||
} | ||
}, | ||
"name": "obs-plugintemplate", | ||
"displayName": "OBS Plugin Template", | ||
"version": "1.0.0", | ||
"author": "Your Name Here", | ||
"website": "https://example.com", | ||
"name": "obs-detect", | ||
"displayName": "OBS Object Detection plugin", | ||
"version": "0.0.1", | ||
"author": "Roy Shilkrot", | ||
"website": "https://github.com/occ-ai", | ||
"email": "[email protected]", | ||
"uuids": { | ||
"windowsApp": "00000000-0000-0000-0000-000000000000" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
include(FetchContent) | ||
|
||
set(CUSTOM_ONNXRUNTIME_URL | ||
"" | ||
CACHE STRING "URL of a downloaded ONNX Runtime tarball") | ||
|
||
set(CUSTOM_ONNXRUNTIME_HASH | ||
"" | ||
CACHE STRING "Hash of a downloaded ONNX Runtime tarball") | ||
|
||
set(Onnxruntime_VERSION "1.17.1") | ||
|
||
if(CUSTOM_ONNXRUNTIME_URL STREQUAL "") | ||
set(USE_PREDEFINED_ONNXRUNTIME ON) | ||
else() | ||
if(CUSTOM_ONNXRUNTIME_HASH STREQUAL "") | ||
message(FATAL_ERROR "Both of CUSTOM_ONNXRUNTIME_URL and CUSTOM_ONNXRUNTIME_HASH must be present!") | ||
else() | ||
set(USE_PREDEFINED_ONNXRUNTIME OFF) | ||
endif() | ||
endif() | ||
|
||
if(USE_PREDEFINED_ONNXRUNTIME) | ||
set(Onnxruntime_BASEURL "https://github.com/microsoft/onnxruntime/releases/download/v${Onnxruntime_VERSION}") | ||
set(Onnxruntime_WINDOWS_VERSION "v${Onnxruntime_VERSION}-1") | ||
set(Onnxruntime_WINDOWS_BASEURL | ||
"https://github.com/occ-ai/occ-ai-dep-onnxruntime-static-win/releases/download/${Onnxruntime_WINDOWS_VERSION}") | ||
|
||
if(APPLE) | ||
set(Onnxruntime_URL "${Onnxruntime_BASEURL}/onnxruntime-osx-universal2-${Onnxruntime_VERSION}.tgz") | ||
set(Onnxruntime_HASH SHA256=9FA57FA6F202A373599377EF75064AE568FDA8DA838632B26A86024C7378D306) | ||
elseif(MSVC) | ||
set(Onnxruntime_URL "${Onnxruntime_WINDOWS_BASEURL}/onnxruntime-windows-${Onnxruntime_WINDOWS_VERSION}-Release.zip") | ||
set(OOnnxruntime_HASH SHA256=39E63850D9762810161AE1B4DEAE5E3C02363521273E4B894A9D9707AB626C38) | ||
else() | ||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") | ||
set(Onnxruntime_URL "${Onnxruntime_BASEURL}/onnxruntime-linux-aarch64-${Onnxruntime_VERSION}.tgz") | ||
set(Onnxruntime_HASH SHA256=70B6F536BB7AB5961D128E9DBD192368AC1513BFFB74FE92F97AAC342FBD0AC1) | ||
else() | ||
set(Onnxruntime_URL "${Onnxruntime_BASEURL}/onnxruntime-linux-x64-gpu-${Onnxruntime_VERSION}.tgz") | ||
set(Onnxruntime_HASH SHA256=613C53745EA4960ED368F6B3AB673558BB8561C84A8FA781B4EA7FB4A4340BE4) | ||
endif() | ||
endif() | ||
else() | ||
set(Onnxruntime_URL "${CUSTOM_ONNXRUNTIME_URL}") | ||
set(Onnxruntime_HASH "${CUSTOM_ONNXRUNTIME_HASH}") | ||
endif() | ||
|
||
FetchContent_Declare( | ||
onnxruntime | ||
URL ${Onnxruntime_URL} | ||
URL_HASH ${Onnxruntime_HASH}) | ||
FetchContent_MakeAvailable(onnxruntime) | ||
|
||
if(APPLE) | ||
set(Onnxruntime_LIB "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime.${Onnxruntime_VERSION}.dylib") | ||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${Onnxruntime_LIB}") | ||
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC "${onnxruntime_SOURCE_DIR}/include") | ||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${Onnxruntime_LIB}") | ||
set_property(SOURCE "${Onnxruntime_LIB}" PROPERTY MACOSX_PACKAGE_LOCATION Frameworks) | ||
source_group("Frameworks" FILES "${Onnxruntime_LIB}") | ||
add_custom_command( | ||
TARGET "${CMAKE_PROJECT_NAME}" | ||
POST_BUILD | ||
COMMAND | ||
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libonnxruntime.${Onnxruntime_VERSION}.dylib" | ||
"@loader_path/../Frameworks/libonnxruntime.${Onnxruntime_VERSION}.dylib" $<TARGET_FILE:${CMAKE_PROJECT_NAME}>) | ||
elseif(MSVC) | ||
add_library(Ort INTERFACE) | ||
set(Onnxruntime_LIB_NAMES | ||
session;providers_shared;providers_dml;optimizer;providers;framework;graph;util;mlas;common;flatbuffers) | ||
foreach(lib_name IN LISTS Onnxruntime_LIB_NAMES) | ||
add_library(Ort::${lib_name} STATIC IMPORTED) | ||
set_target_properties(Ort::${lib_name} PROPERTIES IMPORTED_LOCATION | ||
${onnxruntime_SOURCE_DIR}/lib/onnxruntime_${lib_name}.lib) | ||
set_target_properties(Ort::${lib_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${onnxruntime_SOURCE_DIR}/include) | ||
target_link_libraries(Ort INTERFACE Ort::${lib_name}) | ||
endforeach() | ||
|
||
set(Onnxruntime_EXTERNAL_LIB_NAMES | ||
onnx;onnx_proto;libprotobuf-lite;re2;absl_throw_delegate;absl_hash;absl_city;absl_low_level_hash;absl_raw_hash_set | ||
) | ||
foreach(lib_name IN LISTS Onnxruntime_EXTERNAL_LIB_NAMES) | ||
add_library(Ort::${lib_name} STATIC IMPORTED) | ||
set_target_properties(Ort::${lib_name} PROPERTIES IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/${lib_name}.lib) | ||
target_link_libraries(Ort INTERFACE Ort::${lib_name}) | ||
endforeach() | ||
|
||
add_library(Ort::DirectML SHARED IMPORTED) | ||
set_target_properties(Ort::DirectML PROPERTIES IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/bin/DirectML.dll) | ||
set_target_properties(Ort::DirectML PROPERTIES IMPORTED_IMPLIB ${onnxruntime_SOURCE_DIR}/bin/DirectML.lib) | ||
|
||
target_link_libraries(Ort INTERFACE Ort::DirectML d3d12.lib dxgi.lib dxguid.lib Dxcore.lib) | ||
|
||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Ort) | ||
|
||
install(IMPORTED_RUNTIME_ARTIFACTS Ort::DirectML DESTINATION "obs-plugins/64bit") | ||
else() | ||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") | ||
set(Onnxruntime_LINK_LIBS "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime.so.${Onnxruntime_VERSION}") | ||
set(Onnxruntime_INSTALL_LIBS ${Onnxruntime_LINK_LIBS}) | ||
else() | ||
set(Onnxruntime_LINK_LIBS "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime.so.${Onnxruntime_VERSION}") | ||
set(Onnxruntime_INSTALL_LIBS | ||
${Onnxruntime_LINK_LIBS} "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_shared.so" | ||
"${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_cuda.so" | ||
"${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_tensorrt.so") | ||
endif() | ||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${Onnxruntime_LINK_LIBS}) | ||
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC "${onnxruntime_SOURCE_DIR}/include") | ||
install(FILES ${Onnxruntime_INSTALL_LIBS} DESTINATION "${CMAKE_INSTALL_LIBDIR}/obs-plugins/${CMAKE_PROJECT_NAME}") | ||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/${CMAKE_PROJECT_NAME}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
include(FetchContent) | ||
|
||
set(CUSTOM_OPENCV_URL | ||
"" | ||
CACHE STRING "URL of a downloaded OpenCV static library tarball") | ||
|
||
set(CUSTOM_OPENCV_HASH | ||
"" | ||
CACHE STRING "Hash of a downloaded OpenCV staitc library tarball") | ||
|
||
if(CUSTOM_OPENCV_URL STREQUAL "") | ||
set(USE_PREDEFINED_OPENCV ON) | ||
else() | ||
if(CUSTOM_OPENCV_HASH STREQUAL "") | ||
message(FATAL_ERROR "Both of CUSTOM_OPENCV_URL and CUSTOM_OPENCV_HASH must be present!") | ||
else() | ||
set(USE_PREDEFINED_OPENCV OFF) | ||
endif() | ||
endif() | ||
|
||
if(USE_PREDEFINED_OPENCV) | ||
set(OpenCV_VERSION "v4.8.1-1") | ||
set(OpenCV_BASEURL "https://github.com/obs-ai/obs-backgroundremoval-dep-opencv/releases/download/${OpenCV_VERSION}") | ||
|
||
if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) | ||
set(OpenCV_BUILD_TYPE Release) | ||
else() | ||
set(OpenCV_BUILD_TYPE Debug) | ||
endif() | ||
|
||
if(APPLE) | ||
if(OpenCV_BUILD_TYPE STREQUAL Debug) | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-macos-${OpenCV_VERSION}-Debug.tar.gz") | ||
set(OpenCV_HASH SHA256=2930e335a19cc03a3d825e2b76eadd0d5cf08d8baf6537747d43f503dff32454) | ||
else() | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-macos-${OpenCV_VERSION}-Release.tar.gz") | ||
set(OpenCV_HASH SHA256=b0c4fe2370b0bd5aa65c408e875b1ab18508ba31b93083805d7e398a3ecafdac) | ||
endif() | ||
elseif(MSVC) | ||
if(OpenCV_BUILD_TYPE STREQUAL Debug) | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-windows-${OpenCV_VERSION}-Debug.zip") | ||
set(OpenCV_HASH SHA256=0c5ef12cf4b4e4db7ea17a24db156165b6f01759f3f1660b069d0722e5d5dc37) | ||
else() | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-windows-${OpenCV_VERSION}-Release.zip") | ||
set(OpenCV_HASH SHA256=5e468f71d41d3a3ea46cc4f247475877f65d3655a2764a2c01074bda3b3e6864) | ||
endif() | ||
else() | ||
if(OpenCV_BUILD_TYPE STREQUAL Debug) | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_VERSION}-Debug.tar.gz") | ||
set(OpenCV_HASH SHA256=e2e246d6b4f279be80e7fd0a78cba8a0eeee7b53ae807f2f57428d6876306422) | ||
else() | ||
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_VERSION}-Release.tar.gz") | ||
set(OpenCV_HASH SHA256=809922a7cc9f344a2d82a232ed7b02e122c82e77cba94b4047e666a0527cc00e) | ||
endif() | ||
endif() | ||
else() | ||
set(OpenCV_URL "${CUSTOM_OPENCV_URL}") | ||
set(OpenCV_HASH "${CUSTOM_OPENCV_HASH}") | ||
endif() | ||
|
||
FetchContent_Declare( | ||
opencv | ||
URL ${OpenCV_URL} | ||
URL_HASH ${OpenCV_HASH}) | ||
FetchContent_MakeAvailable(opencv) | ||
|
||
add_library(OpenCV INTERFACE) | ||
if(MSVC) | ||
target_link_libraries( | ||
OpenCV | ||
INTERFACE ${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_imgproc481.lib | ||
${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_core481.lib | ||
${opencv_SOURCE_DIR}/x64/vc17/staticlib/zlib.lib) | ||
target_include_directories(OpenCV SYSTEM INTERFACE ${opencv_SOURCE_DIR}/include) | ||
else() | ||
target_link_libraries( | ||
OpenCV INTERFACE ${opencv_SOURCE_DIR}/lib/libopencv_imgproc.a ${opencv_SOURCE_DIR}/lib/libopencv_core.a | ||
${opencv_SOURCE_DIR}/lib/opencv4/3rdparty/libzlib.a) | ||
target_include_directories(OpenCV SYSTEM INTERFACE ${opencv_SOURCE_DIR}/include/opencv4) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef FILTERDATA_H | ||
#define FILTERDATA_H | ||
|
||
#include <obs-module.h> | ||
#include "edgeyolo/edgeyolo_onnxruntime.hpp" | ||
|
||
/** | ||
* @brief The filter_data struct | ||
* | ||
* This struct is used to store the base data needed for ORT filters. | ||
* | ||
*/ | ||
struct filter_data { | ||
std::string useGPU; | ||
uint32_t numThreads; | ||
|
||
obs_source_t *source; | ||
gs_texrender_t *texrender; | ||
gs_stagesurf_t *stagesurface; | ||
gs_effect_t *effect; | ||
|
||
cv::Mat inputBGRA; | ||
cv::Mat outputPreviewBGRA; | ||
|
||
bool isDisabled; | ||
bool preview; | ||
|
||
std::mutex inputBGRALock; | ||
std::mutex outputLock; | ||
std::mutex modelMutex; | ||
|
||
std::unique_ptr<edgeyolo_cpp::EdgeYOLOONNXRuntime> edgeyolo; | ||
|
||
#if _WIN32 | ||
std::wstring modelFilepath; | ||
#else | ||
std::string modelFilepath; | ||
#endif | ||
}; | ||
|
||
#endif /* FILTERDATA_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef CONSTS_H | ||
#define CONSTS_H | ||
|
||
const char *const USEGPU_CPU = "cpu"; | ||
const char *const USEGPU_DML = "dml"; | ||
const char *const USEGPU_CUDA = "cuda"; | ||
const char *const USEGPU_TENSORRT = "tensorrt"; | ||
const char *const USEGPU_COREML = "coreml"; | ||
|
||
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-detect/\">Detect Plugin</a> (%1) by " | ||
"<a href=\"https://github.com/occ-ai\">OCC AI</a> ❤️ " | ||
"<a href=\"https://www.patreon.com/RoyShilkrot\">Support & Follow</a>"; | ||
const char *const PLUGIN_INFO_TEMPLATE_UPDATE_AVAILABLE = | ||
"<center><a href=\"https://github.com/occ-ai/obs-detect/releases\">🚀 Update available! (%1)</a></center>"; | ||
|
||
#endif /* CONSTS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "detect-filter.h" | ||
|
||
struct obs_source_info detect_filter_info = { | ||
.id = "detect-filter", | ||
.type = OBS_SOURCE_TYPE_FILTER, | ||
.output_flags = OBS_SOURCE_VIDEO, | ||
.get_name = detect_filter_getname, | ||
.create = detect_filter_create, | ||
.destroy = detect_filter_destroy, | ||
.get_defaults = detect_filter_defaults, | ||
.get_properties = detect_filter_properties, | ||
.update = detect_filter_update, | ||
.activate = detect_filter_activate, | ||
.deactivate = detect_filter_deactivate, | ||
.video_tick = detect_filter_video_tick, | ||
.video_render = detect_filter_video_render, | ||
}; |
Oops, something went wrong.