class TestEnrolSubjects(unittest.TestCase): def setUp(self): self.face_log = FaceLog() self.recognition = Recognition() def test_face_log(self): ''' This onlyt gets run if we do not have a valid sightings file which contains the name and a sighting id :return: ''' # If we have sightings file, lets return if os.path.isfile(SIGHTINGS_FILE): return # lets delete any subjects we may already have subjects = self.recognition.list_subjects() for subject in subjects: print 'Going to delete {0}'.format(subject['subject_id']) deleted_id = self.recognition.delete_subject(subject['subject_id']) self.assertEqual(subject['subject_id'], deleted_id) # these are the video files video_files = { 'Alberto': '{}/Subjects/Alberto.mov'.format(data_dir), 'Baris': '{}/Subjects/Baris.mov'.format(data_dir), 'Fred': '{}/Subjects/Fred.mov'.format(data_dir), 'Kjetil': '{}/Subjects/Kjetil.mov'.format(data_dir), 'Laurent': '{}/Subjects/Laurent.mov'.format(data_dir), 'Marie-Claude': '{}/Subjects/Marie-Claude.mov'.format(data_dir), 'Olivier': '{}/Subjects/Olivier.mov'.format(data_dir) } video_files1 = { 'Alberto': '{}/Subjects/Alberto.mov'.format(data_dir), } # lets run face-log and get the sightings, enrol the subjects sighting_list = {} for name, video_file in video_files.iteritems(): task = self.face_log.apply(video_file=video_file, download=False, gender=True, max_frames=10) self.assertTrue(task['success']) sightings = task['sightings'] self.assertEqual(1, len(sightings)) subject_id = self.recognition.create_subject(name=name) sighting_list[subject_id] = sightings[0]['sighting_id'] print '{} {} {}'.format(subject_id, name, sightings[0]['sighting_id']) # save to a file to do some things with with open(SIGHTINGS_FILE, 'w') as f: f.write(json.dumps(sighting_list)) def test_enrol(self): # check we have a sightings file self.assertTrue(os.path.isfile(SIGHTINGS_FILE)) with open(SIGHTINGS_FILE, 'r') as f: sightings = json.load(f) for subject_id, sighting_id in sightings.iteritems(): print subject_id, subject_id self.recognition.add_sighting_to_subject(sighting_id=sighting_id, subject_id=subject_id)
for image_file in image_files: basename = os.path.basename(image_file) name = os.path.splitext(basename)[0] ext = os.path.splitext(basename)[1].lower() if ext not in valid_images: continue try: print 'Enrolling {} from image {}'.format(name, image_file) enrol_from_image(args.host, args.key_file, args.verbose, image_file, name, args.tag) except: pass # Delete a subject if args.delete_subject: print 'Deleting subject with id {}'.format(args.delete_subject) try: recognition.delete_subject(args.delete_subject) except Exception as err: print('Trouble deleting subject', err) # Add a sighting to a subject if args.add_sighting and args.subject_id: print 'Add sighting {} to subject id {}'.format(args.add_sighting, args.subject_id) try: recognition.add_sighting_to_subject(args.add_sighting, args.subject_id) except Exception as err: print('Trouble adding sighting to subject', err)