def enroll(): # role = 'Superuser' req = request.form print(req) user = req['userid'] imgfile = request.files['image'] # print(imgfile.filename) # filetype = req['filename'].split('.')[-1] try: query = f"SELECT role FROM user WHERE username='******'" cur.execute(query) except Error as E: return str(E) role = cur.fetchall() if role[0][0] != 'superuser': return jsonify({"error": 401, "reason": "Invalid role"}) query = 'INSERT INTO encoding (subgroupID, faceOwner, encodingblob) VALUES (%s,%s,%s)' query2 = "UPDATE encoding SET encodingblob=%s WHERE faceID=%s" try: cur.execute(query, (req['subgroupid'], req['name'], "")) lastid = cur.lastrowid saveFile(lastid, imgfile, UPLOAD_FOLDER, client) imgfile.seek(0) x = makeBlob(imgfile) cur.execute(query2, (x, lastid)) con.commit() return jsonify({"last face id": lastid}) except Error as E: return jsonify({'error': str(E)})
def listG(): query = 'SELECT groups.*, subgroups.subgroupID, subgroups.subgroupName FROM groups LEFT JOIN subgroups ON groups.groupID=subgroups.groupID' # try: cur.execute(query) temp = cur.fetchall() # except Error as E: # return jsonify({'error' : E}) return jsonify(temp)
def selectFaces(): req = request.args try: query = f"SELECT faceID, faceOwner FROM encoding WHERE subgroupID={req['subgrouid']}" cur.execute(query) except Error as E: print(E) return 'Err' data = cur.fetchall() mylist = [] for i in data: mylist.append(i) return jsonify({'Result': mylist})
def recognize(): req = request.form imgfile = request.files['image'] try: query = f"SELECT faceOwner,encodingblob FROM encoding WHERE subgroupID={req['subgroupid']}" cur.execute(query) except Error as E: # print(E) return str(E) x = cur.fetchall() knownEncodings = [] knownNames = [] for i in x: res = compare(imgfile, [fromBlob(i[1])], [i[0]]) if res != 'unknown name': return res return jsonify({'Result': res})
def byteface(): idF = request.args['id'] if client.bucket_exists('facerecimages'): # try: query = f"SELECT path FROM images WHERE id={idF}" cur.execute(query) filetype = cur.fetchall()[0][0] if not filetype: return "id not found" resp = client.get_object('facerecimages', str(idF)) byt = resp.data # print(byt) # KALO MAU NGESAVE JADI FILE LOCAL # stream = BytesIO(byt) # img = Image.open(stream) # img.save('test.jpg') else: return jsonify({"error": "bucket not found"}) return jsonify({"filetype": filetype, "b64data": str(byt)})