-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonSandbox.py
63 lines (43 loc) · 2.29 KB
/
PythonSandbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import libjevois as jevois
import cv2
import numpy as np
import os
import time
class PythonSandbox:
# recognizer
def __init__(self):
# Instantiate a JeVois Timer to measure our processing framerate:
self.timer = jevois.Timer("sandbox", 100, jevois.LOG_INFO)
self.frame = 0
self.facenames = []
self.facenames = os.listdir('modules/JeVois/PythonSandbox/training-data/')
self.facename = ""
# ###################################################################################################
## Process function with USB output
def process(self, inframe, outframe):
Id=0
Recognizer = cv2.face.LBPHFaceRecognizer_create();
Recognizer.read('share/facedetector/trainingData.yml')
confidence = 0.0
color_img = inframe.getCvBGR()
gray = inframe.getCvGRAY()
haar = cv2.CascadeClassifier('share/facedetector/haarcascade_frontalface_alt.xml')
faces = haar.detectMultiScale(gray, 1.1, 5);
for (x,y,w,h) in faces:
cv2.rectangle(color_img, (x, y), (x+w, y+h), (0,255, 0), 2)
Id, confidence = Recognizer.predict(gray[y:y+h,x:x+w])
if Id == 0:
self.facename = "Unknown"
else:
self.facename = self.facenames[Id-1]
jevois.sendSerial("Face:"+str(self.facename))
outimg = color_img
# Write a title:
cv2.putText(outimg, str(self.facename), (3, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1, cv2.LINE_AA)
# Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time):
fps = self.timer.stop()
height, width, channels = outimg.shape # if outimg is grayscale, change to: height, width = outimg.shape
cv2.putText(outimg, str(confidence), (3, height - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1, cv2.LINE_AA)
# Convert our BGR output image to video output format and send to host over USB. If your output image is not
# BGR, you can use sendCvGRAY(), sendCvRGB(), or sendCvRGBA() as appropriate:
outframe.sendCvBGR(outimg)