05Feb

AgriShield

 

Farm security cameras are increasingly used to monitor entrances and detect intruders. While these systems improve safety, they also capture authorized workers and family members, raising privacy concerns. At AgriShield, we are exploring whether real-time, privacy-preserving computer vision can run entirely on edge hardware, like a Raspberry Pi, while maintaining performance and usability.

 

Imagine a farm where a single camera watches a barn entrance all day. Workers pass by dozens of times during routine tasks like feeding animals, moving equipment, or even just checking a gate. A traditional camera system records all of this footage continuously—even when nothing suspicious is happening. Identifiable videos of workers and owners are stored, reviewed, and transmitted, often without their own consent or comfort. Agrishield is designed to reduce unnecessary exposure while still keeping the camera useful for security purposes.

 

This blog entry highlights the current implementation, which focuses on face detection and anonymization. Identity recognition, alerting, and storage are planned for future work, but the existing system already demonstrates the feasibility of edge-based privacy protection.

System Overview

Our prototype pipeline is built to run on a Raspberry Pi 5 (8GB) using:

  • OpenCV: Video capture, frame processing, and display.
  • MediaPipe Face Detection: Lightweight, accurate long-range face detection.
  • NumPy: Pixel-level operations for image manipulation.

 

Camera input can come from any USB webcam or RTSP-compatible device (like TP-Link or Wyze cameras). The system is designed to run entirely locally, with no cloud dependency, ensuring fast, real-time processing and keeping sensitive video data on-device.

 

By running it all locally, the video never has to leave the farm. Nothing gets uploaded to the internet, there’s no remote server that stores the footage, and no third-party services analyzing the faces in the recordings. This reduces privacy risk and operational costs and improves reliability in rural areas with limited connectivity.


Live Video & Face Detection

The main loop continuously captures frames from the camera. Each frame undergoes:

  1. Bilateral filtering for noise reduction, which decreases false positives in face detection.
  2. Conversion from BGR to RGB for MediaPipe processing.
  3. Optional frame upscaling to improve detection of small or distant faces.

 

MediaPipe outputs relative bounding boxes for detected faces, which are mapped back to the original frame resolution. Boxes are clamped to frame boundaries to prevent indexing errors. This setup ensures robust detection and smooth frame rates on resource-constrained hardware.


Privacy-Preserving Face Obfuscation

The heart of the system is the circular_blur function, which anonymizes detected faces while preserving natural-looking boundaries.

 

Instead of placing a black box over someone’s face, the system behaves more like frosted glass that is shaped exactly to the targeted face. You can tell when a person is in the frame and see their movements/posture, but you can’t recognize who the person specifically is.

 

The steps are:

  1. Region expansion: The face bounding box is padded to avoid square artifacts.
  2. Pixelation: Downscale and upscale the region to remove fine facial features.
  3. Gaussian blur: Apply a heavy blur to smooth the pixelated region.
  4. Random jitter: Small spatial shifts scramble the pixelated pattern, preventing reconstruction.
  5. Face-aligned elliptical mask: Masks the obfuscation to the shape of the face.
  6. Feathered edges and edge fade: Smoothly fade the mask to avoid visible square edges.
  7. Merge back: Replace the original face region with the anonymized version in the frame.

 

This multi-layer approach produces an artifact-free, face-shaped anonymization in real time, even on a Raspberry Pi.


System Control & Visualization

The prototype provides interactive feedback for developers and demo purposes:

  • Live preview window: Displays the current frame with anonymized faces.
  • Keyboard controls:
    • SPACE: Toggle privacy mode on/off
    • Q: Quit the program
  • Bounding boxes: In monitoring mode, boxes can be color-coded based on bounding box size (as a rough proxy for distance).

 

Seeing the system working in real time allows validation of privacy’s consistent application, whether someone is close, far from, or partially visible to the camera. The setup allows real-time testing of detection and anonymization behavior, ensuring that privacy logic works consistently across different face sizes and positions.


What This Prototype Demonstrates

  • Edge-capable face detection: MediaPipe and OpenCV handle real-time detection on constrained hardware.
  • High-quality anonymization: Pixelation, blur, jitter, and face-shaped masking protect identities effectively.
  • Modular pipeline: Detection → anonymization → display is robust and maintainable.
  • Artifact-free privacy: Expanded ROI and feathered edges eliminate square borders, improving perceptual privacy.

 

The prototype shows how cameras don’t have to be in an “all or nothing”-type of situation. The system can still monitor spaces while respecting the individuals who belong in the environment.

 

Even without identity recognition or alerting, the current system proves that privacy-preserving computer vision can work entirely on-device.


Next Steps

Future enhancements will build on this foundation:

  • Add identity-aware selective privacy, anonymizing only authorized individuals.
  • Implement event-driven storage and alerting for unknown faces.
  • Create a dashboard for monitoring alerts and reviewing events.
  • Conduct quantitative evaluation: FPS, detection accuracy, and privacy-utility trade-offs.

The current prototype ensures a strong foundation for selective, GDPR-aligned privacy on the edge.


AgriShield demonstrates that privacy and security can coexist in farm surveillance, and that even a Raspberry Pi can deliver high-quality, real-time anonymization without cloud dependencies.

Related Blogs