PuriPuri Live

Home of the Puri Stream and PSXplosion
PuriPuri Live

OBS Lightgun Flash Filter (v1.0)

Lightgun Flash Filter for OBS
by Eric ‘Puri_Puri’
Twitter: @3fg_inc
Site: https://puripuri.live

DOWNLOAD: https://puripuri.live/puri_utilities/2022/obs-flash-filter-v1.0.zip

What this is:
A video filter that detects and removes full-screen flashes in captured video, intended for lightgun games that flash the screen whenever the player shoots.

REQUIRES 64-BIT WINDOWS OBS
Tested with Windows 64-bit OBS versions 27.2.4 and 28.0.2

HOW TO INSTALL:
Extract the three files to your OBS install’s plugin\64bit directory
Typically: C:\Program Files\obs-studio\obs-plugins\64bit

obs-flash-filter.dll (OBS filter plugin)
opencv_core454.dll (OpenCV version 4.54 core library)
opencv_imgproc454.dll (OpenCV version 4.54 image processing library)

Known Issues:
– If you are playing on MiSTer FPGA (or any system that draws a crosshair) make sure to disable the crosshair, otherwise it will mess up the algorithm.
– Time Crisis 3 [PS2] has very odd flashes that fade in and out, which is very hard to filter. Will take another looks at it in the future.
– Sometimes crashes when closing OBS. I am not sure why 😅
– Might be a memory leak or two, maybe. Not actually sure.

Modes:
1) Generic 1 4:3 Full screen (Default)
– This is the main operating mode for the filter, and should work with nearly everything. Mainly tested on PSX games that flash the entire screen.

2) Generic 2 Cropped 64px x 64px Center Screen
– Same as Generic 1, but samples a smaller area in the center of the screen. Some games draw the UI over the screen flash, so this accounts for that. Also is faster than the Generic 1 preset, so use if you are having frame drops.
– Intended for: Project Horned Owl [PSX]

3) NES Type 1
– NES Zapper blanks the screen except for a white rectangle for a few frames, then goes back to the game. This detects the flash, then waits for 3 frames before drawing again.
– Intended for: Duck Hunt [NES]

4) NES Type 2
– This variation of the Zapper flashes the entire screen white, then blanks the screen except for a white rectangle. This detects the flash, then waits for 4 frames before drawing again.

5) CUSTOM 1
– This is mainly for playing with the filter. Set the “mean” slider as high as it will go without letting flashes through.

6) CUSTOM 2
– This is mainly for playing with the filter. Set the “stdDev” slider as low as it will go without letting flashes through.

How it works:
New frame
Frame converted to OpenCV Mat in BGR colorspace
Mat converted to HSV colorspace
HSV Mat split into Hue, Saturation, and Value Mats
Value is run through the meanStdDev function to get the average and standard deviation for the entire Value image
Generic:
If the standard deviation is below 5.0 (out of 255.0), then it is probably a flash frame, so discard the frame
NES:
Standard Deviation below 1 OR above 120 is the start of the flash animation, so discard the next 3 to 4 frames.
If it found a flash frame, then just destroy the frame and return NULL (result is showing the last non-flash frame)
Otherwise, draw the frame as-is.