diff --git a/main.py b/main.py index b2d0873..9fe2828 100644 --- a/main.py +++ b/main.py @@ -65,9 +65,11 @@ def start( camera, face_cascade): roi_gray = gray[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w] person = recognize(roi_gray) - if person == 'Hesham' or person == 'Saeed':#Change to if 'unknown' elif openShifter + if person == 'unknown': + print('found unknown face') + else: + print('Sending to Arduino') OpenShifter() - print('Sending to Arduino!') cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2) @@ -96,19 +98,28 @@ def recognize(image): return names[label[0]] def OpenShifter(): + sent = False try: ser = serial.Serial('/dev/ttyUSB0',9600) ser.open() ser.write('o') ser.close() + sent = True except Exception as ex: - print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..') - + print('[ Error ] Can not connect to Arduino at /dev/ttyUSB0 ..\nTrying /dev/ttyUSB1') + if not sent: + try: + ser = serial.Serial('/dev/ttyUSB1',9600) + ser.open() + ser.write('o') + ser.close() + sent = True + except: + def loadNames(): with open("faces/names.json", "r") as read_file: data = json.load(read_file) return list(data) - init()