New Middleware: Connecting Blue Iris to AI Backends (Starting with Roboflow) - Need Help Sending Camera ID!

hax0rsaw

n3wb
May 2, 2023
3
3
Wonder Lake, IL
Hi IPCamTalk Community,

I've developed a middleware application aimed at enhancing Blue Iris's AI capabilities by allowing it to connect to external object detection services, and I'd love to share the concept and ask for help with a specific configuration challenge.

The Vision: A Flexible AI Bridge for Blue Iris

The core idea is a Python (FastAPI) application that acts as a translation layer. It receives alerts from Blue Iris in the standard CodeProject.AI format but then routes the detection task to a configured backend AI service. The goal is to eventually support various backends (different models, local services, cloud APIs), allowing users more flexibility in their choice of AI.

Current Implementation: Roboflow Integration

The initial version focuses specifically on integrating with Roboflow object detection models (tested primarily with their local inference server via inference-sdk, though cloud also works).

How it Works (Current Roboflow Version):

  1. Receives Blue Iris Alerts: Listens on /v1/vision/detection, accepting multipart/form-data requests from Blue Iris's AI alert actions, just like CodeProject.AI.
  2. Sends to Roboflow: Extracts the image and sends it to the configured Roboflow model/endpoint for detection.
  3. Fallback: Includes an optional fallback to a standard CodeProject.AI server if Roboflow fails or returns no detections.
  4. Processes Results: Takes the JSON response from Roboflow.
  5. Coordinate Scaling (The Goal): This is where the core enhancement lies. It attempts to scale the bounding box coordinates returned by Roboflow.
  6. Returns CPAI Format: Sends a JSON response back to Blue Iris formatted like a standard CodeProject.AI response. It can also return an annotated image if requested via Accept: image/*.
  7. Logs & Dashboard: Stores detection history (including images) in an SQLite database and provides a basic web dashboard for viewing history/stats.
The Problem I'm Trying to Solve: Accurate Bounding Boxes

A key objective is to have the middleware return bounding box coordinates that are scaled correctly for the originating camera's specific resolution. This ensures Blue Iris overlays the boxes accurately, even with a mix of different camera resolutions.

My middleware currently scales coordinates, but it uses a static target resolution defined in its config file. This leads to misplaced bounding boxes in Blue Iris whenever a camera's actual resolution doesn't match that static target.

The Challenge: Getting the Camera Identity

To implement dynamic scaling based on the actual camera resolution, the middleware needs to know the short name of the camera that triggered the alert for each request. With the camera name, it could query the Blue Iris API (/json?cmd=camlist) to fetch the correct width and height for scaling.

I know the standard Blue Iris method is to use the &CAM macro in the AI configuration (Alert Action -> Send to web server or AI tab) and send it as a multipart/form-data field, like:

camera=&CAM

Where I Need Help (Based on Logs):

I've added detailed DEBUG logging to the middleware's /v1/vision/detection endpoint. The logs confirm:

  1. Blue Iris is sending the request correctly as multipart/form-data.
  2. My middleware is ready to accept form fields named camera and requestId.
  3. However, the logs clearly show that for the requests being sent by my Blue Iris instance, neither the camera form field nor a requestId form field is being included. The middleware receives None for both.
My Specific Question:

Could someone in the community provide specific guidance, perhaps even screenshots, on configuring the Blue Iris v5 Alert Action (e.g., the "Send to web server" action or the settings on the main AI tab when pointing to a custom server) to ensure it includes the &CAM macro's value as a form field named camera in the multipart/form-data request?

It feels like I'm missing a specific setting or step in the Blue Iris UI to make it add this crucial field to the outgoing request. Getting this identifier reliably is the necessary prerequisite for implementing the dynamic scaling feature.

I'm happy to share relevant Python/FastAPI code snippets or more detailed logs if it helps.

Thanks for reading and for any assistance you can offer!
 
  • Like
Reactions: aesterling