def get_feats(number_of_features): path = './image_features/*.npy' files = glob.glob(path) feats = [] count = 0 bar_len = 60 total = number_of_features * 7 for name in files: # print(name) img = Image(name, npy=True) if (img.number <= number_of_features): count += 1 lib_pat.progress(count, total, name) feats_image = [] feats_image.append( np.load("./image_features/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyebrowL/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyebrowR/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./nose/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyeL/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyeR/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./mouth/lbp/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyebrowL/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyebrowR/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./nose/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyeL/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./eyeR/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feats_image.append( np.load("./mouth/tas/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")) feat = np.concatenate(feats_image, axis=1) feats.append([feat[0]]) feats = np.concatenate(feats, axis=1) feats = feats[0] print("") return (feats)
def extract(start, end): path = './faces/*.png' files = glob.glob(path) number_of_features = end - start + 1 lbp_params = ((1, 1, 2, 2, 5), (5, 10, 8, 15, 6)) har_params = ((1, 1, 1, 2, 5), (1, 10, 20, 11, 8)) gab1_params = (1, 2, 5, 10) gab2_params = (1, 2, 5, 10) count = 0 bar_len = 60 total = number_of_features * 7 for name in files: img = Image(name) if (img.number >= start and img.number <= end): image = cv2.imread(name, 0) lib_pat.progress(count, total, name) extraction_routine( "./image_features/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5), [image], lbp_params[0], lbp_params[1], har_params[0], har_params[1], gab1_params, gab2_params) count += 1 # filled_len = int(round(bar_len * count / float(total))) # percents = round(100.0 * count / float(total), 1) # bar = '=' * filled_len + '-' * (bar_len - filled_len) # sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', name)) # sys.stdout.flush() print("")
def get_feats(number_of_features): path = './image_features/*.npy' files = glob.glob(path) feats = [] count = 0 bar_len = 60 total = number_of_features * 7 for name in files: # print(name) img = Image(name, npy=True) if (img.number <= number_of_features): count += 1 lib_pat.progress(count, total, name) feats_image = [] feats_image.append( [np.load("./image_features/face_" + str(img.group).zfill(3) + "_" + str(img.number).zfill(5) + ".npy")[0]]) for i in range(len(feats_image)): while len(feats_image[i][0]) == 1: feats_image[i] = feats_image[i][0] try: feat = np.concatenate(feats_image, axis=1) feats.append([feat]) except ValueError: raise feats = np.concatenate(feats, axis=1) feats = feats[0] print("") return (feats)
def extraction_routine(arr_name, images, lbp_grids, lbp_dists, har_grids, har_dists, gab_grids1, gab_grids2): """ Saves to arr_name .npy the array of features extracted. Params MUST be tuples, use (1,) for single values :param lbp_grids: tuple :param lbp_dists: tuple, must be the same size than ibp_grids :param har_grids: idem :param har_dists: idem :param gab_grids1: idem :param gab_grids1: idem :return: void """ count = 0 total = len(lbp_grids) + len(har_grids) + len(gab_grids1) + len(gab_grids2) lbps = [] for i in range(len(lbp_grids)): # print('LPB Extraction, Iteration {}/{}'.format((i + 1), len(lbp_grids))) with mp.Pool() as p: lbp = p.starmap(lib_pat.get_LBP, [(images[j], lbp_dists[i], lbp_grids[i], j) for j in range(len(images))]) lbps.append(lbp) count += 1 lib_pat.progress(count, total, up=False) lbp_feats = np.concatenate(lbps, axis=1) hars = [] for i in range(len(har_grids)): # print('Haralick Extraction, Iteration {}/{}'.format((i + 1), len(har_grids))) with mp.Pool() as p: har = p.starmap(lib_pat.get_Haralick, [(images[j], har_dists[i], har_grids[i], j) for j in range(len(images))]) hars.append(har) count += 1 lib_pat.progress(count, total, up=False) har_feats = np.concatenate(hars, axis=1) gabs1 = [] for i in range(len(gab_grids1)): # print('Gabor Extraction, Iteration {}/{}'.format((i + 1), len(gab_grids1))) with mp.Pool() as p: gab = p.starmap(lib_pat.get_Gab, [(images[j], gab_grids1[i], j) for j in range(len(images))]) gabs1.append(gab) count += 1 lib_pat.progress(count, total, up=False) gab_feats1 = np.concatenate(gabs1, axis=1) gabs2 = [] for i in range(len(gab_grids2)): # print('Gabor Extraction, Iteration {}/{}'.format((i + 1), len(gab_grids2))) with mp.Pool() as p: gab = p.starmap(lib_pat.get_Gab_real_im, [(images[j], gab_grids2[i], j) for j in range(len(images))]) gabs2.append(gab) count += 1 lib_pat.progress(count, total, up=False) gab_feats2 = np.concatenate(gabs2, axis=1) feats = np.concatenate((lbp_feats, har_feats, gab_feats1, gab_feats2), axis=1) np.save(arr_name, feats) return feats
def get_feats_test(): path = './image_features_test/*.npy' files = glob.glob(path) feats = [] count = 0 bar_len = 60 total = len(files) for name in files: count += 1 lib_pat.progress(count, total, name) feats_image = [] feats_image.append([np.load(name)[0]]) for i in range(len(feats_image)): while len(feats_image[i][0]) == 1: feats_image[i] = feats_image[i][0] try: feat = np.concatenate(feats_image, axis=1) feats.append([feat]) except ValueError: raise feats = np.concatenate(feats, axis=1) feats = feats[0] print("") return (feats)