updated recognize 'if' & updated OpenShifter()
This commit is contained in:
		
							parent
							
								
									30c8e4b074
								
							
						
					
					
						commit
						427c239043
					
				
							
								
								
									
										21
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								main.py
									
									
									
									
									
								
							@ -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,19 +98,28 @@ 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():
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	with open("faces/names.json", "r") as read_file:
 | 
						with open("faces/names.json", "r") as read_file:
 | 
				
			||||||
		data = json.load(read_file)
 | 
							data = json.load(read_file)
 | 
				
			||||||
		return list(data)
 | 
							return list(data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
init()
 | 
					init()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user