From d198ac8073c939571ff6461b9cab0dbd2308dfe8 Mon Sep 17 00:00:00 2001 From: SadhulaSaiKumar Date: Tue, 29 Aug 2023 05:54:08 +0000 Subject: [PATCH] Upload files to 'Attendence' --- Attendence/anwi_attendence.py | 559 ++++++++++++++++++++++++++++++++++ Attendence/attendence.py | 16 +- Attendence/requirements.txt | 402 ++++++++++++++++++++++++ Attendence/test_attendence.py | 557 +++++++++++++++++++++++++++++++++ Attendence/uat_attendence.py | 559 ++++++++++++++++++++++++++++++++++ 5 files changed, 2091 insertions(+), 2 deletions(-) create mode 100644 Attendence/anwi_attendence.py create mode 100644 Attendence/requirements.txt create mode 100644 Attendence/test_attendence.py create mode 100644 Attendence/uat_attendence.py diff --git a/Attendence/anwi_attendence.py b/Attendence/anwi_attendence.py new file mode 100644 index 0000000..b99eba8 --- /dev/null +++ b/Attendence/anwi_attendence.py @@ -0,0 +1,559 @@ +from flask import Flask, render_template, request, redirect, Response, send_file +import multiprocessing +import face_recognition +#from numba import jit +import numpy as np +import os +#from flask_cors import CORS +app = Flask(__name__) +#CORS(app) +lst = [] + + +@app.route('/', methods=['GET']) +def resume(): + #return render_template('index.html') + return 'Attendence app running' + +def createEncodings(image): + print("Encoding") + """ + Create face encodings for a given image and also return face locations in the given image. + Parameters + ------- + image : cv2 mat + Image you want to detect faces from. + Returns + ------- + known_encodings : list of np array + List of face encodings in a given image + face_locations : list of tuples + list of tuples for face locations in a given image + """ + # Find face locations for all faces in an image + face_locations = face_recognition.face_locations(image) + # Create encodings for all faces in an image + known_encodings = face_recognition.face_encodings(image, known_face_locations=face_locations) + return known_encodings, face_locations +#@app.route('/register', methods=["POST","GET"]) +def registered(url_list): + input=url_list + + from pathlib import Path + Path("ppeople").mkdir(exist_ok=True) + Path("ppeople/" + input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + #z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y+ '.'+ z + print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + try: + img_data = x.encode() + except AttributeError: + return "Successfully saved encoding........." + + import base64 + + with open("ppeople/" + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + + img = "ppeople/" + y + "/" + name + saveLocation = "ppeople/" + y + "/" + y + ".pickle" + + ############ detecting no of faceses ####################### + + + # import cv2 + # import numpy as np + # import dlib + + + # # Connects to your computer's default camera + # cap = cv2.imread(img) + + # # Detect the coordinates + # detector = dlib.get_frontal_face_detector() + + # number_of_faces=[] + # # Capture frames continuously + # # while True: + + # # Capture frame-by-frame + # # ret, frame = cap + # frame = cap + + # # RGB to grayscale + # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + # faces = detector(gray) + + # # Iterator to count faces + # i = 0 + # for face in faces: + + # # Get the coordinates of faces + # x, y = face.left(), face.top() + # x1, y1 = face.right(), face.bottom() + # cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # # Increment iterator for each face in faces + # i = i+1 + + # # Display the box and faces + # cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + # cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # # if len(i)>1: + # # print(i) + # number_of_faces.append(i) + + + # if (len(number_of_faces))>1: + # print("Group Photo") + # return "Group Photo" + # elif (len(number_of_faces))==1: + # print("Single Photo") + # pass + + + + + + def saveEncodings(encs, names, fname='encodings.pickle'): + """ + Save encodings in a pickle file to be used in future. + + Parameters + ---------- + encs : List of np arrays + List of face encodings. + names : List of strings + List of names for each face encoding. + fname : String, optional + Name/Location for pickle file. The default is "encodings.pickle". + + Returns + ------- + None. + + """ + + data = [] + d = [{"name": nm, "encoding": enc} for (nm, enc) in zip(names, encs)] + data.extend(d) + + encodingsFile = fname + + # dump the facial encodings data to disk + print("[INFO] serializing encodings...") + print("[INFO] Encodings Created sucessfully") + f = open(encodingsFile, "wb") + f.write(pickle.dumps(data)) + f.close() + + # Function to create encodings and get face locations + + + def processKnownPeopleImages(img=img, saveLocation=saveLocation): + """ + Process images of known people and create face encodings to compare in future. + Eaach image should have just 1 face in it. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "C:/inetpub/vhosts/port82/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + Returns + ------- + None. + """ + known_encodings = [] + known_names = [] + # for img in os.listdir(path): + + imgPath = img + # Read image + image = cv2.imread(imgPath) + name = img.rsplit('.')[0] + # Resize + try: + print(image.shape) + except AttributeError: + return "Successfully saved encoding........." + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + # Get locations and encodings + encs, locs = createEncodings(image) + try: + known_encodings.append(encs[0]) + except IndexError: + os.remove(saveLocation) + print('------------------------------------- save location --------------------------------') + print(saveLocation) + return "hello world!" + + + # known_encodings.append(encs[0]) + known_names.append(name) + for loc in locs: + top, right, bottom, left = loc + # Show Image + # cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2) + # cv2.imshow("Image", image) + # cv2.waitKey(1) + # cv2.destroyAllWindows() + saveEncodings(known_encodings, known_names, saveLocation) + + import cv2 + #import face_recognition + import pickle + + processKnownPeopleImages(img, saveLocation) + return 'Successfully saved encoding.........' + + +# ******************************** COMPARUISION ********************************************************* +#@app.route('/submit', methods=["POST","GET"]) +def submit(url_list): + + from datetime import datetime + import pytz + tz_NY = pytz.timezone('Asia/Kolkata') + datetime_NY = datetime.now(tz_NY) + India_Date = (datetime_NY.strftime("%Y-%m-%d")) + India_Date = str(India_Date) + # India_Time = (datetime_NY.strftime("%I:%M:%S %p")) + # India_Time = str(India_Time) + input=url_list + import pickle + import cv2 + + from pathlib import Path + Path("GGallery/"+ India_Date).mkdir(exist_ok=True) + Path("GGallery/"+ India_Date +'/'+ input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + # z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y + '.' + z + # print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + img_data = x.encode() + + import base64 + + + with open("GGallery/"+India_Date+'/' + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + + path = "GGallery/" +India_Date+'/'+ y + "/" + name + pickle_location = "ppeople/" + y + "/" + y + ".pickle" + import pathlib + file = pathlib.Path(pickle_location) + if file.exists (): + pass + else: + print ("pickle File not exist") + print(name) + return "Face not found in profile (please change your profile)" + + check_faces="ppeople/" + y + "/" + y + ".jpg" + print(check_faces) + + + ############ detecting no of faceses ####################### + + + import cv2 + import numpy as np + import dlib + + + # Connects to your computer's default camera + cap = cv2.imread(check_faces) + + # Detect the coordinates + detector = dlib.get_frontal_face_detector() + + number_of_faces=[] + # Capture frames continuously + # while True: + + # Capture frame-by-frame + # ret, frame = cap + frame = cap + + # RGB to grayscale + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + faces = detector(gray) + + # Iterator to count faces + i = 0 + for face in faces: + + # Get the coordinates of faces + x, y = face.left(), face.top() + x1, y1 = face.right(), face.bottom() + cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # Increment iterator for each face in faces + i = i+1 + + # Display the box and faces + cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # if len(i)>1: + # print(i) + number_of_faces.append(i) + + + if (len(number_of_faces))>1: + print("Group Photo") + return "Group Photo" + elif (len(number_of_faces))==1: + print("Single Photo") + pass + + + + + def readEncodingsPickle(fname): + """ + Read Pickle file. + + Parameters + ---------- + fname : String + Name of pickle file.(Full location) + + Returns + ------- + encodings : list of np arrays + list of all saved encodings + names : List of Strings + List of all saved names + + """ + + + data = pickle.loads(open(fname, "rb").read()) + + + data = np.array(data) + encodings = [d["encoding"] for d in data] + names = [d["name"] for d in data] + return encodings, names + + + def compareFaceEncodings(unknown_encoding, known_encodings, known_names): + """ + Compares face encodings to check if 2 faces are same or not. + + Parameters + ---------- + unknown_encoding : np array + Face encoding of unknown people. + known_encodings : np array + Face encodings of known people. + known_names : list of strings + Names of known people + + Returns + ------- + acceptBool : Bool + face matched or not + duplicateName : String + Name of matched face + distance : Float + Distance between 2 faces + + """ + duplicateName = "" + distance = 0.0 + matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.54) + face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) + + best_match_index = np.argmin(face_distances) + + distance = face_distances[best_match_index] + if matches[best_match_index]: + acceptBool = True + duplicateName = known_names[best_match_index] + else: + acceptBool = False + duplicateName = "" + return acceptBool, duplicateName, distance + + #p = [] + + + def processDatasetImages(path=path, pickle_location=pickle_location): + """ + Process image in dataset from where you want to separate images. + It separates the images into directories of known people, groups and any unknown people images. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "D:/port1004/port1004/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + + Returns + ------- + None. + + """ + # Read pickle file for known people to compare faces from + + people_encodings, names = readEncodingsPickle(pickle_location) + # print(p) + # imgPath = path + img + + # Read image + # path=r"C:\Users\katku\Pictures\final\100011460000611.jpg" + image = cv2.imread(path) + #orig = image.copy() + + # Resize + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + + # Get locations and encodings + encs, locs = createEncodings(image) + + # Save image to a group image folder if more than one face is in image + # if len(locs) > 1: + # saveImageToDirectory(orig, "Group", img) + + # Processing image for each face + i = 0 + knownFlag = 0 + for loc in locs: + top, right, bottom, left = loc + unknown_encoding = encs[i] + i += 1 + acceptBool, duplicateName, distance = compareFaceEncodings(unknown_encoding, people_encodings, names) + if acceptBool: + # saveImageToDirectory(orig, duplicateName,name) + knownFlag = 1 + if knownFlag == 1: + print("Match Found") + + + #print(path) + with_extension = path.split("/")[-1] + without_extension = with_extension.split(".")[0] + + # output_s = {"FileID": without_extension, + # "Date": India_Date, + # "Time": India_Time} + # output_json = json.dumps(output_s) + output_json='Matched successfully' + print(loc) + lst.append(output_json) + + print(output_json) + # exit() + + else: + print('Not Matched') + pass + # saveImageToDirectory(orig, "0",name) + + + import numpy as np + import json + + processDatasetImages(path, pickle_location) + return lst[0] + #return 'matched successfully' + + +@app.route('/detect', methods=["POST"]) +def detect(): + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + # id = "100013660000125" + url_list.append(Dataset) + # multiprocessing + pool_size = multiprocessing.cpu_count() * 2 + with multiprocessing.Pool(pool_size) as pool: + try: + results = pool.map(submit, url_list) + except FileNotFoundError: + return 'plese get registered with your PhotoID' + except IndexError: + #return 'unable to recognize face' + return 'failed' + + pool.close() + + return results[0] + + + +@app.route('/register', methods=["POST"]) +def register(): + print("hello start..........") + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + # id = "100013660000125" + url_list.append(Dataset) + UserLocation=Dataset["FilePath"] + print(UserLocation) + + # if "cO2" in UserLocation or UserLocation is None: + # pass + # else: + # return "Please update the URL in the integration" + + + # multiprocessing + pool_size = multiprocessing.cpu_count() * 2 + with multiprocessing.Pool(pool_size) as pool: + try: + results = pool.map(registered, url_list) + except IndexError: + pass + print('face not found') + except FileNotFoundError: + pass + + + #os.remove(img) + # return 'unable to recognize face' + + pool.close() + #return results[0] + return 'Successfully saved encoding.........' + + + + +if __name__ == "__main__": + app.run(host='0.0.0.0',port =5006,debug=False) diff --git a/Attendence/attendence.py b/Attendence/attendence.py index 97d3c2c..0be12dc 100644 --- a/Attendence/attendence.py +++ b/Attendence/attendence.py @@ -59,7 +59,10 @@ def registered(url_list): # filename=image[-1] # print(x) - img_data = x.encode() + try: + img_data = x.encode() + except AttributeError: + return "Successfully saved encoding........." import base64 @@ -388,7 +391,7 @@ def submit(url_list): """ duplicateName = "" distance = 0.0 - matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.54) + matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.51) face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) best_match_index = np.argmin(face_distances) @@ -521,6 +524,15 @@ def register(): Dataset= request.get_json() # id = "100013660000125" url_list.append(Dataset) + UserLocation=Dataset["FilePath"] + print(UserLocation) + + # if "cO2" in UserLocation or UserLocation is None: + # pass + # else: + # return "Please update the URL in the integration" + + # multiprocessing pool_size = multiprocessing.cpu_count() * 2 with multiprocessing.Pool(pool_size) as pool: diff --git a/Attendence/requirements.txt b/Attendence/requirements.txt new file mode 100644 index 0000000..9e17193 --- /dev/null +++ b/Attendence/requirements.txt @@ -0,0 +1,402 @@ +absl-py==1.3.0 +aio-pika==8.2.3 +aiofiles==23.1.0 +aiogram==2.25.1 +aiohttp @ file:///tmp/build/80754af9/aiohttp_1646806365504/work +aiormq==6.4.2 +aiosignal @ file:///tmp/build/80754af9/aiosignal_1637843061372/work +alabaster @ file:///home/ktietz/src/ci/alabaster_1611921544520/work +anaconda-client @ file:///tmp/build/80754af9/anaconda-client_1635342557008/work +anaconda-navigator==2.1.4 +anaconda-project @ file:///tmp/build/80754af9/anaconda-project_1637161053845/work +anyio @ file:///tmp/build/80754af9/anyio_1644463572971/work/dist +appdirs==1.4.4 +APScheduler==3.9.1.post1 +argon2-cffi @ file:///opt/conda/conda-bld/argon2-cffi_1645000214183/work +argon2-cffi-bindings @ file:///tmp/build/80754af9/argon2-cffi-bindings_1644569679365/work +arrow @ file:///opt/conda/conda-bld/arrow_1649166651673/work +astroid @ file:///tmp/build/80754af9/astroid_1628063140030/work +astropy @ file:///opt/conda/conda-bld/astropy_1650891077797/work +asttokens @ file:///opt/conda/conda-bld/asttokens_1646925590279/work +astunparse==1.6.3 +async-timeout==4.0.2 +atomicwrites==1.4.0 +attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work +Automat @ file:///tmp/build/80754af9/automat_1600298431173/work +autopep8 @ file:///opt/conda/conda-bld/autopep8_1639166893812/work +Babel @ file:///tmp/build/80754af9/babel_1620871417480/work +backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work +backports.functools-lru-cache @ file:///tmp/build/80754af9/backports.functools_lru_cache_1618170165463/work +backports.tempfile @ file:///home/linux1/recipes/ci/backports.tempfile_1610991236607/work +backports.weakref==1.0.post1 +bcrypt @ file:///tmp/build/80754af9/bcrypt_1607022650461/work +beautifulsoup4 @ file:///opt/conda/conda-bld/beautifulsoup4_1650462163268/work +bidict==0.22.1 +binaryornot @ file:///tmp/build/80754af9/binaryornot_1617751525010/work +bitarray @ file:///tmp/build/80754af9/bitarray_1648739490228/work +bkcharts==0.2 +black==19.10b0 +bleach @ file:///opt/conda/conda-bld/bleach_1641577558959/work +bokeh @ file:///tmp/build/80754af9/bokeh_1638362822154/work +boto3 @ file:///opt/conda/conda-bld/boto3_1649078879353/work +botocore @ file:///opt/conda/conda-bld/botocore_1649076662316/work +Bottleneck @ file:///tmp/build/80754af9/bottleneck_1648028898966/work +brotlipy==0.7.0 +CacheControl==0.12.11 +cachetools @ file:///tmp/build/80754af9/cachetools_1619597386817/work +certifi==2021.10.8 +cffi @ file:///opt/conda/conda-bld/cffi_1642701102775/work +chardet @ file:///tmp/build/80754af9/chardet_1607706775000/work +charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work +click @ file:///tmp/build/80754af9/click_1646056590078/work +cloudpickle @ file:///tmp/build/80754af9/cloudpickle_1632508026186/work +clyent==1.2.2 +colorama @ file:///tmp/build/80754af9/colorama_1607707115595/work +colorcet @ file:///tmp/build/80754af9/colorcet_1611168489822/work +colorclass==2.2.2 +coloredlogs==15.0.1 +colorhash==1.2.1 +conda==4.12.0 +conda-build==3.21.8 +conda-content-trust @ file:///tmp/build/80754af9/conda-content-trust_1617045594566/work +conda-pack @ file:///tmp/build/80754af9/conda-pack_1611163042455/work +conda-package-handling @ file:///tmp/build/80754af9/conda-package-handling_1649105784853/work +conda-repo-cli @ file:///tmp/build/80754af9/conda-repo-cli_1620168426516/work +conda-token @ file:///tmp/build/80754af9/conda-token_1620076980546/work +conda-verify==3.4.2 +confluent-kafka==1.9.2 +constantly==15.1.0 +cookiecutter @ file:///opt/conda/conda-bld/cookiecutter_1649151442564/work +cryptography @ file:///tmp/build/80754af9/cryptography_1633520369886/work +cssselect==1.1.0 +cycler @ file:///tmp/build/80754af9/cycler_1637851556182/work +Cython @ file:///tmp/build/80754af9/cython_1647850345254/work +cytoolz==0.11.0 +daal4py==2021.5.0 +dask==2022.10.2 +datashader @ file:///tmp/build/80754af9/datashader_1623782308369/work +datashape==0.5.4 +debugpy @ file:///tmp/build/80754af9/debugpy_1637091799509/work +decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work +defusedxml @ file:///tmp/build/80754af9/defusedxml_1615228127516/work +diff-match-patch @ file:///Users/ktietz/demo/mc3/conda-bld/diff-match-patch_1630511840874/work +distributed @ file:///opt/conda/conda-bld/distributed_1647271944416/work +dlib==19.24.0 +dnspython==1.16.0 +docopt==0.6.2 +docutils @ file:///tmp/build/80754af9/docutils_1620827980776/work +entrypoints @ file:///tmp/build/80754af9/entrypoints_1649926439650/work +et-xmlfile==1.1.0 +executing @ file:///opt/conda/conda-bld/executing_1646925071911/work +face-recognition==1.3.0 +face-recognition-models==0.3.0 +fastjsonschema @ file:///tmp/build/80754af9/python-fastjsonschema_1620414857593/work/dist +fbmessenger==6.0.0 +filelock @ file:///opt/conda/conda-bld/filelock_1647002191454/work +fire==0.5.0 +flake8 @ file:///tmp/build/80754af9/flake8_1620776156532/work +Flask @ file:///home/ktietz/src/ci/flask_1611932660458/work +flatbuffers==23.3.3 +fonttools==4.25.0 +frozenlist @ file:///tmp/build/80754af9/frozenlist_1637767113340/work +fsspec @ file:///opt/conda/conda-bld/fsspec_1647268051896/work +future @ file:///tmp/build/80754af9/future_1607571303524/work +gast==0.4.0 +gensim @ file:///tmp/build/80754af9/gensim_1646806807927/work +glob2 @ file:///home/linux1/recipes/ci/glob2_1610991677669/work +gmpy2 @ file:///tmp/build/80754af9/gmpy2_1645438755360/work +google-api-core @ file:///C:/ci/google-api-core-split_1613980333946/work +google-auth @ file:///tmp/build/80754af9/google-auth_1626320605116/work +google-auth-oauthlib==0.4.6 +google-cloud-core @ file:///tmp/build/80754af9/google-cloud-core_1625077425256/work +google-cloud-storage @ file:///tmp/build/80754af9/google-cloud-storage_1601307969662/work +google-crc32c @ file:///tmp/build/80754af9/google-crc32c_1612242928148/work +google-pasta==0.2.0 +google-resumable-media @ file:///tmp/build/80754af9/google-resumable-media_1624367812531/work +googleapis-common-protos @ file:///tmp/build/80754af9/googleapis-common-protos-feedstock_1617957652138/work +greenlet @ file:///tmp/build/80754af9/greenlet_1628888132713/work +grpcio @ file:///tmp/build/80754af9/grpcio_1637590821884/work +h5py @ file:///tmp/build/80754af9/h5py_1637138488546/work +HeapDict @ file:///Users/ktietz/demo/mc3/conda-bld/heapdict_1630598515714/work +holoviews @ file:///opt/conda/conda-bld/holoviews_1645454331194/work +httptools==0.5.0 +humanfriendly==10.0 +hvplot @ file:///tmp/build/80754af9/hvplot_1627305124151/work +hyperlink @ file:///tmp/build/80754af9/hyperlink_1610130746837/work +idna @ file:///tmp/build/80754af9/idna_1637925883363/work +imagecodecs @ file:///tmp/build/80754af9/imagecodecs_1635529108216/work +imageio @ file:///tmp/build/80754af9/imageio_1617700267927/work +imagesize @ file:///tmp/build/80754af9/imagesize_1637939814114/work +importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1648544546694/work +incremental @ file:///tmp/build/80754af9/incremental_1636629750599/work +inflection==0.5.1 +iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work +intake @ file:///opt/conda/conda-bld/intake_1647436631684/work +intervaltree @ file:///Users/ktietz/demo/mc3/conda-bld/intervaltree_1630511889664/work +ipykernel @ file:///tmp/build/80754af9/ipykernel_1647000773790/work/dist/ipykernel-6.9.1-py3-none-any.whl +ipython @ file:///tmp/build/80754af9/ipython_1648817057602/work +ipython-genutils @ file:///tmp/build/80754af9/ipython_genutils_1606773439826/work +ipywidgets @ file:///tmp/build/80754af9/ipywidgets_1634143127070/work +isort @ file:///tmp/build/80754af9/isort_1628603791788/work +itemadapter @ file:///tmp/build/80754af9/itemadapter_1626442940632/work +itemloaders @ file:///opt/conda/conda-bld/itemloaders_1646805235997/work +itsdangerous @ file:///tmp/build/80754af9/itsdangerous_1621432558163/work +jdcal @ file:///Users/ktietz/demo/mc3/conda-bld/jdcal_1630584345063/work +jedi @ file:///tmp/build/80754af9/jedi_1644297102865/work +jeepney @ file:///tmp/build/80754af9/jeepney_1627537048313/work +Jinja2 @ file:///tmp/build/80754af9/jinja2_1612213139570/work +jinja2-time @ file:///opt/conda/conda-bld/jinja2-time_1649251842261/work +jmespath @ file:///Users/ktietz/demo/mc3/conda-bld/jmespath_1630583964805/work +joblib @ file:///tmp/build/80754af9/joblib_1635411271373/work +json5 @ file:///tmp/build/80754af9/json5_1624432770122/work +jsonpickle==3.0.1 +jsonschema @ file:///tmp/build/80754af9/jsonschema_1650025953207/work +jupyter @ file:///tmp/build/80754af9/jupyter_1607700846274/work +jupyter-client @ file:///tmp/build/80754af9/jupyter_client_1616770841739/work +jupyter-console @ file:///tmp/build/80754af9/jupyter_console_1616615302928/work +jupyter-core @ file:///tmp/build/80754af9/jupyter_core_1646976314572/work +jupyter-server @ file:///opt/conda/conda-bld/jupyter_server_1644494914632/work +jupyterlab @ file:///opt/conda/conda-bld/jupyterlab_1647445413472/work +jupyterlab-pygments @ file:///tmp/build/80754af9/jupyterlab_pygments_1601490720602/work +jupyterlab-server @ file:///opt/conda/conda-bld/jupyterlab_server_1644500396812/work +jupyterlab-widgets @ file:///tmp/build/80754af9/jupyterlab_widgets_1609884341231/work +keras==2.11.0 +keyring @ file:///tmp/build/80754af9/keyring_1638531355686/work +kiwisolver @ file:///opt/conda/conda-bld/kiwisolver_1638569886207/work +lazy-object-proxy @ file:///tmp/build/80754af9/lazy-object-proxy_1616529027849/work +libarchive-c @ file:///tmp/build/80754af9/python-libarchive-c_1617780486945/work +libclang==16.0.0 +llvmlite==0.38.0 +locket @ file:///tmp/build/80754af9/locket_1647006009810/work +lxml @ file:///tmp/build/80754af9/lxml_1646624513062/work +magic-filter==1.0.9 +Markdown @ file:///tmp/build/80754af9/markdown_1614363852612/work +MarkupSafe @ file:///tmp/build/80754af9/markupsafe_1621523467000/work +matplotlib @ file:///tmp/build/80754af9/matplotlib-suite_1647441664166/work +matplotlib-inline @ file:///tmp/build/80754af9/matplotlib-inline_1628242447089/work +mattermostwrapper==2.2 +mccabe==0.6.1 +mistune @ file:///tmp/build/80754af9/mistune_1607364877025/work +mkl-fft==1.3.1 +mkl-random @ file:///tmp/build/80754af9/mkl_random_1626186066731/work +mkl-service==2.4.0 +mock @ file:///tmp/build/80754af9/mock_1607622725907/work +mpmath==1.2.1 +msgpack @ file:///tmp/build/80754af9/msgpack-python_1612287166301/work +multidict @ file:///opt/conda/conda-bld/multidict_1640703752579/work +multipledispatch @ file:///tmp/build/80754af9/multipledispatch_1607574243360/work +munkres==1.1.4 +mypy-extensions==0.4.3 +navigator-updater==0.2.1 +nbclassic @ file:///opt/conda/conda-bld/nbclassic_1644943264176/work +nbclient @ file:///tmp/build/80754af9/nbclient_1650290509967/work +nbconvert @ file:///opt/conda/conda-bld/nbconvert_1649751911790/work +nbformat @ file:///tmp/build/80754af9/nbformat_1649826788557/work +nest-asyncio @ file:///tmp/build/80754af9/nest-asyncio_1649847906199/work +networkx==2.6.3 +nltk @ file:///opt/conda/conda-bld/nltk_1645628263994/work +nose @ file:///opt/conda/conda-bld/nose_1642704612149/work +notebook @ file:///tmp/build/80754af9/notebook_1645002532094/work +numba @ file:///opt/conda/conda-bld/numba_1648040517072/work +numexpr @ file:///tmp/build/80754af9/numexpr_1640689833592/work +numpy @ file:///tmp/build/80754af9/numpy_and_numpy_base_1649764630438/work +numpydoc @ file:///opt/conda/conda-bld/numpydoc_1643788541039/work +oauthlib==3.2.2 +olefile @ file:///Users/ktietz/demo/mc3/conda-bld/olefile_1629805411829/work +opencv-python==4.7.0.72 +openpyxl @ file:///tmp/build/80754af9/openpyxl_1632777717936/work +opt-einsum==3.3.0 +packaging==20.9 +pamqp==3.2.1 +pandas==1.4.2 +pandocfilters @ file:///opt/conda/conda-bld/pandocfilters_1643405455980/work +panel @ file:///opt/conda/conda-bld/panel_1650637168846/work +param @ file:///tmp/build/80754af9/param_1636647414893/work +parsel @ file:///tmp/build/80754af9/parsel_1646722533460/work +parso @ file:///opt/conda/conda-bld/parso_1641458642106/work +partd @ file:///opt/conda/conda-bld/partd_1647245470509/work +pathspec==0.7.0 +patsy==0.5.2 +pep8==1.7.1 +pexpect @ file:///tmp/build/80754af9/pexpect_1605563209008/work +pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work +Pillow==9.0.1 +pkginfo @ file:///tmp/build/80754af9/pkginfo_1643162084911/work +plotly @ file:///opt/conda/conda-bld/plotly_1646671701182/work +pluggy @ file:///tmp/build/80754af9/pluggy_1648024445381/work +poyo @ file:///tmp/build/80754af9/poyo_1617751526755/work +prometheus-client @ file:///opt/conda/conda-bld/prometheus_client_1643788673601/work +prompt-toolkit @ file:///tmp/build/80754af9/prompt-toolkit_1633440160888/work +Protego @ file:///tmp/build/80754af9/protego_1598657180827/work +protobuf==3.19.1 +psutil @ file:///tmp/build/80754af9/psutil_1612297992929/work +psycopg2-binary==2.9.6 +ptyprocess @ file:///tmp/build/80754af9/ptyprocess_1609355006118/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl +pure-eval @ file:///opt/conda/conda-bld/pure_eval_1646925070566/work +py @ file:///opt/conda/conda-bld/py_1644396412707/work +pyasn1 @ file:///Users/ktietz/demo/mc3/conda-bld/pyasn1_1629708007385/work +pyasn1-modules==0.2.8 +pycodestyle @ file:///tmp/build/80754af9/pycodestyle_1615748559966/work +pycosat==0.6.3 +pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work +pyct @ file:///tmp/build/80754af9/pyct_1613411549454/work +pycurl==7.44.1 +pydantic==1.10.2 +PyDispatcher==2.0.5 +pydocstyle @ file:///tmp/build/80754af9/pydocstyle_1621600989141/work +pydot==1.4.2 +pyerfa @ file:///tmp/build/80754af9/pyerfa_1621556109336/work +pyflakes @ file:///tmp/build/80754af9/pyflakes_1617200973297/work +Pygments @ file:///opt/conda/conda-bld/pygments_1644249106324/work +PyHamcrest @ file:///tmp/build/80754af9/pyhamcrest_1615748656804/work +PyJWT @ file:///tmp/build/80754af9/pyjwt_1619682484438/work +pykwalify==1.8.0 +pylint @ file:///tmp/build/80754af9/pylint_1627536788603/work +pyls-spyder==0.4.0 +pymongo==3.10.1 +pyodbc @ file:///tmp/build/80754af9/pyodbc_1647425888968/work +pyOpenSSL @ file:///tmp/build/80754af9/pyopenssl_1635333100036/work +pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work +pyrsistent @ file:///tmp/build/80754af9/pyrsistent_1636110951836/work +PySocks @ file:///tmp/build/80754af9/pysocks_1605305812635/work +pytest==7.1.1 +python-crfsuite==0.9.9 +python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work +python-engineio==4.4.0 +python-lsp-black @ file:///tmp/build/80754af9/python-lsp-black_1634232156041/work +python-lsp-jsonrpc==1.0.0 +python-lsp-server==1.2.4 +python-slugify @ file:///tmp/build/80754af9/python-slugify_1620405669636/work +python-snappy @ file:///tmp/build/80754af9/python-snappy_1610133040135/work +python-socketio==5.8.0 +pytz==2021.3 +pytz-deprecation-shim==0.1.0.post0 +pyviz-comms @ file:///tmp/build/80754af9/pyviz_comms_1623747165329/work +PyWavelets @ file:///tmp/build/80754af9/pywavelets_1648710015787/work +pyxdg @ file:///tmp/build/80754af9/pyxdg_1603822279816/work +PyYAML==6.0 +pyzmq @ file:///tmp/build/80754af9/pyzmq_1638434985866/work +QDarkStyle @ file:///tmp/build/80754af9/qdarkstyle_1617386714626/work +qstylizer @ file:///tmp/build/80754af9/qstylizer_1617713584600/work/dist/qstylizer-0.1.10-py2.py3-none-any.whl +QtAwesome @ file:///tmp/build/80754af9/qtawesome_1637160816833/work +qtconsole @ file:///opt/conda/conda-bld/qtconsole_1649078897110/work +QtPy @ file:///opt/conda/conda-bld/qtpy_1649073884068/work +questionary==1.10.0 +queuelib==1.5.0 +randomname==0.1.5 +rasa==3.5.4 +rasa-sdk==3.5.0 +redis==4.5.4 +regex @ file:///tmp/build/80754af9/regex_1648447707500/work +requests @ file:///opt/conda/conda-bld/requests_1641824580448/work +requests-file @ file:///Users/ktietz/demo/mc3/conda-bld/requests-file_1629455781986/work +requests-oauthlib==1.3.1 +requests-toolbelt==0.10.1 +rocketchat-API==1.28.1 +rope @ file:///opt/conda/conda-bld/rope_1643788605236/work +rsa @ file:///tmp/build/80754af9/rsa_1614366226499/work +Rtree @ file:///tmp/build/80754af9/rtree_1618420843093/work +ruamel-yaml-conda @ file:///tmp/build/80754af9/ruamel_yaml_1616016711199/work +ruamel.yaml==0.17.21 +ruamel.yaml.clib==0.2.7 +s3transfer @ file:///tmp/build/80754af9/s3transfer_1626435152308/work +sanic==21.12.2 +Sanic-Cors==2.0.1 +sanic-jwt==1.8.0 +sanic-routing==0.7.2 +scikit-image @ file:///tmp/build/80754af9/scikit-image_1648214171611/work +scikit-learn @ file:///tmp/build/80754af9/scikit-learn_1642617106979/work +scikit-learn-intelex==2021.20220215.212715 +scipy @ file:///tmp/build/80754af9/scipy_1641555004408/work +Scrapy @ file:///tmp/build/80754af9/scrapy_1646837771788/work +seaborn @ file:///tmp/build/80754af9/seaborn_1629307859561/work +SecretStorage @ file:///tmp/build/80754af9/secretstorage_1614022780358/work +Send2Trash @ file:///tmp/build/80754af9/send2trash_1632406701022/work +sentry-sdk==1.14.0 +service-identity @ file:///Users/ktietz/demo/mc3/conda-bld/service_identity_1629460757137/work +sip==4.19.13 +six @ file:///tmp/build/80754af9/six_1644875935023/work +sklearn-crfsuite==0.3.6 +slack-sdk==3.21.0 +smart-open @ file:///tmp/build/80754af9/smart_open_1623928409369/work +sniffio @ file:///tmp/build/80754af9/sniffio_1614030464178/work +snowballstemmer @ file:///tmp/build/80754af9/snowballstemmer_1637937080595/work +sortedcollections @ file:///tmp/build/80754af9/sortedcollections_1611172717284/work +sortedcontainers @ file:///tmp/build/80754af9/sortedcontainers_1623949099177/work +soupsieve @ file:///tmp/build/80754af9/soupsieve_1636706018808/work +Sphinx @ file:///opt/conda/conda-bld/sphinx_1643644169832/work +sphinxcontrib-applehelp @ file:///home/ktietz/src/ci/sphinxcontrib-applehelp_1611920841464/work +sphinxcontrib-devhelp @ file:///home/ktietz/src/ci/sphinxcontrib-devhelp_1611920923094/work +sphinxcontrib-htmlhelp @ file:///tmp/build/80754af9/sphinxcontrib-htmlhelp_1623945626792/work +sphinxcontrib-jsmath @ file:///home/ktietz/src/ci/sphinxcontrib-jsmath_1611920942228/work +sphinxcontrib-qthelp @ file:///home/ktietz/src/ci/sphinxcontrib-qthelp_1611921055322/work +sphinxcontrib-serializinghtml @ file:///tmp/build/80754af9/sphinxcontrib-serializinghtml_1624451540180/work +spyder @ file:///tmp/build/80754af9/spyder_1636479868270/work +spyder-kernels @ file:///tmp/build/80754af9/spyder-kernels_1634236920897/work +SQLAlchemy @ file:///tmp/build/80754af9/sqlalchemy_1647581680159/work +stack-data @ file:///opt/conda/conda-bld/stack_data_1646927590127/work +statsmodels @ file:///tmp/build/80754af9/statsmodels_1648015433305/work +sympy @ file:///tmp/build/80754af9/sympy_1647853653589/work +tables @ file:///tmp/build/80754af9/pytables_1607975397488/work +tabulate==0.8.9 +tarsafe==0.0.3 +TBB==0.2 +tblib @ file:///Users/ktietz/demo/mc3/conda-bld/tblib_1629402031467/work +tenacity @ file:///tmp/build/80754af9/tenacity_1626248292117/work +tensorboard==2.11.2 +tensorboard-data-server==0.6.1 +tensorboard-plugin-wit==1.8.1 +tensorflow==2.11.0 +tensorflow-addons==0.19.0 +tensorflow-estimator==2.11.0 +tensorflow-hub==0.12.0 +tensorflow-io-gcs-filesystem==0.32.0 +tensorflow-text==2.11.0 +termcolor==2.2.0 +terminado @ file:///tmp/build/80754af9/terminado_1644322582718/work +terminaltables==3.1.10 +testpath @ file:///tmp/build/80754af9/testpath_1624638946665/work +text-unidecode @ file:///Users/ktietz/demo/mc3/conda-bld/text-unidecode_1629401354553/work +textdistance @ file:///tmp/build/80754af9/textdistance_1612461398012/work +threadpoolctl @ file:///Users/ktietz/demo/mc3/conda-bld/threadpoolctl_1629802263681/work +three-merge @ file:///tmp/build/80754af9/three-merge_1607553261110/work +tifffile @ file:///tmp/build/80754af9/tifffile_1627275862826/work +tinycss @ file:///tmp/build/80754af9/tinycss_1617713798712/work +tldextract @ file:///opt/conda/conda-bld/tldextract_1646638314385/work +toml @ file:///tmp/build/80754af9/toml_1616166611790/work +tomli @ file:///tmp/build/80754af9/tomli_1637314251069/work +toolz @ file:///tmp/build/80754af9/toolz_1636545406491/work +tornado @ file:///tmp/build/80754af9/tornado_1606942317143/work +tqdm @ file:///opt/conda/conda-bld/tqdm_1650891076910/work +traitlets @ file:///tmp/build/80754af9/traitlets_1636710298902/work +twilio==7.14.2 +Twisted @ file:///tmp/build/80754af9/twisted_1646835200521/work +typed-ast @ file:///tmp/build/80754af9/typed-ast_1624953673314/work +typeguard==3.0.2 +typing-utils==0.1.0 +typing_extensions==4.5.0 +tzdata==2023.3 +tzlocal==4.3 +ujson @ file:///tmp/build/80754af9/ujson_1648025916270/work +Unidecode @ file:///tmp/build/80754af9/unidecode_1614712377438/work +urllib3==1.26.15 +uvloop==0.17.0 +w3lib @ file:///Users/ktietz/demo/mc3/conda-bld/w3lib_1629359764703/work +watchdog @ file:///tmp/build/80754af9/watchdog_1638367282716/work +wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work +webencodings==0.5.1 +webexteamssdk==1.6.1 +websocket-client @ file:///tmp/build/80754af9/websocket-client_1614803975924/work +websockets==10.4 +Werkzeug @ file:///opt/conda/conda-bld/werkzeug_1645628268370/work +widgetsnbextension @ file:///tmp/build/80754af9/widgetsnbextension_1644992802045/work +wrapt @ file:///tmp/build/80754af9/wrapt_1607574498026/work +wurlitzer @ file:///tmp/build/80754af9/wurlitzer_1638368168359/work +xarray @ file:///opt/conda/conda-bld/xarray_1639166117697/work +xlrd @ file:///tmp/build/80754af9/xlrd_1608072521494/work +XlsxWriter @ file:///opt/conda/conda-bld/xlsxwriter_1649073856329/work +yapf @ file:///tmp/build/80754af9/yapf_1615749224965/work +yarl @ file:///tmp/build/80754af9/yarl_1606939947528/work +zict==2.0.0 +zipp @ file:///opt/conda/conda-bld/zipp_1641824620731/work +zope.interface @ file:///tmp/build/80754af9/zope.interface_1625036153595/work diff --git a/Attendence/test_attendence.py b/Attendence/test_attendence.py new file mode 100644 index 0000000..bc7ac52 --- /dev/null +++ b/Attendence/test_attendence.py @@ -0,0 +1,557 @@ +from flask import Flask, render_template, request, redirect, Response, send_file +import multiprocessing +import face_recognition +import os +import asyncio +#from flask_cors import CORS +app = Flask(__name__) +#CORS(app) +lst = [] + + +@app.route('/', methods=['GET']) +def resume(): + #return render_template('index.html') + return 'Attendence test app running' + +def createEncodings(image): + print("Encoding") + """ + Create face encodings for a given image and also return face locations in the given image. + Parameters + ------- + image : cv2 mat + Image you want to detect faces from. + Returns + ------- + known_encodings : list of np array + List of face encodings in a given image + face_locations : list of tuples + list of tuples for face locations in a given image + """ + # Find face locations for all faces in an image + face_locations = face_recognition.face_locations(image) + # Create encodings for all faces in an image + known_encodings = face_recognition.face_encodings(image, known_face_locations=face_locations) + return known_encodings, face_locations +#@app.route('/registered', methods=["POST","GET"]) +def registered(url_list): + input=url_list + + from pathlib import Path + Path("ppeople").mkdir(exist_ok=True) + Path("ppeople/" + input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + #z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y+ '.'+ z + print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + img_data = x.encode() + + import base64 + + with open("ppeople/" + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + fh.close() + + img = "ppeople/" + y + "/" + name + saveLocation = "ppeople/" + y + "/" + y + ".pickle" + + ############ detecting no of faceses ####################### + + + # import cv2 + # import numpy as np + # import dlib + + + # # Connects to your computer's default camera + # cap = cv2.imread(img) + + # # Detect the coordinates + # detector = dlib.get_frontal_face_detector() + + # number_of_faces=[] + # # Capture frames continuously + # # while True: + + # # Capture frame-by-frame + # # ret, frame = cap + # frame = cap + + # # RGB to grayscale + # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + # faces = detector(gray) + + # # Iterator to count faces + # i = 0 + # for face in faces: + + # # Get the coordinates of faces + # x, y = face.left(), face.top() + # x1, y1 = face.right(), face.bottom() + # cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # # Increment iterator for each face in faces + # i = i+1 + + # # Display the box and faces + # cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + # cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # # if len(i)>1: + # # print(i) + # number_of_faces.append(i) + + + # if (len(number_of_faces))>1: + # print("Group Photo") + # return "Group Photo" + # elif (len(number_of_faces))==1: + # print("Single Photo") + # pass + + + + + + def saveEncodings(encs, names, fname='encodings.pickle'): + """ + Save encodings in a pickle file to be used in future. + + Parameters + ---------- + encs : List of np arrays + List of face encodings. + names : List of strings + List of names for each face encoding. + fname : String, optional + Name/Location for pickle file. The default is "encodings.pickle". + + Returns + ------- + None. + + """ + + data = [] + d = [{"name": nm, "encoding": enc} for (nm, enc) in zip(names, encs)] + data.extend(d) + + encodingsFile = fname + + # dump the facial encodings data to disk + print("[INFO] serializing encodings...") + print("[INFO] Encodings Created sucessfully") + f = open(encodingsFile, "wb") + f.write(pickle.dumps(data)) + f.close() + + # Function to create encodings and get face locations + + + def processKnownPeopleImages(img=img, saveLocation=saveLocation): + """ + Process images of known people and create face encodings to compare in future. + Eaach image should have just 1 face in it. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "C:/inetpub/vhosts/port82/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + Returns + ------- + None. + """ + known_encodings = [] + known_names = [] + # for img in os.listdir(path): + + imgPath = img + # Read image + image = cv2.imread(imgPath) + name = img.rsplit('.')[0] + # Resize + try: + print(image.shape) + except AttributeError: + return "Successfully saved encoding........." + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + # Get locations and encodings + encs, locs = createEncodings(image) + try: + known_encodings.append(encs[0]) + except IndexError: + os.remove(saveLocation) + print('------------------------------------- save location --------------------------------') + print(saveLocation) + return "hello world!" + + + # known_encodings.append(encs[0]) + known_names.append(name) + for loc in locs: + top, right, bottom, left = loc + # Show Image + # cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2) + # cv2.imshow("Image", image) + # cv2.waitKey(1) + # cv2.destroyAllWindows() + saveEncodings(known_encodings, known_names, saveLocation) + + import cv2 + #import face_recognition + import pickle + + processKnownPeopleImages(img, saveLocation) + return 'Successfully saved encoding.........' + + +# ******************************** COMPARUISION ********************************************************* +#@app.route('/submit', methods=["POST","GET"]) +def submit(url_list): + + from datetime import datetime + import pytz + tz_NY = pytz.timezone('Asia/Kolkata') + datetime_NY = datetime.now(tz_NY) + India_Date = (datetime_NY.strftime("%Y-%m-%d")) + India_Date = str(India_Date) + India_Time = (datetime_NY.strftime("%I:%M:%S %p")) + India_Time = str(India_Time) + input=url_list + import pickle + import cv2 + + from pathlib import Path + Path("GGallery").mkdir(exist_ok=True) + Path("GGallery/" + input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + # z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y + '.' + z + # print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + img_data = x.encode() + + import base64 + + + with open("GGallery/" + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + fh.close() + + path = "GGallery/" + y + "/" + name + pickle_location = "ppeople/" + y + "/" + y + ".pickle" + import pathlib + file = pathlib.Path(pickle_location) + if file.exists (): + pass + else: + print ("pickle File not exist") + print(name) + return "Face not found in profile (please change your profile)" + + check_faces="ppeople/" + y + "/" + y + ".jpg" + print(check_faces) + + + ############ detecting no of faceses ####################### + + + import cv2 + import numpy as np + import dlib + + + # Connects to your computer's default camera + cap = cv2.imread(check_faces) + + # Detect the coordinates + detector = dlib.get_frontal_face_detector() + + number_of_faces=[] + # Capture frames continuously + # while True: + + # Capture frame-by-frame + # ret, frame = cap + frame = cap + + # RGB to grayscale + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + faces = detector(gray) + + # Iterator to count faces + i = 0 + for face in faces: + + # Get the coordinates of faces + x, y = face.left(), face.top() + x1, y1 = face.right(), face.bottom() + cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # Increment iterator for each face in faces + i = i+1 + + # Display the box and faces + cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # if len(i)>1: + # print(i) + number_of_faces.append(i) + + + if (len(number_of_faces))>1: + print("Group Photo") + return "Group Photo" + elif (len(number_of_faces))==1: + print("Single Photo") + pass + + + + + def readEncodingsPickle(fname): + """ + Read Pickle file. + + Parameters + ---------- + fname : String + Name of pickle file.(Full location) + + Returns + ------- + encodings : list of np arrays + list of all saved encodings + names : List of Strings + List of all saved names + + """ + + + data = pickle.loads(open(fname, "rb").read()) + + + data = np.array(data) + encodings = [d["encoding"] for d in data] + names = [d["name"] for d in data] + return encodings, names + + + def compareFaceEncodings(unknown_encoding, known_encodings, known_names): + """ + Compares face encodings to check if 2 faces are same or not. + + Parameters + ---------- + unknown_encoding : np array + Face encoding of unknown people. + known_encodings : np array + Face encodings of known people. + known_names : list of strings + Names of known people + + Returns + ------- + acceptBool : Bool + face matched or not + duplicateName : String + Name of matched face + distance : Float + Distance between 2 faces + + """ + duplicateName = "" + distance = 0.0 + matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.5) + + face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) + + best_match_index = np.argmin(face_distances) + + distance = face_distances[best_match_index] + if matches[best_match_index]: + acceptBool = True + duplicateName = known_names[best_match_index] + else: + acceptBool = False + duplicateName = "" + return acceptBool, duplicateName, distance + + #p = [] + + + def processDatasetImages(path=path, pickle_location=pickle_location): + """ + Process image in dataset from where you want to separate images. + It separates the images into directories of known people, groups and any unknown people images. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "D:/port1004/port1004/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + + Returns + ------- + None. + + """ + # Read pickle file for known people to compare faces from + + people_encodings, names = readEncodingsPickle(pickle_location) + # print(p) + # imgPath = path + img + + # Read image + # path=r"C:\Users\katku\Pictures\final\100011460000611.jpg" + image = cv2.imread(path) + #orig = image.copy() + + # Resize + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + + # Get locations and encodings + encs, locs = createEncodings(image) + + # Save image to a group image folder if more than one face is in image + # if len(locs) > 1: + # saveImageToDirectory(orig, "Group", img) + + # Processing image for each face + i = 0 + knownFlag = 0 + for loc in locs: + top, right, bottom, left = loc + unknown_encoding = encs[i] + i += 1 + acceptBool, duplicateName, distance = compareFaceEncodings(unknown_encoding, people_encodings, names) + if acceptBool: + # saveImageToDirectory(orig, duplicateName,name) + knownFlag = 1 + if knownFlag == 1: + print("Match Found") + + + #print(path) + with_extension = path.split("/")[-1] + without_extension = with_extension.split(".")[0] + + # output_s = {"FileID": without_extension, + # "Date": India_Date, + # "Time": India_Time} + # output_json = json.dumps(output_s) + output_json='Matched successfully' + print(loc) + lst.append(output_json) + + print(output_json) + # exit() + + else: + print('Not Matched') + pass + # saveImageToDirectory(orig, "0",name) + + + import numpy as np + import json + + processDatasetImages(path, pickle_location) + return lst[0] + #return 'matched successfully' + + +@app.route('/test_detect', methods=["POST"]) +def detect(): + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + + # id = "100013660000125" + url_list.append(Dataset) + # multiprocessing + with multiprocessing.Pool(processes=2) as pool: + try: + results = pool.map(submit, url_list) + except FileNotFoundError: + return 'plese get registered with your PhotoID' + except IndexError: + #return 'unable to recognize face' + return 'failed' + + pool.close() + + return results[0] + + + + +@app.route('/test_register', methods=["POST"]) +def register(): + print("hello start..........") + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + # referrer = request.headers + # print(referrer) + # id = "100013660000125" + url_list.append(Dataset) + UserLocaton=Dataset["FilePath"] + print(UserLocaton) + if "c02" in UserLocaton: + return "Please update url in integration" + else: + pass + # multiprocessing + with multiprocessing.Pool(processes=2) as pool: + try: + results = pool.map(registered, url_list) + except IndexError: + pass + print('face not found') + except FileNotFoundError: + pass + + + #os.remove(img) + # return 'unable to recognize face' + + pool.close() + #return results[0] + return 'Successfully saved encoding.........' + + + + +if __name__ == "__main__": + app.run(host='0.0.0.0',port =5004,debug=False) \ No newline at end of file diff --git a/Attendence/uat_attendence.py b/Attendence/uat_attendence.py new file mode 100644 index 0000000..2c3c1e4 --- /dev/null +++ b/Attendence/uat_attendence.py @@ -0,0 +1,559 @@ +from flask import Flask, render_template, request, redirect, Response, send_file +import multiprocessing +import face_recognition +#from numba import jit +import numpy as np +import os +#from flask_cors import CORS +app = Flask(__name__) +#CORS(app) +lst = [] + + +@app.route('/', methods=['GET']) +def resume(): + #return render_template('index.html') + return 'Attendence app running' + +def createEncodings(image): + print("Encoding") + """ + Create face encodings for a given image and also return face locations in the given image. + Parameters + ------- + image : cv2 mat + Image you want to detect faces from. + Returns + ------- + known_encodings : list of np array + List of face encodings in a given image + face_locations : list of tuples + list of tuples for face locations in a given image + """ + # Find face locations for all faces in an image + face_locations = face_recognition.face_locations(image) + # Create encodings for all faces in an image + known_encodings = face_recognition.face_encodings(image, known_face_locations=face_locations) + return known_encodings, face_locations +#@app.route('/registered', methods=["POST","GET"]) +def registered(url_list): + input=url_list + + from pathlib import Path + Path("ppeople").mkdir(exist_ok=True) + Path("ppeople/" + input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + #z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y+ '.'+ z + print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + try: + img_data = x.encode() + except AttributeError: + return "Successfully saved encoding........." + + import base64 + + with open("ppeople/" + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + + img = "ppeople/" + y + "/" + name + saveLocation = "ppeople/" + y + "/" + y + ".pickle" + + ############ detecting no of faceses ####################### + + + # import cv2 + # import numpy as np + # import dlib + + + # # Connects to your computer's default camera + # cap = cv2.imread(img) + + # # Detect the coordinates + # detector = dlib.get_frontal_face_detector() + + # number_of_faces=[] + # # Capture frames continuously + # # while True: + + # # Capture frame-by-frame + # # ret, frame = cap + # frame = cap + + # # RGB to grayscale + # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + # faces = detector(gray) + + # # Iterator to count faces + # i = 0 + # for face in faces: + + # # Get the coordinates of faces + # x, y = face.left(), face.top() + # x1, y1 = face.right(), face.bottom() + # cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # # Increment iterator for each face in faces + # i = i+1 + + # # Display the box and faces + # cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + # cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # # if len(i)>1: + # # print(i) + # number_of_faces.append(i) + + + # if (len(number_of_faces))>1: + # print("Group Photo") + # return "Group Photo" + # elif (len(number_of_faces))==1: + # print("Single Photo") + # pass + + + + + + def saveEncodings(encs, names, fname='encodings.pickle'): + """ + Save encodings in a pickle file to be used in future. + + Parameters + ---------- + encs : List of np arrays + List of face encodings. + names : List of strings + List of names for each face encoding. + fname : String, optional + Name/Location for pickle file. The default is "encodings.pickle". + + Returns + ------- + None. + + """ + + data = [] + d = [{"name": nm, "encoding": enc} for (nm, enc) in zip(names, encs)] + data.extend(d) + + encodingsFile = fname + + # dump the facial encodings data to disk + print("[INFO] serializing encodings...") + print("[INFO] Encodings Created sucessfully") + f = open(encodingsFile, "wb") + f.write(pickle.dumps(data)) + f.close() + + # Function to create encodings and get face locations + + + def processKnownPeopleImages(img=img, saveLocation=saveLocation): + """ + Process images of known people and create face encodings to compare in future. + Eaach image should have just 1 face in it. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "C:/inetpub/vhosts/port82/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + Returns + ------- + None. + """ + known_encodings = [] + known_names = [] + # for img in os.listdir(path): + + imgPath = img + # Read image + image = cv2.imread(imgPath) + name = img.rsplit('.')[0] + # Resize + try: + print(image.shape) + except AttributeError: + return "Successfully saved encoding........." + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + # Get locations and encodings + encs, locs = createEncodings(image) + try: + known_encodings.append(encs[0]) + except IndexError: + os.remove(saveLocation) + print('------------------------------------- save location --------------------------------') + print(saveLocation) + return "hello world!" + + + # known_encodings.append(encs[0]) + known_names.append(name) + for loc in locs: + top, right, bottom, left = loc + # Show Image + # cv2.rectangle(image, (left, top), (right, bottom), color=(255, 0, 0), thickness=2) + # cv2.imshow("Image", image) + # cv2.waitKey(1) + # cv2.destroyAllWindows() + saveEncodings(known_encodings, known_names, saveLocation) + + import cv2 + #import face_recognition + import pickle + + processKnownPeopleImages(img, saveLocation) + return 'Successfully saved encoding.........' + + +# ******************************** COMPARUISION ********************************************************* +#@app.route('/submit', methods=["POST","GET"]) +def submit(url_list): + + from datetime import datetime + import pytz + tz_NY = pytz.timezone('Asia/Kolkata') + datetime_NY = datetime.now(tz_NY) + India_Date = (datetime_NY.strftime("%Y-%m-%d")) + India_Date = str(India_Date) + # India_Time = (datetime_NY.strftime("%I:%M:%S %p")) + # India_Time = str(India_Time) + input=url_list + import pickle + import cv2 + + from pathlib import Path + Path("GGallery/"+ India_Date).mkdir(exist_ok=True) + Path("GGallery/"+ India_Date +'/'+ input["FileName"]).mkdir(exist_ok=True) + + a = input + # print(a) + x = a['FileData'] + # print(x) + y = a['FileName'] + # z = a['FileType'] + z='jpg' + # CreatedBy=a['CreatedBy'] + + name = y + '.' + z + # print(name) + # print(y) + # image = y.split("/") + # filename=image[-1] + + # print(x) + img_data = x.encode() + + import base64 + + + with open("GGallery/"+India_Date+'/' + input["FileName"] + "/" + name, "wb") as fh: + fh.write(base64.decodebytes(img_data)) + + path = "GGallery/" +India_Date+'/'+ y + "/" + name + pickle_location = "ppeople/" + y + "/" + y + ".pickle" + import pathlib + file = pathlib.Path(pickle_location) + if file.exists (): + pass + else: + print ("pickle File not exist") + print(name) + return "Face not found in profile (please change your profile)" + + check_faces="ppeople/" + y + "/" + y + ".jpg" + print(check_faces) + + + ############ detecting no of faceses ####################### + + + import cv2 + import numpy as np + import dlib + + + # Connects to your computer's default camera + cap = cv2.imread(check_faces) + + # Detect the coordinates + detector = dlib.get_frontal_face_detector() + + number_of_faces=[] + # Capture frames continuously + # while True: + + # Capture frame-by-frame + # ret, frame = cap + frame = cap + + # RGB to grayscale + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + faces = detector(gray) + + # Iterator to count faces + i = 0 + for face in faces: + + # Get the coordinates of faces + x, y = face.left(), face.top() + x1, y1 = face.right(), face.bottom() + cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2) + # Increment iterator for each face in faces + i = i+1 + + # Display the box and faces + cv2.putText(frame, 'face num'+str(i), (x-10, y-10), + cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + + # if len(i)>1: + # print(i) + number_of_faces.append(i) + + + if (len(number_of_faces))>1: + print("Group Photo") + return "Group Photo" + elif (len(number_of_faces))==1: + print("Single Photo") + pass + + + + + def readEncodingsPickle(fname): + """ + Read Pickle file. + + Parameters + ---------- + fname : String + Name of pickle file.(Full location) + + Returns + ------- + encodings : list of np arrays + list of all saved encodings + names : List of Strings + List of all saved names + + """ + + + data = pickle.loads(open(fname, "rb").read()) + + + data = np.array(data) + encodings = [d["encoding"] for d in data] + names = [d["name"] for d in data] + return encodings, names + + + def compareFaceEncodings(unknown_encoding, known_encodings, known_names): + """ + Compares face encodings to check if 2 faces are same or not. + + Parameters + ---------- + unknown_encoding : np array + Face encoding of unknown people. + known_encodings : np array + Face encodings of known people. + known_names : list of strings + Names of known people + + Returns + ------- + acceptBool : Bool + face matched or not + duplicateName : String + Name of matched face + distance : Float + Distance between 2 faces + + """ + duplicateName = "" + distance = 0.0 + matches = face_recognition.compare_faces(known_encodings, unknown_encoding, tolerance=0.54) + face_distances = face_recognition.face_distance(known_encodings, unknown_encoding) + + best_match_index = np.argmin(face_distances) + + distance = face_distances[best_match_index] + if matches[best_match_index]: + acceptBool = True + duplicateName = known_names[best_match_index] + else: + acceptBool = False + duplicateName = "" + return acceptBool, duplicateName, distance + + #p = [] + + + def processDatasetImages(path=path, pickle_location=pickle_location): + """ + Process image in dataset from where you want to separate images. + It separates the images into directories of known people, groups and any unknown people images. + Parameters + ---------- + path : STRING, optional + Path for known people dataset. The default is "D:/port1004/port1004/wwwroot/_files/People". + It should be noted that each image in this dataset should contain only 1 face. + saveLocation : STRING, optional + Path for storing encodings for known people dataset. The default is "./known_encodings.pickle in current directory". + + Returns + ------- + None. + + """ + # Read pickle file for known people to compare faces from + + people_encodings, names = readEncodingsPickle(pickle_location) + # print(p) + # imgPath = path + img + + # Read image + # path=r"C:\Users\katku\Pictures\final\100011460000611.jpg" + image = cv2.imread(path) + #orig = image.copy() + + # Resize + image = cv2.resize(image, (0, 0), fx=0.9, fy=0.9, interpolation=cv2.INTER_LINEAR) + + # Get locations and encodings + encs, locs = createEncodings(image) + + # Save image to a group image folder if more than one face is in image + # if len(locs) > 1: + # saveImageToDirectory(orig, "Group", img) + + # Processing image for each face + i = 0 + knownFlag = 0 + for loc in locs: + top, right, bottom, left = loc + unknown_encoding = encs[i] + i += 1 + acceptBool, duplicateName, distance = compareFaceEncodings(unknown_encoding, people_encodings, names) + if acceptBool: + # saveImageToDirectory(orig, duplicateName,name) + knownFlag = 1 + if knownFlag == 1: + print("Match Found") + + + #print(path) + with_extension = path.split("/")[-1] + without_extension = with_extension.split(".")[0] + + # output_s = {"FileID": without_extension, + # "Date": India_Date, + # "Time": India_Time} + # output_json = json.dumps(output_s) + output_json='Matched successfully' + print(loc) + lst.append(output_json) + + print(output_json) + # exit() + + else: + print('Not Matched') + pass + # saveImageToDirectory(orig, "0",name) + + + import numpy as np + import json + + processDatasetImages(path, pickle_location) + return lst[0] + #return 'matched successfully' + + +@app.route('/uat01_detect', methods=["POST"]) +def detect(): + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + # id = "100013660000125" + url_list.append(Dataset) + # multiprocessing + pool_size = multiprocessing.cpu_count() * 2 + with multiprocessing.Pool(pool_size) as pool: + try: + results = pool.map(submit, url_list) + except FileNotFoundError: + return 'plese get registered with your PhotoID' + except IndexError: + #return 'unable to recognize face' + return 'failed' + + pool.close() + + return results[0] + + + +@app.route('/uat01_register', methods=["POST"]) +def register(): + print("hello start..........") + if __name__ == "__main__": + + url_list=[] + Dataset= request.get_json() + # id = "100013660000125" + url_list.append(Dataset) + UserLocation=Dataset["FilePath"] + print(UserLocation) + + # if "cO2" in UserLocation or UserLocation is None: + # pass + # else: + # return "Please update the URL in the integration" + + + # multiprocessing + pool_size = multiprocessing.cpu_count() * 2 + with multiprocessing.Pool(pool_size) as pool: + try: + results = pool.map(registered, url_list) + except IndexError: + pass + print('face not found') + except FileNotFoundError: + pass + + + #os.remove(img) + # return 'unable to recognize face' + + pool.close() + #return results[0] + return 'Successfully saved encoding.........' + + + + +if __name__ == "__main__": + app.run(host='0.0.0.0',port =5005,debug=False)