def post(self): image_stream = self.request.files['img'][0] image_64_encode = base64.encodestring(image_stream['body']) image_64_decode = base64.decodestring(image_64_encode) print("-------Detection Started-----") detected_imgs = prep.init(image_64_decode) print("-------Detection Complete-----") print("No. of Detected Images ",len(detected_imgs)) print("-------Recognition Started-----") model = 'model/lightened_cnn/lightened_cnn' para = cmp.loadModel(model, 0) for index in range(len(detected_imgs)): inputPath = '/Users/admin/Work/Face_Recognition/out' print("Recognition started for Face ",index+1 ) cmp.compare_two_face(para, inputPath,detected_imgs[index]) print("-------Recognition Complete-----")
def process1(image_urls,d,folder): df = pd.DataFrame(dtype=np.int8) hashtable = {} st = time.time() for i in range(len(image_urls)): print("**************" + image_urls[i] + "*************************") img = urllib.request.urlopen(image_urls[i]).read() image_id = image_urls[i].split('/')[-1] image_64_encode = base64.encodestring(img) image_64_decode = base64.decodestring(image_64_encode) # image_64_decode = cv2.resize(image_64_decode, (image_64_decode.shape[0] / 4, image_64_decode.shape[1] / 4)) dst = time.time() detected_imgs = prep.init(image_64_decode) det = time.time() print("Time Taken In Detection on No. of faces ", (det - dst), len(detected_imgs)) for index in range(len(detected_imgs)): print("For Face************", index) rst = time.time() detected_face_id = image_id + '_' + str(index) noOfFacesInImage = len(detected_imgs) response = cmp.compare_two_face(para, detected_imgs[index], hashtable, detected_face_id, image_id, noOfFacesInImage) ret = time.time() # print("is_already_exist",response) print("Time Taken In Recognition ", (ret - rst)) if (response['is_already_exist'] == True): buildMatrix(response['classId'], image_id, noOfFacesInImage, df) elif (response['is_already_exist'] == False): buildHashTable(detected_face_id, detected_imgs[index], hashtable) buildMatrix(detected_face_id, image_id, noOfFacesInImage, df) # print(hashtable) df.fillna(0, inplace=True) print("**********dataFrame************") print(df) #print(image_urls[i].split('/')[-1]) name = os.path.join(d,folder+'_matrix.csv') print(name) df.to_csv(name) dff = get_most_frequent_faces(df) print("**********Most Frequent faces dataFrame************") print(dff) name = os.path.join(d, folder + '_result.csv') dff.to_csv(name) pics = get_pics_with_most_faces(dff) for p in pics[0:3]: os.rename(os.path.join(d,p), os.path.join(d,'top_'+p)) name = os.path.join(d, folder + '_result.csv') #pics.to_csv(name) # analyse(df) print("**********Final Output************") print(pics) et = time.time() logger.info("Time Taken In Detection And Recognition in folder {} {}".format(folder,((et - st) / 60)))
def get(self): from recognition import compare as cmp model='model/lightened_cnn/lightened_cnn' para = cmp.loadModel(model,0) print ("similar",cmp.compare_two_face(para,"/Users/admin/Work/Face_Recognition/output","151497675637119.jpg","151377336968480.jpg")) #cmp.compare_two_face(para, "/Users/admin/Work/facerecognition/out", "151426961291577.jpg") print("detect start") self.write("recognize")
def detectImageAndAssignClasses(obj, step, callback=None): image_64_decode = decodeImage(obj) print( "***************-------Detection Started FROM CAMERA-----*******************", step) detected_imgs = prep.init(image_64_decode) model = 'model/lightened_cnn/lightened_cnn' para = cmp.loadModel(model, 0) for index in range(len(detected_imgs)): response = cmp.compare_two_face( obj, para, os.environ.get("DETECTED_FACES_STORE_PATH"), detected_imgs[index], step, image_64_decode, createRandomImageId("main_img")) print( "***************-------Detection And Recognition Complete FROM CAMERA-----*******************", step) callback(response)
def process(): dir = "/Users/admin/Work/jaws-recognition-service/main" items = os.listdir(dir) print(items) i = 0 final = [] resp = [] elements = [] image_urls = [] # Append empty lists in first two indexes. elements.append([]) for folder in items: res = {} # images = os.listdir(os.path.join(dir, folder)) url = 'http://localhost:8888/main/' + folder image_urls.append(url) # for img in images: # url = 'http://localhost:8888/main/' + img # image_urls.append(url) # image_urls = ['http://localhost:8888/main/539266179/chetan_ashish.jpg','http://localhost:8888/main/539266232/faraz.jpg','http://localhost:8888/main/539266232/faraj_ashish_rahul.jpg'] print(image_urls) df = pd.DataFrame(dtype=np.int8) hashtable = {} st = time.time() for i in range(len(image_urls)): img = urllib.request.urlopen(image_urls[i]).read() image_id = image_urls[i].split('/')[-1] image_64_encode = base64.encodestring(img) image_64_decode = base64.decodestring(image_64_encode) dst = time.time() detected_imgs = prep.init(image_64_decode) det =time.time() print("Time Taken In Detection on No. of faces ", (det - dst),len(detected_imgs)) for index in range(len(detected_imgs)): print("For Face************",index) rst = time.time() detected_face_id =image_id + '_' + str(index) noOfFacesInImage = len(detected_imgs) response = cmp.compare_two_face(para,detected_imgs[index],hashtable,detected_face_id,image_id,noOfFacesInImage) ret = time.time() #print("is_already_exist",response) print("Time Taken In Recognition ", (ret - rst)) if(response['is_already_exist'] == True): buildMatrix(response['classId'], image_id, noOfFacesInImage,df) elif(response['is_already_exist'] == False): buildHashTable(detected_face_id,detected_imgs[index],hashtable) buildMatrix(detected_face_id,image_id,noOfFacesInImage,df) #print(hashtable) df.fillna(0, inplace=True) print("**********dataFrame************") print(df) dff = get_most_frequent_faces(df) print("**********Most Frequent faces dataFrame************") print(dff) pics = get_pics_with_most_faces(dff) #analyse(df) print("**********Final Output************") print(pics) et = time.time() print("Final Time Taken In Detection And Recognition ", (et - st))