Skip to content

Activate overlay to hide parts of the screen

WarmUpTill edited this page Mar 6, 2023 · 6 revisions

The following example will use pattern matching to make sure certain elements of the screen are hidden if a particular pattern can be found. We will use hiding the production tab in Starcraft 2 whenever an a certain unit is built - regardless of how many - as an example.

The following scene / source setup will be used to achieve this behaviour:

OBSOverlayActive

  • A single example scene (1)
  • A color source used to block certain parts of the screen, to indicate that the macro successfully matched the pattern (2)
  • A game/display capture source to capture the gameplay (3)

Toggling the visibility of the color source will either show or hide the production tab, by overlaying a grey box over top off it.

Next we need a pattern to match - for this example we will use the "Marine" icon.
This image was created by simply taking a screenshot of the video source and cutting it down to the needed size.

SC2Pattern

You can also automatically create a screenshot of the given source by clicking the "Browse" button (3) of the file selection in the image below.
If you already have selected the area you want to perform the check on the screenshot will be resized automatically.

Once the pattern is ready we can create our macros to automate the showing and hiding of the color source overlay. We start by creating a macro to show the color source if the pattern is found:

VideoCondition1

First we create a video condition and select "Display Capture" as the video source to analyze (1), "matches pattern" as the type of check we want to perform (2), and which pattern file we want to use (3).
Next we add an action of type "Scene item visibility" to show the color source if the above condition is met. (4)

While this might already work as expected we can tweak the settings of video condition for better results and performance:

VideoCondition2

First we reduce the interval at which this conditions is checked to roughly only once a second (1) and we reduce the area that needs to be checked to only cover the area where we expect the pattern to occur (2).

An additional improvement that could be made to avoid false positives would be to improve the pattern.
By replacing the area at which the number is being displayed to represent the number of units of that type being produced with an transparent rectangle we can effectively ignore this part of the pattern.

VideoCondition3

To achieve this we create a new pattern:

SC2PatternWithAlpha

... and select it in the video condition (1).
Then we check the "Use alpha channel as mask for pattern" option. Note that the pattern file should be exported with transparency, so the file format should support transparency, like png.

Next we have to tweak the "Threshold" value to be used.
This is best done by clicking the "Show match" option and playing back some example footage.
If the pattern can be found it will be highlighted in a red box.

As a last step we create the inverse of the "Show overlay" macro to automatically hide the overlay if the pattern cannot be found:

Hideoverlay

Instead of once again performing the same pattern matching we can reuse the results of the checks of the "Show overlay" macro by using a condition of type "Macro" of type "State". (1)
This will safe CPU resources and will also avoid conflicts if you change some parameters on one macro but not the other. Now we just need to add the action to hide the overlay (2) and everything should be set up.

Make sure that the scene switcher is running and enjoy your automatic overlay toggling! :)

Example guides

Explanations

Clone this wiki locally