Roboflow Workflows is a low-code laptop imaginative and prescient utility builder. With Workflows, you possibly can construct multi-step laptop imaginative and prescient workflows in a browser editor. You’ll be able to then deploy your Workflows utilizing the Roboflow API, a Devoted Deployment, or by yourself {hardware}.
On this information, we’ll discover how you can use conventional laptop imaginative and prescient methods to robotically blur your display throughout delicate moments, reminiscent of when switching between tabs or browsers. This may very well be utilized by dwell streamers to blur a display whereas switching tabs, decreasing the prospect a tab is by accident opened with delicate data seen.
Here’s a demo of the system in use:
Listed here are the steps we are going to comply with on this information:
- Create a workflow that calculates the dominant color in a area
- Arrange OBS
- Set up and import libraries
- Outline wanted variables
- Create blur operate that runs when the dominant color modifications, indicative of a tab change.
- Run the Workflow with OBS in your laptop
Let’s begin constructing!
Create a Workflow
Our finish workflow will look much like this:
First, create a brand new Workflow in your Roboflow account:
Subsequent, choose the customized Workflow choice.
Subsequent, choose Absolute Static Crop. This block permit us to focus our Workflow on a selected a part of a picture.
Subsequent, insert the x y and width and peak of the areas you’re detecting. This must be the area of the display that you just need to blur.
For my case, I used these values:
To retrieve these values, we advocate utilizing a screenshot device in your laptop to determine the x, y, width, and peak positions of the area you need to apply this device to.
Subsequent, add a dominant colour block. You will discover it by looking out it up within the workflow search bar.
Make it possible for the dominant colour block accepts the static crop block as an enter. Lastly, save the code block and save the deploy code.
Set Up OBS
With a purpose to document our display, we are going to want a digital digital camera supplier. In my case, I used OBS with a view to seize my display. We will arrange the digital digital camera on OBS by choosing the beginning digital digital camera class in OBS.
Now that now we have our digital digital camera arrange, we will lastly begin to code.
Set up and import libraries
Earlier than we start to code, let’s set up the wanted libraries.
!pip set up opencv-python inference
Import the libraries into a brand new Python script:
import cv2
from inference import InferencePipeline
from inference.core.interfaces.digital camera.entities import VideoFrame
Outline wanted variables
Now we have to outline the mandatory variables. We will probably be utilizing prev colour with a view to perceive what the earlier colour is. We use blur_frame_count with a view to depend what number of frames must be blurred throughout the course of.
prev_color = (255, 255, 255)
blur_frame_count = 0
Create blur operate
Subsequent, with a view to blur the display, we will probably be utilizing the GaussianBlur operate from the cv2 library. The area of curiosity (roi variable) would be the full picture. Throughout the operate, for each body blurred, we subtract the blurred body depend by 1.
def blur_screen():
roi = img
blurred_roi = cv2.GaussianBlur(roi, (15, 15), 0)
img = blurred_roi
print("Blurring utilized to the body.")
blur_frame_count -= 1
Create prediction operate
On this step, we are going to create a operate that may look by way of every body proven and relying on the present colour and former colour, it’ll blur the subsequent few frames. This operate will make the most of the outputs of our mannequin with a view to decide the colour of every tab.
The complete code snippet appears much like this:
def on_prediction(res: dict, body: VideoFrame) -> None:
world prev_color, blur_frame_count
img = body.picture
colour = res["dominant_color"] if colour[0] > (prev_color[0] + 10):
blur_frame_count = 3
print("Tabs modified, beginning blur...") if blur_frame_count > 0:
blur_screen() prev_color = res["dominant_color"] cv2.imshow("Display screen Blur", img) if cv2.waitKey(1) & 0xFF == ord("q"):
return
First, we set the prev_coor and blur_frame_count variables as world variables with a view to entry them within the operate.
Then, we set the picture.
Subsequent, utilizing our Workflow, we will get the dominant colour of the tab. If the colour distinction is over 10, then we all know that the tab has been switched. If this occurs, we set the blur_frame_count to three and name the operate blur_screen Three instances.
Lastly, we outline the earlier colour of the display and present the picture, whether or not it’s blurred or unblurred.
Import Workflow Code
Lastly, we will add the Workflow code with a view to join the Workflow with the Prediction operate.
pipeline = InferencePipeline.init_with_workflow(
video_reference=1,
workspace_name="nathan-yan",
workflow_id="WORKFLOW-ID”,
max_fps=60,
api_key="API_KEY",
on_prediction=on_prediction,
)
Ensure that to start out the pipeline by working the next code.
pipeline.begin()
Here’s a demo exhibiting our utility in use:
Conclusion
On this information, We discovered how you can blur tab modifications with a view to defend consumer privateness and data leakage. We additionally discovered how you can create a workflow with a view to make the most of conventional laptop imaginative and prescient methods. For extra tutorials and guides using workflows, take a look at some blogs.