Enhance Image Privacy with the kharioki/blur-faces Cognitive Actions

21 Apr 2025
Enhance Image Privacy with the kharioki/blur-faces Cognitive Actions

In the digital age, protecting privacy while managing visual content is essential. The kharioki/blur-faces Cognitive Actions offer a straightforward way to apply blur filters to images, helping to enhance privacy or draw focus to specific areas within an image. This blog post will guide you through the integration of the "Add Blur Filter to Image" action, enabling you to seamlessly incorporate this capability into your applications.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following setup:

  • API Key: You will need an API key to authenticate your requests.
  • Environment: Make sure you have an environment that can send HTTP requests, such as a Python setup with the requests library.

Authentication is typically done by passing your API key in the request headers.

Cognitive Actions Overview

Add Blur Filter to Image

Description: This action applies a customizable blur filter to an image, enhancing privacy or emphasizing specific areas.

Category: Image Processing

Input

The input for this action requires the following fields:

  • inputImage (required): A valid URI pointing to the image you want to process.
  • blur (optional): A number indicating the radius of the blur effect, defaulting to 5. Larger values result in a stronger blur.

Example Input:

{
  "blur": 5,
  "inputImage": "https://replicate.delivery/pbxt/J1sfRLwQpduwTZtdBV6o15BzrEpF7aAJl6FatWNX8vmX6otU/Namor%20dans%20Black%20Panther%20Wakanda%20Forever.jpeg"
}

Output

The output is a URI to the processed image with the blur effect applied.

Example Output:

https://assets.cognitiveactions.com/invocations/1b17b87e-73aa-4668-addb-4425232f5ae7/0e8b1553-00e0-40d2-b206-f8bf0348935a.png

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call this action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "a859f0b2-519f-4375-92e5-7cb5b28280e6" # Action ID for Add Blur Filter to Image

# Construct the input payload based on the action's requirements
payload = {
    "blur": 5,
    "inputImage": "https://replicate.delivery/pbxt/J1sfRLwQpduwTZtdBV6o15BzrEpF7aAJl6FatWNX8vmX6otU/Namor%20dans%20Black%20Panther%20Wakanda%20Forever.jpeg"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the required input, including the blur radius and image URI. The endpoint URL and request structure are illustrative; make sure to adjust them based on your actual implementation and provider's specifications.

Conclusion

The kharioki/blur-faces Cognitive Actions provide a valuable toolset for developers looking to enhance image privacy in their applications. By integrating the "Add Blur Filter to Image" action, you can ensure that sensitive content is protected while maintaining control over the visual narrative. Explore potential use cases like social media applications, content management systems, or any platform where image privacy is a priority.