stability updates #4

Closed
Hesham wants to merge 1 commits from Proper-if-recognition into master
Showing only changes of commit 427c239043 - Show all commits

19
main.py
View File

@ -65,9 +65,11 @@ def start( camera, face_cascade):
roi_gray = gray[y:y+h, x:x+w] roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w]
person = recognize(roi_gray) 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() OpenShifter()
print('Sending to Arduino!')
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) 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) cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2)
@ -96,13 +98,23 @@ def recognize(image):
return names[label[0]] return names[label[0]]
def OpenShifter(): def OpenShifter():
sent = False
try: try:
ser = serial.Serial('/dev/ttyUSB0',9600) ser = serial.Serial('/dev/ttyUSB0',9600)
ser.open() ser.open()
ser.write('o') ser.write('o')
ser.close() ser.close()
sent = True
except Exception as ex: 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(): def loadNames():
@ -110,5 +122,4 @@ def loadNames():
data = json.load(read_file) data = json.load(read_file)
return list(data) return list(data)
init() init()