This directory contains plugins for the Securade.ai HUB camera processing system. Plugins provide different ways to process and analyze camera feeds, from basic image processing to complex computer vision tasks.
The plugin system allows you to create custom image processing modules that can be dynamically loaded and selected in the HUB interface. Each plugin receives an input image and can return a processed/annotated version of that image.
To create a new plugin:
- Create a new Python file in this directory (e.g.,
my_plugin.py
) - Import the base plugin class:
from plugins.base_plugin import BasePlugin
- Create your plugin class that inherits from
BasePlugin
- Implement the required properties and methods
Here's a template for a new plugin:
import numpy as np
from plugins.base_plugin import BasePlugin
class MyPlugin(BasePlugin):
# Unique identifier for your plugin
SLUG = "my_plugin"
# Display name that will appear in the UI
NAME = "My Custom Plugin"
def run(self, image: np.ndarray, **kwargs) -> np.ndarray:
"""Process the input image
Args:
image: Input image as numpy array (RGB format)
**kwargs: Additional arguments passed from the UI
Returns:
Processed image as numpy array (RGB format)
"""
# Your image processing code here
processed_image = image # Replace with actual processing
return processed_image
SLUG
: A unique string identifier for your plugin (lowercase, no spaces)NAME
: A human-readable name that will be displayed in the UIrun(self, image, **kwargs)
: The main processing method that receives and returns an image
Your plugin can access additional arguments through the kwargs
parameter. The system provides several common arguments:
def run(self, image: np.ndarray, **kwargs) -> np.ndarray:
# Access YOLO detector if needed
detector = kwargs.get('yolo_detector')
# Access other optional parameters
param1 = kwargs.get('param1', default_value)
param2 = kwargs.get('param2')
# Check if required parameters are provided
if param2 is None:
raise ValueError("Plugin requires 'param2' parameter")
Demonstrates how to use the YOLOv7 detector for object detection:
class YOLODetector(BasePlugin):
SLUG = "yolo_detector"
NAME = "YOLO Object Detector"
def run(self, image: np.ndarray, **kwargs) -> np.ndarray:
detector = kwargs.get('yolo_detector')
detector.load_cv2mat(image)
detector.inference()
return detector.image.copy()
Shows how to implement basic image processing using OpenCV:
class EdgeDetector(BasePlugin):
SLUG = "edge_detector"
NAME = "Edge Detector"
def run(self, image: np.ndarray, **kwargs) -> np.ndarray:
threshold1 = kwargs.get('threshold1', 100)
threshold2 = kwargs.get('threshold2', 200)
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
edges = cv2.Canny(gray, threshold1, threshold2)
return cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
- Error Handling: Handle missing dependencies and invalid parameters gracefully
- Documentation: Include docstrings and comments explaining your plugin's functionality
- Input Validation: Verify input image format and required parameters
- Performance: Optimize processing for real-time video analysis when possible
- Memory Management: Clean up resources and avoid memory leaks
Your plugins can use these pre-installed libraries:
- OpenCV (cv2)
- NumPy
- PyTorch
- Other common Python libraries
- Print statements will appear in the server console
- Use try/except blocks to catch and log errors
- Test your plugin with different image sizes and formats
- Verify your plugin works with both still images and video streams
When contributing new plugins:
- Follow the naming conventions and code style of existing plugins
- Include example usage and documentation
- Test thoroughly with different inputs
- Update this README if adding new features or dependencies