Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit a41f024

Browse files
authored
Merge pull request #20 from occ-ai/roy.pixelate_dilate_zoom_choices
feat: Add pixelate effect support for masking
2 parents 6ccfecb + 615f91c commit a41f024

File tree

8 files changed

+252
-69
lines changed

8 files changed

+252
-69
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ Current features:
3939

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

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

5555
## Train and use a custom detection model
5656

data/effects/pixelate.effect

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
uniform float4x4 ViewProj;
2+
uniform texture2d image;
3+
uniform texture2d focalmask;
4+
5+
uniform float pixel_size; // Size of the pixelation
6+
uniform float2 tex_size; // Size of the texture in pixels
7+
8+
sampler_state textureSampler {
9+
Filter = Linear;
10+
AddressU = Clamp;
11+
AddressV = Clamp;
12+
};
13+
14+
struct VertDataIn {
15+
float4 pos : POSITION;
16+
float2 uv : TEXCOORD0;
17+
};
18+
19+
struct VertDataOut {
20+
float4 pos : POSITION;
21+
float2 uv : TEXCOORD0;
22+
};
23+
24+
VertDataOut VSDefault(VertDataOut v_in)
25+
{
26+
VertDataOut vert_out;
27+
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
28+
vert_out.uv = v_in.uv;
29+
return vert_out;
30+
}
31+
32+
float4 PSPixelate(VertDataOut v_in) : TARGET
33+
{
34+
if (focalmask.Sample(textureSampler, v_in.uv).r == 0) {
35+
// No mask - return the original image value without any blur
36+
return image.Sample(textureSampler, v_in.uv);
37+
}
38+
39+
float2 pixelUV = v_in.uv * tex_size; // Convert to pixel coordinates
40+
float2 pixelatedUV = floor(pixelUV / pixel_size) * pixel_size / tex_size;
41+
return image.Sample(textureSampler, pixelatedUV);
42+
}
43+
44+
technique Draw
45+
{
46+
pass
47+
{
48+
vertex_shader = VSDefault(v_in);
49+
pixel_shader = PSPixelate(v_in);
50+
}
51+
}

data/locale/en-US.ini

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GPUTensorRT="GPU (TensorRT)"
77
GPUDirectML="GPU (DirectML)"
88
CoreML="CoreML"
99
NumThreads="Number of Threads"
10-
ModelSize="Model Size"
10+
ModelSize="Model"
1111
SmallFast="Small (Fast)"
1212
Medium="Medium"
1313
LargeSlow="Large (Accurate)"
@@ -22,7 +22,7 @@ Blur="Blur"
2222
OutputMask="Output Mask"
2323
Transparent="Transparent"
2424
MaskingColor="Masking Color"
25-
MaskingBlurRadius="Masking Blur Radius"
25+
MaskingBlurRadius="Blur / Pixelate Size"
2626
TrackingZoomFollowGroup="Tracking (Zoom, Follow) Options"
2727
ZoomFactor="Zoom Factor"
2828
ZoomObject="Zoom Object"
@@ -40,3 +40,9 @@ CropLeft="Left"
4040
CropTop="Top"
4141
CropRight="Right"
4242
CropBottom="Bottom"
43+
Pixelate="Pixelate"
44+
DilationIterations="Dilation"
45+
Biggest="Biggest"
46+
Oldest="Oldest"
47+
FaceDetect="Face Detection"
48+
MinSizeThreshold="Min. Object Area"

src/FilterData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ struct filter_data {
1717
float conf_threshold;
1818
std::string modelSize;
1919

20+
int minAreaThreshold;
2021
int objectCategory;
2122
bool maskingEnabled;
2223
std::string maskingType;
2324
int maskingColor;
2425
int maskingBlurRadius;
26+
int maskingDilateIterations;
2527
bool trackingEnabled;
2628
float zoomFactor;
2729
float zoomSpeedFactor;
@@ -46,6 +48,7 @@ struct filter_data {
4648
gs_stagesurf_t *stagesurface;
4749
gs_effect_t *kawaseBlurEffect;
4850
gs_effect_t *maskingEffect;
51+
gs_effect_t *pixelateEffect;
4952

5053
cv::Mat inputBGRA;
5154
cv::Mat outputPreviewBGRA;

src/consts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const char *const USEGPU_COREML = "coreml";
99

1010
const char *const KAWASE_BLUR_EFFECT_PATH = "effects/kawase_blur.effect";
1111
const char *const MASKING_EFFECT_PATH = "effects/masking.effect";
12+
const char *const PIXELATE_EFFECT_PATH = "effects/pixelate.effect";
1213

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

0 commit comments

Comments
 (0)