bae705aa97
- Add NFC ePassport roadmap (ICAO 9303, eIDAS) - Add TensorFlow.js edge face detection (BlazeFace) - Add structured audit logger (GDPR-compliant) - Risk scoring support Part of KYC Apple Native UX v1.1.0
197 lines
6.6 KiB
Python
197 lines
6.6 KiB
Python
"""
|
|
Visual Geolocation Pipeline
|
|
Complete pipeline from image to precise geolocation
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, '/home/bernt/.openclaw/workspace/iom')
|
|
|
|
from typing import Dict, List, Optional, Tuple
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
import numpy as np
|
|
|
|
from visual_geolocation.evidence_extractor import EvidenceExtractor, EvidencePackage
|
|
from visual_geolocation.geolocation_engine import GeolocationEngine, GeolocationEstimate
|
|
from visual_geolocation.confidence_model import ConfidenceModel, ConfidenceReport
|
|
from visual_geolocation.ocr_pipeline import OCRPipeline
|
|
from visual_geolocation.map_matcher import MapMatcher
|
|
from visual_geolocation.similarity_search import SimilaritySearch
|
|
|
|
|
|
@dataclass
|
|
class GeolocationResult:
|
|
"""Complete geolocation result"""
|
|
lat: float
|
|
lng: float
|
|
accuracy: float
|
|
confidence: float
|
|
method: str
|
|
evidence_summary: Dict
|
|
confidence_report: ConfidenceReport
|
|
map_matches: List[Dict]
|
|
similar_images: List[Dict]
|
|
|
|
|
|
class VisualGeolocationPipeline:
|
|
"""
|
|
Complete visual geolocation pipeline
|
|
|
|
Flow:
|
|
1. Extract evidence (7 layers)
|
|
2. Geolocate (8 methods)
|
|
3. Calculate confidence
|
|
4. Match against maps
|
|
5. Find similar images
|
|
6. Return complete result
|
|
"""
|
|
|
|
def __init__(self, use_real_ai: bool = True):
|
|
self.evidence_extractor = EvidenceExtractor(use_real_ai=use_real_ai)
|
|
self.geolocation_engine = GeolocationEngine()
|
|
self.confidence_model = ConfidenceModel()
|
|
self.ocr_pipeline = OCRPipeline(engine="simulated")
|
|
self.map_matcher = MapMatcher()
|
|
self.similarity_search = SimilaritySearch()
|
|
|
|
def process_image(
|
|
self,
|
|
image_path: str,
|
|
image_id: Optional[str] = None
|
|
) -> GeolocationResult:
|
|
"""
|
|
Process image through complete pipeline
|
|
|
|
Returns precise geolocation with confidence
|
|
"""
|
|
print(f"Processing image: {image_path}")
|
|
print("=" * 60)
|
|
|
|
# Step 1: Extract evidence
|
|
print("\n[1/6] Extracting evidence...")
|
|
evidence = self.evidence_extractor.extract_all_evidence(image_path, image_id)
|
|
|
|
# Step 2: Geolocate
|
|
print("\n[2/6] Geolocating...")
|
|
estimate = self.geolocation_engine.geolocate(evidence)
|
|
|
|
# Step 3: Calculate confidence
|
|
print("\n[3/6] Calculating confidence...")
|
|
confidence_report = self.confidence_model.calculate_confidence(estimate, evidence)
|
|
|
|
# Step 4: Match against maps
|
|
print("\n[4/6] Matching against maps...")
|
|
map_matches = self.map_matcher.match_location(
|
|
estimate.lat,
|
|
estimate.lng,
|
|
evidence.to_dict(),
|
|
radius=estimate.accuracy * 2
|
|
)
|
|
|
|
# Step 5: Find similar images
|
|
print("\n[5/6] Finding similar images...")
|
|
similar_images = []
|
|
if evidence.visual_embedding is not None:
|
|
similar_images = self.similarity_search.search(
|
|
np.array(evidence.visual_embedding),
|
|
k=5
|
|
)
|
|
|
|
# Step 6: Compile result
|
|
print("\n[6/6] Compiling result...")
|
|
result = GeolocationResult(
|
|
lat=estimate.lat,
|
|
lng=estimate.lng,
|
|
accuracy=estimate.accuracy,
|
|
confidence=confidence_report.overall_confidence,
|
|
method=estimate.method,
|
|
evidence_summary={
|
|
"visual_objects": len(evidence.visual_objects),
|
|
"semantic_objects": len(evidence.semantic_objects),
|
|
"text_detections": len(evidence.text_detections),
|
|
"geometric_features": len(evidence.geometric_features),
|
|
"environmental_signals": len(evidence.environmental_signals)
|
|
},
|
|
confidence_report=confidence_report,
|
|
map_matches=[
|
|
{
|
|
"name": m.name,
|
|
"type": m.match_type,
|
|
"distance": m.distance,
|
|
"confidence": m.confidence
|
|
}
|
|
for m in map_matches[:5]
|
|
],
|
|
similar_images=[
|
|
{
|
|
"image_id": m.image_id,
|
|
"similarity": m.similarity,
|
|
"timestamp": m.timestamp
|
|
}
|
|
for m in similar_images[:5]
|
|
]
|
|
)
|
|
|
|
print("\n" + "=" * 60)
|
|
print("PIPELINE COMPLETE")
|
|
print("=" * 60)
|
|
|
|
return result
|
|
|
|
def print_result(self, result: GeolocationResult):
|
|
"""Print geolocation result"""
|
|
print(f"\n📍 GEOLOCATION RESULT")
|
|
print(f" Position: {result.lat:.6f}, {result.lng:.6f}")
|
|
print(f" Accuracy: ±{result.accuracy:.1f}m")
|
|
print(f" Confidence: {result.confidence:.1%}")
|
|
print(f" Method: {result.method}")
|
|
|
|
print(f"\n📊 EVIDENCE SUMMARY")
|
|
for key, value in result.evidence_summary.items():
|
|
print(f" {key}: {value}")
|
|
|
|
print(f"\n✅ CONFIDENCE REPORT")
|
|
print(f" Overall: {result.confidence_report.overall_confidence:.1%}")
|
|
print(f" Uncertainty: ±{result.confidence_report.uncertainty_radius:.1f}m")
|
|
print(f" Supporting evidence: {len(result.confidence_report.supporting_evidence)}")
|
|
print(f" Contradicting evidence: {len(result.confidence_report.contradicting_evidence)}")
|
|
print(f" Unknown factors: {len(result.confidence_report.unknown_factors)}")
|
|
|
|
if result.map_matches:
|
|
print(f"\n🗺️ MAP MATCHES")
|
|
for match in result.map_matches:
|
|
print(f" {match['name']} ({match['type']})")
|
|
print(f" Distance: {match['distance']:.1f}m, Confidence: {match['confidence']:.1%}")
|
|
|
|
if result.similar_images:
|
|
print(f"\n🖼️ SIMILAR IMAGES")
|
|
for img in result.similar_images:
|
|
print(f" {img['image_id']}: {img['similarity']:.1%} similarity")
|
|
|
|
|
|
# Example usage
|
|
def test_pipeline():
|
|
"""Test complete pipeline"""
|
|
print("=" * 60)
|
|
print("VISUAL GEOLOCATION PIPELINE")
|
|
print("=" * 60)
|
|
|
|
pipeline = VisualGeolocationPipeline(use_real_ai=True)
|
|
|
|
# Create test image
|
|
from PIL import Image
|
|
img = Image.new('RGB', (640, 480), color='blue')
|
|
img.save('/tmp/test_pipeline.jpg')
|
|
|
|
# Process image
|
|
result = pipeline.process_image('/tmp/test_pipeline.jpg', 'test_001')
|
|
|
|
# Print result
|
|
pipeline.print_result(result)
|
|
|
|
return result
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_pipeline()
|