Skip to content

Commit

Permalink
Merge pull request #20 from occ-ai/roy.pixelate_dilate_zoom_choices
Browse files Browse the repository at this point in the history
feat: Add pixelate effect support for masking
  • Loading branch information
royshil committed Jun 1, 2024
2 parents 6ccfecb + 615f91c commit a41f024
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 69 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ Current features:

- Detect over 80 categories of objects, using an efficient model ([EdgeYOLO](https://github.com/LSH9832/edgeyolo))
- 3 Model sizes: Small, Medium and Large
- Face detection model, fast and efficient ([YuNet](https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet))
- Load custom ONNX detection models from disk
- Control detection threshold
- Select object category filter (e.g. find only "Person")
- Masking: Blur, Solid color, Transparent, output binary mask (combine with other plugins!)
- Tracking: Single object / All objects, Zoom factor, smooth transition
- Filter by: Minimal Detection confidence, Object category (e.g. only "Person"), Object Minimal Size
- Masking: Blur, Pixelate, Solid color, Transparent, output binary mask (combine with other plugins!)
- Tracking: Single object / Biggest / Oldest / All objects, Zoom factor, smooth transition
- SORT algorithm for tracking smoothness and continuity
- Save detections to file in real-time, for integrations e.g. with Streamer.bot

Roadmap features:
- Precise object mask, beyond bounding box
- Implement SORT tracking for smoothness
- Multiple object category selection (e.g. Dog + Cat + Duck)
- Make available detection information for other plugins through settings
- More real-time models choices

## Train and use a custom detection model

Expand Down
51 changes: 51 additions & 0 deletions data/effects/pixelate.effect
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
uniform float4x4 ViewProj;
uniform texture2d image;
uniform texture2d focalmask;

uniform float pixel_size; // Size of the pixelation
uniform float2 tex_size; // Size of the texture in pixels

sampler_state textureSampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};

struct VertDataIn {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};

struct VertDataOut {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};

VertDataOut VSDefault(VertDataOut v_in)
{
VertDataOut vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}

float4 PSPixelate(VertDataOut v_in) : TARGET
{
if (focalmask.Sample(textureSampler, v_in.uv).r == 0) {
// No mask - return the original image value without any blur
return image.Sample(textureSampler, v_in.uv);
}

float2 pixelUV = v_in.uv * tex_size; // Convert to pixel coordinates
float2 pixelatedUV = floor(pixelUV / pixel_size) * pixel_size / tex_size;
return image.Sample(textureSampler, pixelatedUV);
}

technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSPixelate(v_in);
}
}
10 changes: 8 additions & 2 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GPUTensorRT="GPU (TensorRT)"
GPUDirectML="GPU (DirectML)"
CoreML="CoreML"
NumThreads="Number of Threads"
ModelSize="Model Size"
ModelSize="Model"
SmallFast="Small (Fast)"
Medium="Medium"
LargeSlow="Large (Accurate)"
Expand All @@ -22,7 +22,7 @@ Blur="Blur"
OutputMask="Output Mask"
Transparent="Transparent"
MaskingColor="Masking Color"
MaskingBlurRadius="Masking Blur Radius"
MaskingBlurRadius="Blur / Pixelate Size"
TrackingZoomFollowGroup="Tracking (Zoom, Follow) Options"
ZoomFactor="Zoom Factor"
ZoomObject="Zoom Object"
Expand All @@ -40,3 +40,9 @@ CropLeft="Left"
CropTop="Top"
CropRight="Right"
CropBottom="Bottom"
Pixelate="Pixelate"
DilationIterations="Dilation"
Biggest="Biggest"
Oldest="Oldest"
FaceDetect="Face Detection"
MinSizeThreshold="Min. Object Area"
3 changes: 3 additions & 0 deletions src/FilterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ struct filter_data {
float conf_threshold;
std::string modelSize;

int minAreaThreshold;
int objectCategory;
bool maskingEnabled;
std::string maskingType;
int maskingColor;
int maskingBlurRadius;
int maskingDilateIterations;
bool trackingEnabled;
float zoomFactor;
float zoomSpeedFactor;
Expand All @@ -46,6 +48,7 @@ struct filter_data {
gs_stagesurf_t *stagesurface;
gs_effect_t *kawaseBlurEffect;
gs_effect_t *maskingEffect;
gs_effect_t *pixelateEffect;

cv::Mat inputBGRA;
cv::Mat outputPreviewBGRA;
Expand Down
1 change: 1 addition & 0 deletions src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const char *const USEGPU_COREML = "coreml";

const char *const KAWASE_BLUR_EFFECT_PATH = "effects/kawase_blur.effect";
const char *const MASKING_EFFECT_PATH = "effects/masking.effect";
const char *const PIXELATE_EFFECT_PATH = "effects/pixelate.effect";

const char *const PLUGIN_INFO_TEMPLATE =
"<a href=\"https://github.com/occ-ai/obs-detect/\">Detect Plugin</a> (%1) by "
Expand Down
Loading

0 comments on commit a41f024

Please sign in to comment.