class SmartCameraApp:
def __init__(self):
self.model = MobileNet()
self.cap = cv2.VideoCapture(0)
def detect_objects_continuous(self):
while True:
ret, frame = self.cap.read()
if not ret:
continue
# Fast inference
results = self.model.inference(frame)
# Display results
if results['predictions']:
top_pred = results['predictions'][0]
# Only show high-confidence predictions
if top_pred['confidence'] > 0.3:
self.display_prediction(frame, top_pred)
# Show FPS
fps = 1.0 / results['inference_time']
cv2.putText(frame, f"FPS: {fps:.1f}", (10, 70),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
cv2.imshow('Smart Camera', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
def display_prediction(self, frame, prediction):
text = f"{prediction['class']}: {prediction['confidence']:.2f}"
cv2.putText(frame, text, (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
# Run the app
app = SmartCameraApp()
app.detect_objects_continuous()