def test_rgba_int_array_facial_features(self): test_face = os.path.normpath(os.path.join(DIR, "data/48by48rgba.png")) response = facial_features(test_face) self.assertTrue(isinstance(response, list)) self.assertEqual(len(response), 48) self.check_range(response)
def test_good_facial_features(self): test_face = np.random.rand(48,48).tolist() response = facial_features(test_face) self.assertTrue(isinstance(response, list)) self.assertEqual(len(response), 48) self.check_range(response)
def test_good_facial_features(self): test_face = np.random.rand(48, 48).tolist() response = facial_features(test_face) self.assertTrue(isinstance(response, list)) self.assertEqual(len(response), 48) self.check_range(response)
def test_good_int_array_facial_features(self): fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy']) test_face = os.path.normpath(os.path.join(DIR, "data/48by48.png")) response = facial_features(test_face) self.assertTrue(isinstance(response, list)) self.assertEqual(len(response), 48) self.check_range(response)
def _grab_one(self, local_img_path, search_term): try: img = Image.open(local_img_path) self.captured_data.append( {'celeb': search_term, 'face_feats': indicoio.facial_features(img), 'face_corners': self._get_single_face_corners(img), 'local_img_path': local_img_path }) except: print('failed to grab facial feats for ' + local_img_path) self.failed_to_capture.append((local_img_path, search_term))
def _grab_one(self, local_img_path, search_term): try: img = Image.open(local_img_path) self.captured_data.append({ 'celeb': search_term, 'face_feats': indicoio.facial_features(img), 'face_corners': self._get_single_face_corners(img), 'local_img_path': local_img_path }) except: print('failed to grab facial feats for ' + local_img_path) self.failed_to_capture.append((local_img_path, search_term))
def recordFaceData(directory, nickname): allImages = [] count = 0 for file in os.listdir(directory): if file.endswith('.jpg'): allImages.append(file) currentRecordedFeatures = {} currentRecordedFeatures['names'] = [] currentRecordedFeatures['features'] = [] print 'Caching...' for image in allImages: print 'Collecting info ... ', count count += 1 face = indicoio.facial_localization(directory + '/' + image) if len(face) > 0: face = face[0] img = cv2.imread(directory + '/' + image) faceImg = img[ face['top_left_corner'][1] : face['bottom_right_corner'][1], face['top_left_corner'][0] : face['bottom_right_corner'][0] ] facialFeatures = indicoio.facial_features(faceImg) if (count % 50) == 0: cv2.imwrite('images/faces/' + str(int(time.time())) + '.jpg', faceImg) currentRecordedFeatures['names'].append(nickname) currentRecordedFeatures['features'].append(facialFeatures) np.save(featuresCacheFile + nickname + '.npy', [currentRecordedFeatures]) print 'Done' return currentRecordedFeatures
def test_batch_facial_features(self): test_data = [os.path.normpath(os.path.join(DIR, "data/48by48.png"))] response = facial_features(test_data, api_key=self.api_key) self.assertTrue(isinstance(response, list)) self.assertTrue(isinstance(response[0], list)) self.assertEqual(len(response[0]), 48)
def test_good_facial_features(self): test_face = np.linspace(0,50,48*48).reshape(48,48).tolist() response = facial_features(test_face) self.assertTrue(isinstance(response, list)) self.assertEqual(len(response), 48)
def identifyFaces(imgPath, testing=False): faces = extractFaces(imgPath) dataMisha = np.load('facialFeatures/facesMisha.npy')[0] dataMihai = np.load('facialFeatures/facesMihai.npy')[0] dataPavel = np.load('facialFeatures/facesPavel.npy')[0] dataRishab = np.load('facialFeatures/facesRishab.npy')[0] trainingNames = dataMisha['names'] + \ dataMihai['names'] + \ dataPavel['names'] + \ dataRishab['names'] trainingFeatures = dataMisha['features'] + \ dataMihai['features'] + \ dataPavel['features'] + \ dataRishab['features'] n_trainingNames = lb.fit_transform(trainingNames) # clf = SGDClassifier(loss="modified_huber", penalty="l1") # clf = SGDClassifier(loss="modified_huber", penalty="l1", epsilon=0.0001) # clf = NearestCentroid() clf = KNeighborsClassifier(n_neighbors=5, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None) clf.fit(trainingFeatures, n_trainingNames) for path in faces: print lb.inverse_transform(clf.predict(indicoio.facial_features(path))) if testing == True: predictedNames = [] trainingNames = dataMisha['names'][0:650] + \ dataMihai['names'][0:650] + \ dataPavel['names'][0:650] + \ dataRishab['names'][0:650] trainingFeatures = dataMisha['features'][0:650] + \ dataMihai['features'][0:650] + \ dataPavel['features'][0:650] + \ dataRishab['features'][0:650] testNames = dataMisha['names'][651:701] + \ dataMihai['names'][651:701] + \ dataPavel['names'][651:701] + \ dataRishab['names'][651:701] testFeatures = dataMisha['features'][651:701] + \ dataMihai['features'][651:701] + \ dataPavel['features'][651:701] + \ dataRishab['features'][651:701] correctCount = 0 count = 0 for x in range(0,len(testFeatures)): predictedName = clf.predict(testFeatures[x]) predictedNames.append(predictedName) predictedNames = lb.inverse_transform(predictedNames) for x in range(0,len(predictedNames)): print count , ' *** ', predictedNames[x], ' - ', testNames[x] count += 1 if predictedNames[x] == testNames[x]: correctCount += 1 print 'Correct % - ', (correctCount / float(len(predictedNames))) * 100 print correctCount, '/' , len(predictedNames)
def get_images_feats(images_paths): "returns list of np arrays of feats" results = indicoio.facial_features(images_paths) return [np.array(results[i]) for i in xrange(len(results))]