-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathai_camera_recognition.py
More file actions
50 lines (43 loc) · 1.56 KB
/
ai_camera_recognition.py
File metadata and controls
50 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cv2
import numpy as np
# -------------------------
# AI RECOGNITION VIA CAMERA
# -------------------------
def recognize_ai_from_camera(model_path=None):
"""
Attempts to recognize a user's AI (e.g., a visual marker, QR code, or face) using the webcam.
If a model_path is provided, loads a custom AI recognition model (placeholder for extension).
"""
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Camera not accessible.")
return None
print("Press 'q' to quit.")
recognized = False
while True:
ret, frame = cap.read()
if not ret:
print("Failed to capture frame.")
break
# Example: Try to detect a QR code as a stand-in for AI identity
detector = cv2.QRCodeDetector()
data, bbox, _ = detector.detectAndDecode(frame)
if bbox is not None and data:
print(f"AI Identity Detected: {data}")
recognized = True
cv2.polylines(frame, [np.int32(bbox)], True, (0,255,0), 2)
cv2.putText(frame, f"AI: {data}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)
else:
cv2.putText(frame, "No AI detected", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)
cv2.imshow('AI Recognition', frame)
if cv2.waitKey(1) & 0xFF == ord('q') or recognized:
break
cap.release()
cv2.destroyAllWindows()
if recognized:
return data
else:
print("No AI identity recognized.")
return None
if __name__ == "__main__":
recognize_ai_from_camera()