└── facedetection.py /facedetection.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from cv2 import cv2 4 | 5 | import clx.xms 6 | import requests 7 | 8 | client = clx.xms.Client(service_plan_id='your_service id', 9 | token='token_id') 10 | 11 | create = clx.xms.api.MtBatchTextSmsCreate() 12 | create.sender = 'sender no.' 13 | create.recipients = {'recipients no.'} 14 | create.body = 'This is a test message from your Sinch account' 15 | 16 | 17 | detector = cv2.CascadeClassifier( 18 | "path") 19 | 20 | 21 | 22 | cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) 23 | 24 | counter = 0 25 | 26 | 27 | while True: 28 | 29 | 30 | ret, img = cap.read() 31 | 32 | if ret: 33 | 34 | 35 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 36 | 37 | 38 | faces = detector.detectMultiScale(gray, 1.1, 4) 39 | 40 | for face in faces: 41 | 42 | 43 | if(face.any() and counter ==0): 44 | try: 45 | batch = client.create_batch(create) 46 | except (requests.exceptions.RequestException, clx.xms.exceptions.ApiException) as ex: 47 | print('Failed to communicate with XMS: %s' % str(ex)) 48 | #sms ends here 49 | 50 | cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) 51 | 52 | 53 | cv2.imshow("Face", img) 54 | counter = 1 55 | 56 | key = cv2.waitKey(1) 57 | if key == ord("q"): 58 | break 59 | cap.release() 60 | cv2.destroyAllWindows() 61 | --------------------------------------------------------------------------------