Files
boc/iom/visual_geolocation/test_visual_geolocation.py
T
Bernt bae705aa97 ARCHITECTURE: NFC roadmap, edge AI, audit logging
- 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
2026-06-29 16:24:48 +00:00

164 lines
4.7 KiB
Python

"""
Test Visual Geolocation Pipeline
"""
import sys
sys.path.insert(0, '/home/bernt/.openclaw/workspace/iom')
from visual_geolocation.evidence_extractor import EvidenceExtractor, EvidencePackage
from visual_geolocation.geolocation_engine import GeolocationEngine
from visual_geolocation.confidence_model import ConfidenceModel
from datetime import datetime
def test_evidence_extraction():
"""Test evidence extraction"""
print("=== Testing Evidence Extraction ===\n")
extractor = EvidenceExtractor(use_real_ai=True)
# Test with dummy image
from PIL import Image
img = Image.new('RGB', (640, 480), color='blue')
img.save('/tmp/test_geo.jpg')
# Extract evidence
package = extractor.extract_all_evidence('/tmp/test_geo.jpg', 'test_001')
print(f"\nEvidence package:")
print(f" Image ID: {package.image_id}")
print(f" Timestamp: {package.timestamp}")
print(f" Visual objects: {len(package.visual_objects)}")
print(f" Semantic objects: {len(package.semantic_objects)}")
print(f" Text detections: {len(package.text_detections)}")
print(f" Geometric features: {len(package.geometric_features)}")
print(f" Environmental signals: {len(package.environmental_signals)}")
return package
def test_geolocation():
"""Test geolocation engine"""
print("\n=== Testing Geolocation Engine ===\n")
engine = GeolocationEngine()
# Create sample evidence with GPS
from visual_geolocation.evidence_extractor import ImageMetadata
evidence = EvidencePackage(
image_id="test_bangkok",
timestamp=datetime.now(),
metadata=ImageMetadata(
gps_lat=13.7563,
gps_lng=100.5018,
altitude=10.0
),
visual_objects=[],
semantic_objects=[],
text_detections=[],
geometric_features=[],
environmental_signals=[],
temporal_signals={}
)
# Geolocate
estimate = engine.geolocate(evidence)
print(f"Geolocation estimate:")
print(f" Lat: {estimate.lat}")
print(f" Lng: {estimate.lng}")
print(f" Accuracy: {estimate.accuracy}m")
print(f" Confidence: {estimate.confidence}")
print(f" Method: {estimate.method}")
return estimate
def test_confidence():
"""Test confidence model"""
print("\n=== Testing Confidence Model ===\n")
model = ConfidenceModel()
# Create sample evidence
from visual_geolocation.evidence_extractor import ImageMetadata, VisualObject, TextDetection
from visual_geolocation.geolocation_engine import GeolocationEstimate
evidence = EvidencePackage(
image_id="test_bangkok",
timestamp=datetime.now(),
metadata=ImageMetadata(
gps_lat=13.7563,
gps_lng=100.5018,
altitude=10.0,
compass_heading=90.0
),
visual_objects=[
VisualObject(label="street_light", confidence=0.85, bbox=[100, 200, 50, 150]),
VisualObject(label="building", confidence=0.92, bbox=[0, 0, 640, 480])
],
semantic_objects=[],
text_detections=[
TextDetection(text="Bangkok", confidence=0.95, bbox=[200, 100, 100, 50])
],
geometric_features=[],
environmental_signals=[],
temporal_signals={}
)
estimate = GeolocationEstimate(
lat=13.7563,
lng=100.5018,
accuracy=10.0,
confidence=0.9,
method="gps",
evidence={}
)
# Calculate confidence
report = model.calculate_confidence(estimate, evidence)
print(f"Confidence Report:")
print(f" Overall confidence: {report.overall_confidence:.2f}")
print(f" Uncertainty radius: {report.uncertainty_radius:.1f}m")
print(f" Supporting evidence: {len(report.supporting_evidence)}")
for ev in report.supporting_evidence:
print(f" - {ev['type']}: {ev['description']}")
print(f" Contradicting evidence: {len(report.contradicting_evidence)}")
print(f" Unknown factors: {len(report.unknown_factors)}")
for factor in report.unknown_factors:
print(f" - {factor}")
return report
def test_full_pipeline():
"""Test full visual geolocation pipeline"""
print("=" * 60)
print("FULL VISUAL GEOLOCATION PIPELINE TEST")
print("=" * 60)
# 1. Extract evidence
package = test_evidence_extraction()
# 2. Geolocate
estimate = test_geolocation()
# 3. Calculate confidence
report = test_confidence()
print("\n" + "=" * 60)
print("PIPELINE TEST COMPLETE")
print("=" * 60)
return {
"evidence": package,
"estimate": estimate,
"confidence": report
}
if __name__ == '__main__':
test_full_pipeline()