to be tested
This commit is contained in:
parent
20270cc73a
commit
9f75eda8a5
@ -20,6 +20,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="main.py" />
|
||||
<Compile Include="Trainer.py" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
|
||||
</Project>
|
17
Trainer.py
17
Trainer.py
@ -3,26 +3,29 @@ from io import BytesIO
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
def train(label, path):
|
||||
def addPerson(label, ImagesPath, newFileName, oldFileName):
|
||||
try:
|
||||
#faceFilePath = '/faces/hesham-saeed2'
|
||||
faceFile = '/faces/'+ oldFileName
|
||||
face_recognizer = cv2.createLBPHFaceRecognizer()
|
||||
face_recognizer.load('/faces/hesham-saeed2')
|
||||
face_recognizer.load(faceFile)
|
||||
except:
|
||||
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
|
||||
images = []
|
||||
labels = []
|
||||
image_names = os.listdir(path)
|
||||
image_names = os.listdir(ImagesPath)
|
||||
for image_name in image_names:
|
||||
if image_name.startswith('.'):
|
||||
continue;
|
||||
image_path = train_path + image_name
|
||||
image = cv2.imread(image_path)
|
||||
image = cv2.imread(image_path)
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||
for (x,y,w,h) in faces:
|
||||
images.append(gray[y:y+h, x:x+w])
|
||||
labels.append(label)
|
||||
face_recognizer.train(images, np.array(labels))
|
||||
|
||||
|
||||
face_recognizer.train(images, np.array(labels))
|
||||
face_recognizer.save('/faces/'+newFileName)
|
||||
|
||||
|
36
main.py
36
main.py
@ -12,11 +12,8 @@ try:
|
||||
except Exception as ex:
|
||||
print('[ Error ] some depandincies are missing\n'+ str(ex.args))
|
||||
|
||||
|
||||
def init():
|
||||
go = True
|
||||
#OpenShifter()
|
||||
#if Sensors():
|
||||
print('Initilizing Camera and cascade components..')
|
||||
try:
|
||||
camera = PiCamera()
|
||||
@ -115,25 +112,22 @@ def recognize(image):
|
||||
return 'Saeed'
|
||||
else:
|
||||
return 'Unknown'
|
||||
|
||||
def Sensors():
|
||||
|
||||
while 1:
|
||||
try:
|
||||
line = ser.readline()
|
||||
print(line)
|
||||
if 'A' in line:
|
||||
return True
|
||||
else:
|
||||
print('Sensors not OK..')
|
||||
|
||||
except:
|
||||
print('[ Error ] Can not connect with arduino. Retrying..')
|
||||
|
||||
def OpenShifter():
|
||||
ser = serial.Serial('/dev/ttyUSB1',9600)
|
||||
ser.open()
|
||||
ser.write('O')
|
||||
ser.close()
|
||||
try:
|
||||
ser = serial.Serial('/dev/ttyUSB1',9600)
|
||||
ser.open()
|
||||
ser.write('O')
|
||||
ser.close()
|
||||
except Exception as ex:
|
||||
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 .. \n Trying /dev/ttyUSB0')
|
||||
try:
|
||||
ser = serial.Serial('/dev/ttyUSB0',9600)
|
||||
ser.open()
|
||||
ser.write('O')
|
||||
ser.close()
|
||||
except Exception as ex:
|
||||
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB0')
|
||||
|
||||
|
||||
init()
|
||||
|
Loading…
Reference in New Issue
Block a user