Spaces:
Runtime error
Runtime error
| ```bash | |
| pip install opencv-python face-recognition simple-salesforce | |
| ``` | |
| ### Python Code | |
| ```python | |
| import cv2 | |
| import face_recognition | |
| import os | |
| from simple_salesforce import Salesforce | |
| from datetime import datetime | |
| # Salesforce connection | |
| sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token') | |
| # Function to query Salesforce for PAN and Aadhar match | |
| def query_salesforce(pan, aadhaar): | |
| # Query staff | |
| staff_query = f"SELECT Id, Name FROM Staff__c WHERE PAN__c = '{pan}' OR Aadhar__c = '{aadhar}'" | |
| staff_result = sf.query(staff_query) | |
| if staff_result['totalSize'] > 0: | |
| return f"Match found in Staff: {staff_result['records'][0]['Name']}" | |
| # Query customer | |
| customer_query = f"SELECT Id, Name FROM Customer__c WHERE PAN__c = '{pan}' OR Aadhar__c = '{aadhar}'" | |
| customer_result = sf.query(customer_query) | |
| if customer_result['totalSize'] > 0: | |
| return f"Match found in Customer: {customer_result['records'][0]['Name']}" | |
| return None | |
| # Function to send alert if no match found | |
| def send_alert(): | |
| print("ALERT: No match found in Salesforce for the captured face!") | |
| # Load known faces (you should have a known_faces folder with images of staff and customers) | |
| known_faces_dir = 'known_faces' | |
| known_faces = [] | |
| known_names = [] | |
| # Iterate over each file in the known_faces folder | |
| for filename in os.listdir(known_faces_dir): | |
| image_path = os.path.join(known_faces_dir, filename) | |
| image = face_recognition.load_image_file(image_path) | |
| encoding = face_recognition.face_encodings(image)[0] | |
| known_faces.append(encoding) | |
| known_names.append(filename.split('.')[0]) # Assuming file name format is staff or customer name | |
| # Read images from folder | |
| image_folder = 'images_to_check' | |
| for filename in os.listdir(image_folder): | |
| image_path = os.path.join(image_folder, filename) | |
| unknown_image = face_recognition.load_image_file(image_path) | |
| # Detect faces | |
| face_locations = face_recognition.face_locations(unknown_image) | |
| face_encodings = face_recognition.face_encodings(unknown_image, face_locations) | |
| for face_encoding in face_encodings: | |
| # Compare the detected face with known faces | |
| matches = face_recognition.compare_faces(known_faces, face_encoding) | |
| face_distances = face_recognition.face_distance(known_faces, face_encoding) | |
| best_match_index = face_distances.argmin() | |
| # Capture timestamp | |
| timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
| if matches[best_match_index]: | |
| name = known_names[best_match_index] | |
| print(f"Face matched with {name} at {timestamp}") | |
| # You can add logic to fetch PAN/Aadhar and call Salesforce for match verification | |
| # pan = ... (Fetch corresponding PAN from your dataset) | |
| # aadhaar = ... (Fetch corresponding Aadhar from your dataset) | |
| # result = query_salesforce(pan, aadhar) | |
| # if result: | |
| # print(result) | |
| # else: | |
| # send_alert() | |
| else: | |
| send_alert() | |
| ``` | |