cnn works
This commit is contained in:
parent
58fa46a92d
commit
8fa3ef8427
|
|
@ -153,12 +153,10 @@ class Camera(Resource):
|
|||
try:
|
||||
if type == "stream":
|
||||
return flask.Response(self.gen(self.VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
if type == "processed":
|
||||
elif type == "processed":
|
||||
return flask.Response(self.genProcessed(self.VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
elif type == "still":
|
||||
lastImage1 = base64.b64decode(lastImage)
|
||||
return flask.Response(lastImage1, mimetype='image/png')
|
||||
return flask.Response(base64.b64decode(lastImage), mimetype='image/png')
|
||||
|
||||
return flask.make_response(flask.jsonify({'error': "No idea how you got here"}), 404)
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -10,19 +10,15 @@ from io import StringIO
|
|||
TOLERANCE = 0.6
|
||||
FRAME_THICKNESS = 3
|
||||
FONT_THICKNESS = 2
|
||||
MODEL = "hog" # default: 'hog', other one can be 'cnn' - CUDA accelerated (if available) deep-learning pretrained model
|
||||
MODEL = "cnn" # default: 'hog', other one can be 'cnn' - CUDA accelerated (if available) deep-learning pretrained model
|
||||
|
||||
def readb64(base64_string):
|
||||
sbuf = StringIO()
|
||||
sbuf.write(base64.b64decode(base64_string))
|
||||
pimg = Image.open(sbuf)
|
||||
return cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
|
||||
|
||||
print('Loading known faces...')
|
||||
known_faces = []
|
||||
known_names = []
|
||||
|
||||
def initFaceRec():
|
||||
dlib.DLIB_USE_CUDA=True
|
||||
print('Loading known faces...', dlib.DLIB_USE_CUDA)
|
||||
session = Session()
|
||||
# We oranize known faces as subfolders of KNOWN_FACES_DIR
|
||||
# Each subfolder's name becomes our label (name)
|
||||
|
|
@ -38,7 +34,7 @@ def initFaceRec():
|
|||
# Append encodings and name
|
||||
known_faces.append(encoding)
|
||||
known_names.append(name)
|
||||
|
||||
print('DONE Loading known faces...')
|
||||
session.close()
|
||||
|
||||
def identifyFace(image):
|
||||
|
|
@ -58,8 +54,10 @@ def identifyFace(image):
|
|||
return res
|
||||
|
||||
def identifyFaceVideo(url):
|
||||
|
||||
video = cv2.VideoCapture(url)
|
||||
image = video.read()[1]
|
||||
image = cv2.resize(image,None,fx=0.5,fy=0.5)
|
||||
ret, image = cv2.imencode(".png", image)
|
||||
|
||||
nparr = np.fromstring(image, np.uint8)
|
||||
|
|
@ -74,13 +72,16 @@ def identifyFaceVideo(url):
|
|||
|
||||
face_locations.update(compareFace(face_encoding, face_location))
|
||||
|
||||
session = Session()
|
||||
for k, v in face_locations.items():
|
||||
# Paint frame
|
||||
cv2.rectangle(image, v[0], v[1], [255, 0, 0], FRAME_THICKNESS)
|
||||
# Wite a name
|
||||
cv2.putText(image, k, v[0], cv2.FONT_HERSHEY_SIMPLEX, 1.5, [255, 0, 255], FONT_THICKNESS)
|
||||
name = " ".join(session.query(Person.fname, Person.lname).filter(Person.person_id == int(k)).first())
|
||||
cv2.putText(image, name, v[0], cv2.FONT_HERSHEY_SIMPLEX, 1.5, [255, 0, 255], FONT_THICKNESS)
|
||||
|
||||
# Show image
|
||||
session.close()
|
||||
image = cv2.imencode(".jpg", image)[1]
|
||||
return image
|
||||
|
||||
|
|
@ -90,10 +91,9 @@ def compareFace(face_encoding, face_location):
|
|||
face_locations = {}
|
||||
match = None
|
||||
if True in results: # If at least one is true, get a name of first of found labels
|
||||
match = "name"
|
||||
print(f' - {match} from {results}')
|
||||
match = known_names[results.index(True)]
|
||||
top_left = (face_location[3], face_location[0])
|
||||
bottom_right = (face_location[1], face_location[2])
|
||||
|
||||
face_locations[match] = (top_left, bottom_right)
|
||||
face_locations[str(match)] = (top_left, bottom_right)
|
||||
return face_locations
|
||||
|
|
@ -0,0 +1 @@
|
|||
https://stackoverflow.com/a/57592670/10785079
|
||||
Loading…
Reference in New Issue