merge #5
42
main.py
42
main.py
@ -41,20 +41,16 @@ def init():
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
print('closing')
|
print('closing')
|
||||||
#else:
|
|
||||||
#print('Sensors not Satisfied')
|
|
||||||
|
|
||||||
def start( camera, face_cascade):
|
def start( camera, face_cascade):
|
||||||
j = 0
|
j = 0
|
||||||
rawCapture = PiRGBArray(camera)
|
rawCapture = PiRGBArray(camera)
|
||||||
#camera.framerate = 32
|
|
||||||
#rawCapture = PiRGBArray(camera, size=(640, 480))
|
|
||||||
#for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
|
|
||||||
while 1:
|
while 1:
|
||||||
#try:
|
try:
|
||||||
#camera.capture('img.jpg')
|
camera.capture(rawCapture, format="bgr")
|
||||||
#img = cv2.imread('img.jpg',1)
|
except:
|
||||||
camera.capture(rawCapture, format="bgr")
|
print('[ Error ] Can not capture image. Restarting..')
|
||||||
|
init()
|
||||||
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.2,5)
|
faces = face_cascade.detectMultiScale(gray, 1.2,5)
|
||||||
@ -79,18 +75,16 @@ def start( camera, face_cascade):
|
|||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
break
|
break
|
||||||
|
|
||||||
#except:
|
|
||||||
#print('[ Error ] Unexpected exception')
|
|
||||||
#print('Closing')
|
|
||||||
#break
|
|
||||||
|
|
||||||
def recognize(image):
|
def recognize(image):
|
||||||
names = loadNames()
|
names = loadNames()
|
||||||
face_recognizer = cv2.createLBPHFaceRecognizer()
|
try:
|
||||||
face_recognizer.load('faces/m')
|
face_recognizer = cv2.createLBPHFaceRecognizer()
|
||||||
img = image.copy()
|
face_recognizer.load('faces/m')
|
||||||
label= face_recognizer.predict(img)
|
img = image.copy()
|
||||||
|
label= face_recognizer.predict(img)
|
||||||
|
except:
|
||||||
|
print('[ Error ] Error in Recognize() function')
|
||||||
if label[1] > 120:
|
if label[1] > 120:
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
else:
|
else:
|
||||||
@ -107,10 +101,12 @@ def OpenShifter():
|
|||||||
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..')
|
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..')
|
||||||
|
|
||||||
def loadNames():
|
def loadNames():
|
||||||
|
try:
|
||||||
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)
|
||||||
|
except:
|
||||||
|
print('[ Error ] Error in loadNames() function')
|
||||||
|
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
Loading…
Reference in New Issue
Block a user