Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
fb84cf1bb5 | |||
a82b98154f | |||
4441616ef1 | |||
96c2d4ccc3 | |||
00b476ee0b | |||
c43128f6f5 | |||
48dbd127a2 |
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>FaceRecognition-python</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
5
.pydevproject
Normal file
5
.pydevproject
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
|
||||||
|
</pydev_project>
|
@ -1 +1 @@
|
|||||||
### Python code to run in Raspberry Pi with PiCamera to recognize certin faces and send a Serial signal 'o' to be received by arduino.
|
### Python code to run in Raspberry Pi with PiCamera to recognize certin faces.
|
@ -7,7 +7,9 @@ const int buzzerPin = 3;
|
|||||||
int inputVal = 0;
|
int inputVal = 0;
|
||||||
long duration;
|
long duration;
|
||||||
int distance;
|
int distance;
|
||||||
char piInput = 'N';
|
boolean IROK = false;
|
||||||
|
boolean UltraOK = false;
|
||||||
|
char pi = 'N';
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(trigPin, OUTPUT);
|
pinMode(trigPin, OUTPUT);
|
||||||
@ -24,46 +26,43 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
|
IROK = false;
|
||||||
|
UltraOK = false;
|
||||||
|
pi = 'N';
|
||||||
|
|
||||||
boolean IROK = false;
|
distance = readDistance();
|
||||||
boolean UltraOK = false;
|
|
||||||
// Clears the trigPin
|
|
||||||
digitalWrite(trigPin, LOW);
|
|
||||||
delayMicroseconds(2);
|
|
||||||
// Sets the trigPin on HIGH state for 10 micro seconds
|
|
||||||
digitalWrite(trigPin, HIGH);
|
|
||||||
delayMicroseconds(10);
|
|
||||||
digitalWrite(trigPin, LOW);
|
|
||||||
// Reads the echoPin, returns the sound wave travel time in microseconds
|
|
||||||
duration = pulseIn(echoPin, HIGH);
|
|
||||||
// Calculating the distance
|
|
||||||
distance= duration*0.034/2;
|
|
||||||
|
|
||||||
if (distance < 70) UltraOK = true;
|
if (distance < 70) UltraOK = true;
|
||||||
else UltraOK = false;
|
else UltraOK = false;
|
||||||
if (digitalRead(ProxSensor) == LOW ) IROK = true;
|
if (digitalRead(ProxSensor) == LOW ) IROK = true;
|
||||||
else IROK = false;
|
else IROK = false;
|
||||||
char pi = 'N';
|
|
||||||
if (Serial.available() > 0) { pi = Serial.read(); }
|
|
||||||
|
if (Serial.available() > 0) {
|
||||||
|
pi = Serial.read();
|
||||||
|
}
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
Serial.println(pi);
|
Serial.println(pi);
|
||||||
Serial.println(IROK);
|
Serial.println(IROK);
|
||||||
Serial.println(UltraOK);
|
Serial.println(UltraOK);
|
||||||
//if (IROK && UltraOK) Serial.println("A");
|
|
||||||
if (IROK && UltraOK && pi == 'o') {
|
if (IROK && UltraOK && pi == 'o') {
|
||||||
//if (Serial.read() == 'o') {
|
openShifter();
|
||||||
|
}
|
||||||
|
IROK = false;
|
||||||
|
UltraOK = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void openShifter() {
|
||||||
digitalWrite(relayPin, HIGH);
|
digitalWrite(relayPin, HIGH);
|
||||||
playBuzzer(300, true);
|
playBuzzer(300, true);
|
||||||
delay(4000);
|
delay(7000);
|
||||||
digitalWrite(relayPin, LOW);
|
digitalWrite(relayPin, LOW);
|
||||||
IROK = false;
|
IROK = false;
|
||||||
UltraOK = false;
|
UltraOK = false;
|
||||||
pi = 'N';
|
pi = 'N';
|
||||||
serialFlush();
|
serialFlush();
|
||||||
//}
|
|
||||||
}
|
|
||||||
IROK = false;
|
|
||||||
UltraOK = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialFlush() {
|
void serialFlush() {
|
||||||
@ -83,10 +82,17 @@ void playBuzzer(int time, boolean ok){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int readDistance() {
|
||||||
|
// Clears the trigPin
|
||||||
|
digitalWrite(trigPin, LOW);
|
||||||
|
delayMicroseconds(2);
|
||||||
|
// Sets the trigPin on HIGH state for 10 micro seconds
|
||||||
|
digitalWrite(trigPin, HIGH);
|
||||||
|
delayMicroseconds(10);
|
||||||
|
digitalWrite(trigPin, LOW);
|
||||||
|
// Reads the echoPin, returns the sound wave travel time in microseconds
|
||||||
|
duration = pulseIn(echoPin, HIGH);
|
||||||
|
// Calculating the distance
|
||||||
|
return duration * 0.034 / 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4
main.py
4
main.py
@ -64,7 +64,7 @@ def start( camera, face_cascade):
|
|||||||
img = rawCapture.array
|
img = rawCapture.array
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
faces = face_cascade.detectMultiScale(gray, 1.3,5)
|
faces = face_cascade.detectMultiScale(gray, 1.3,5)
|
||||||
i = 0;
|
i = 0
|
||||||
for (x,y,w,h) in faces:
|
for (x,y,w,h) in faces:
|
||||||
i += 1
|
i += 1
|
||||||
j += 1
|
j += 1
|
||||||
@ -110,6 +110,8 @@ def recognize(image,face_recognizer, names):
|
|||||||
print(str(label) + ' >>'+names[label[0]])
|
print(str(label) + ' >>'+names[label[0]])
|
||||||
return names[label[0]]
|
return names[label[0]]
|
||||||
|
|
||||||
|
#def DrawSquares(image,gray,faces,color):
|
||||||
|
|
||||||
def OpenShifter():
|
def OpenShifter():
|
||||||
try:
|
try:
|
||||||
ser = serial.Serial('/dev/ttyUSB0',9600)
|
ser = serial.Serial('/dev/ttyUSB0',9600)
|
||||||
|
13
trainer.py
13
trainer.py
@ -7,10 +7,10 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
picCount = 0
|
picCount = 0
|
||||||
new = False
|
new = False
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
print('Starting training..')
|
print('Starting training..')
|
||||||
label = int(input('Label (Integer): '))
|
label = int(input('Label (Integer): '))
|
||||||
@ -32,12 +32,14 @@ def start():
|
|||||||
addPerson(label, newFileName, oldFileName)
|
addPerson(label, newFileName, oldFileName)
|
||||||
addName(name)
|
addName(name)
|
||||||
|
|
||||||
|
|
||||||
def clearTrainFolder():
|
def clearTrainFolder():
|
||||||
print('clearing train folder')
|
print('clearing train folder')
|
||||||
filelist = [f for f in os.listdir('train/') if f.endswith(".jpg")]
|
filelist = [f for f in os.listdir('train/') if f.endswith(".jpg")]
|
||||||
for f in filelist:
|
for f in filelist:
|
||||||
os.remove(os.path.join('train/', f))
|
os.remove(os.path.join('train/', f))
|
||||||
|
|
||||||
|
|
||||||
def addPerson(label, newFileName, oldFileName):
|
def addPerson(label, newFileName, oldFileName):
|
||||||
try:
|
try:
|
||||||
# faceFilePath = '/faces/hesham-saeed2'
|
# faceFilePath = '/faces/hesham-saeed2'
|
||||||
@ -45,9 +47,9 @@ def addPerson(label, newFileName, oldFileName):
|
|||||||
face_recognizer = cv2.createLBPHFaceRecognizer()
|
face_recognizer = cv2.createLBPHFaceRecognizer()
|
||||||
global new
|
global new
|
||||||
if new:
|
if new:
|
||||||
print 'new file. skipping load function'
|
print('new file. skipping load function')
|
||||||
else:
|
else:
|
||||||
print 'loading old file'
|
print('loading old file')
|
||||||
face_recognizer.load(faceFile)
|
face_recognizer.load(faceFile)
|
||||||
except:
|
except:
|
||||||
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
|
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
|
||||||
@ -76,6 +78,7 @@ def addPerson(label, newFileName, oldFileName):
|
|||||||
face_recognizer.save('faces/' + newFileName)
|
face_recognizer.save('faces/' + newFileName)
|
||||||
print('Updated and saved file in faces/' + newFileName)
|
print('Updated and saved file in faces/' + newFileName)
|
||||||
|
|
||||||
|
|
||||||
def capture(count):
|
def capture(count):
|
||||||
try:
|
try:
|
||||||
print('Initializing camera')
|
print('Initializing camera')
|
||||||
@ -97,6 +100,7 @@ def capture(count):
|
|||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
print('Done!')
|
print('Done!')
|
||||||
|
|
||||||
|
|
||||||
def promptNew():
|
def promptNew():
|
||||||
filemode = raw_input('Make new File? (y/n): ')
|
filemode = raw_input('Make new File? (y/n): ')
|
||||||
if filemode == 'y':
|
if filemode == 'y':
|
||||||
@ -107,8 +111,8 @@ def promptNew():
|
|||||||
print('incorrect input')
|
print('incorrect input')
|
||||||
promptNew()
|
promptNew()
|
||||||
|
|
||||||
def addName(newName):
|
|
||||||
|
|
||||||
|
def addName(newName):
|
||||||
with open("faces/names.json", "r") as read_file:
|
with open("faces/names.json", "r") as read_file:
|
||||||
exist = False
|
exist = False
|
||||||
namesJson = json.load(read_file)
|
namesJson = json.load(read_file)
|
||||||
@ -125,4 +129,5 @@ def addName(newName):
|
|||||||
with open("faces/names.json", "w") as write_file:
|
with open("faces/names.json", "w") as write_file:
|
||||||
json.dump(names, write_file)
|
json.dump(names, write_file)
|
||||||
|
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
Loading…
Reference in New Issue
Block a user