Real-world code examples for integrating Harpoon 1.1 into defense systems
Add AI drone detection to your existing Python surveillance system
# Basic drone detection integration
from harpoon import DroneDetector
import cv2
# Initialize detector
detector = DroneDetector("harpoon_v1.1.onnx", device="cuda")
# Process single image
image = cv2.imread("camera_frame.jpg")
detections = detector.detect(image, confidence=0.6)
# Handle detections
for detection in detections:
x1, y1, x2, y2 = detection.bbox
confidence = detection.confidence
print(f"Drone detected: {confidence:.2f} at [{x1},{y1},{x2},{y2}]")
# Alert your existing security system
security_system.send_alert(detection)
# Advanced integration with tracking
from harpoon import DroneDetector, DroneTracker
import numpy as np
class DefenseSystem:
def __init__(self):
self.detector = DroneDetector("harpoon_v1.1.onnx")
self.tracker = DroneTracker()
self.threat_threshold = 0.7
def process_frame(self, frame):
# Detect drones
detections = self.detector.detect(frame)
# Update tracking
tracked_objects = self.tracker.update(detections)
# Assess threats
for obj in tracked_objects:
if obj.confidence > self.threat_threshold:
self.handle_threat(obj)
def handle_threat(self, threat):
# Integration with defense systems
threat_data = {
'position': threat.bbox,
'confidence': threat.confidence,
'track_id': threat.id,
'velocity': threat.velocity
}
# Send to command center
self.notify_command_center(threat_data)
# Activate countermeasures if needed
if threat.confidence > 0.9:
self.activate_countermeasures(threat)
# Real-time streaming integration
import asyncio
from harpoon import AsyncDroneDetector
async def stream_processor():
detector = AsyncDroneDetector("harpoon_v1.1.onnx")
# Connect to your camera stream
stream_url = "rtsp://camera.local/stream"
async for frame in camera_stream(stream_url):
# Non-blocking detection
detections = await detector.detect_async(frame)
# Process results immediately
if detections:
await handle_detections(detections)
async def handle_detections(detections):
for detection in detections:
# Send real-time alerts
await alert_system.notify_async(detection)
# Update dashboard
await dashboard.update_threats(detection)
# Run the stream processor
asyncio.run(stream_processor())
Integrate with existing C++ surveillance infrastructure
#include "harpoon/detector.h"
#include "harpoon/types.h"
#include
class SurveillanceSystem {
private:
harpoon::DroneDetector detector;
public:
SurveillanceSystem() : detector("harpoon_v1.1.onnx") {}
void processFrame(const cv::Mat& frame) {
// Detect drones with Harpoon
auto detections = detector.detect(frame, 0.6f);
for (const auto& detection : detections) {
handleDetection(detection);
}
}
void handleDetection(const harpoon::Detection& detection) {
// Extract detection data
auto bbox = detection.getBoundingBox();
float confidence = detection.getConfidence();
// Integrate with existing alert system
AlertData alert{
.x = bbox.x,
.y = bbox.y,
.width = bbox.width,
.height = bbox.height,
.confidence = confidence,
.timestamp = std::chrono::system_clock::now()
};
// Send to command center
commandCenter.sendAlert(alert);
// Log to database
database.logThreat(alert);
}
};
// Usage in your main surveillance loop
int main() {
SurveillanceSystem system;
cv::VideoCapture cap(0); // Your camera
cv::Mat frame;
while (cap.read(frame)) {
system.processFrame(frame);
}
return 0;
}
Integrate via HTTP API calls from any programming language
# Deploy Harpoon API server
docker run -p 8080:8080 chiliadresearch/harpoon:api-v1.1
# Send image for detection
curl -X POST http://localhost:8080/detect \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@camera_frame.jpg" \
-F "confidence=0.6"
# Response:
# {
# "detections": [
# {
# "bbox": [100, 150, 200, 250],
# "confidence": 0.87,
# "class": "drone",
# "track_id": null
# }
# ],
# "processing_time": 0.023,
# "model_version": "1.1.0"
# }
# Python API client integration
import requests
import cv2
import json
class HarpoonAPIClient:
def __init__(self, api_url, api_key):
self.api_url = api_url
self.headers = {"Authorization": f"Bearer {api_key}"}
def detect_drones(self, image_path, confidence=0.6):
with open(image_path, 'rb') as img_file:
files = {'image': img_file}
data = {'confidence': confidence}
response = requests.post(
f"{self.api_url}/detect",
headers=self.headers,
files=files,
data=data
)
return response.json()
def stream_detect(self, camera_url):
cap = cv2.VideoCapture(camera_url)
while True:
ret, frame = cap.read()
if not ret:
break
# Save frame temporarily
cv2.imwrite('temp_frame.jpg', frame)
# Send for detection
results = self.detect_drones('temp_frame.jpg')
# Process results
if results['detections']:
self.handle_detections(results['detections'])
# Usage
client = HarpoonAPIClient("http://harpoon-api:8080", "your-api-key")
client.stream_detect("rtsp://camera.local/stream")
// JavaScript/Node.js integration
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
class HarpoonClient {
constructor(apiUrl, apiKey) {
this.apiUrl = apiUrl;
this.headers = { Authorization: `Bearer ${apiKey}` };
}
async detectDrones(imagePath, confidence = 0.6) {
const formData = new FormData();
formData.append('image', fs.createReadStream(imagePath));
formData.append('confidence', confidence);
try {
const response = await axios.post(
`${this.apiUrl}/detect`,
formData,
{
headers: {
...this.headers,
...formData.getHeaders()
}
}
);
return response.data;
} catch (error) {
console.error('Detection failed:', error.message);
throw error;
}
}
async streamDetection(wsUrl) {
const WebSocket = require('ws');
const ws = new WebSocket(wsUrl, {
headers: this.headers
});
ws.on('message', (data) => {
const detection = JSON.parse(data);
this.handleDetection(detection);
});
return ws;
}
handleDetection(detection) {
if (detection.confidence > 0.7) {
// Send alert to security system
this.sendSecurityAlert(detection);
}
// Update monitoring dashboard
this.updateDashboard(detection);
}
}
// Usage
const client = new HarpoonClient('http://localhost:8080', 'your-api-key');
client.detectDrones('./camera_frame.jpg').then(console.log);
Real Docker containers deployed to DockerHub - instant deployment
# Complete real-time drone detection with GUI
# Performance: 12.2 FPS, 83ms inference, multi-drone tracking
# Pull and run the complete system
docker run -it --rm \
--device=/dev/video0 \
--privileged \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v /dev/shm:/dev/shm \
christiankhoury05/harpoon-1.1-final:latest
# Features:
# β
Real-time webcam detection
# β
Green bounding boxes around drones
# β
Multi-drone tracking (up to 4 simultaneous)
# β
96.6% accuracy, 12.2 FPS performance
# β
Console output with confidence scores
# β
Cross-platform support (Linux/macOS/Windows)
# Lightweight API server for system integration
# Perfect for adding to existing surveillance systems
# Pull and run API server
docker run -d -p 8080:8080 \
--name harpoon-api \
christiankhoury05/harpoon-model-api:1.1
# Test the API
curl -X POST -F "file=@drone_image.jpg" \
http://localhost:8080/detect
# Response format:
# {
# "detections": [
# {
# "bbox": [x1, y1, x2, y2],
# "confidence": 0.94,
# "class": "drone"
# }
# ],
# "inference_time": 83.2,
# "image_size": [640, 640]
# }
# Health check
curl http://localhost:8080/health
# Custom integration using Harpoon as base
FROM christiankhoury05/harpoon-model-api:1.1
# Add your custom security system integration
COPY security_integration.py /app/
COPY alert_system.py /app/
COPY config.yaml /app/config/
# Install additional dependencies
RUN pip install pika redis celery
# Custom startup script
COPY start_custom.sh /app/
RUN chmod +x /app/start_custom.sh
# Environment variables for your system
ENV ALERT_WEBHOOK_URL=""
ENV REDIS_URL="redis://localhost:6379"
ENV SECURITY_SYSTEM_API=""
# Custom entrypoint
CMD ["/app/start_custom.sh"]
Actual console output from Harpoon 1.1 Final detecting multiple drones
# Real console output from production system
π¨ DRONE DETECTED! Count: 4 | Frame: 291
π― Drone 1: 47.361 confidence
π― Drone 2: 4.229 confidence
π― Drone 3: 96.426 confidence
π― Drone 4: 8.263 confidence
π¨ DRONE DETECTED! Count: 4 | Frame: 292
π― Drone 1: 46.302 confidence
π― Drone 2: 4.268 confidence
π― Drone 3: 94.217 confidence
π― Drone 4: 8.337 confidence
π¨ DRONE DETECTED! Count: 4 | Frame: 293
π― Drone 1: 45.628 confidence
π― Drone 2: 4.261 confidence
π― Drone 3: 92.093 confidence
π― Drone 4: 8.342 confidence
π Session Complete
π Session stats: 317 frames, avg 91.1ms per frame
π― Total detection events: 1268
β‘ Average FPS: 11.0
π― Multi-drone tracking: Up to 4 simultaneous
π Peak confidence: 96.6%
1,268 events in 317 frames = 4+ detections per frame average
4 simultaneous drones tracked with individual confidence scores
91.1ms average per frame = 11 FPS sustained performance
4.2% - 96.6% range allows fine-tuned threat assessment
Scalable enterprise deployment with auto-scaling
# harpoon-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: harpoon-api
labels:
app: harpoon
spec:
replicas: 3
selector:
matchLabels:
app: harpoon
template:
metadata:
labels:
app: harpoon
spec:
containers:
- name: harpoon-api
image: chiliadresearch/harpoon:api-v1.1
ports:
- containerPort: 8080
env:
- name: MODEL_PATH
value: "/models/harpoon_v1.1.onnx"
- name: CUDA_VISIBLE_DEVICES
value: "0"
resources:
requests:
memory: "2Gi"
cpu: "1000m"
nvidia.com/gpu: 1
limits:
memory: "4Gi"
cpu: "2000m"
nvidia.com/gpu: 1
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: harpoon-service
spec:
selector:
app: harpoon
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: harpoon-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: harpoon-api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70