Beispiel #1
0
class TestSubject(unittest.TestCase):

        class TestData:
            def __init__(self, name, user_data):
                self.name = name
                self.user_data = user_data
                self.verbose = True

        def setUp(self):
            self.recognition = Recognition()

        # Test on some known videos
        def create_subjects(self):
            print "Creating some subjects"

            test_data = [
                        TestSubject.TestData(name='Kieron', user_data='user data'),
                        TestSubject.TestData(name='Katie', user_data='a lady')
            ]

            for this_test in test_data:
                print "** Testing {0} **".format(this_test.name)
                subject = self.recognition.create_subject(name=this_test.name, user_data=this_test.user_data)
                print 'created subject {name} {subject_id}'.format(name=subject['name'], subject_id=subject['subject_id'])
                self.assertIsNotNone(subject['subject_id'])

        def list_subjects(self):
            print "List all the subjects"

            subjects = self.recognition.list_subjects()

            self.assertIsNotNone(subjects)

            for subject in subjects:
                print '{0} has id {1}'.format(subject['name'], subject['subject_id'])

        def delete_subjects(self):
            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)
class TestTag(unittest.TestCase):

        class TestData:
            def __init__(self, name):
                self.name = name
                self.verbose = True

        def setUp(self):
            self.recognition = Recognition()

        def create_tags(self):
            print "Creating some watchlists"

            test_data = [
                        TestTag.TestData(name='Blacklist'),
                        TestTag.TestData(name='Whitelist'),
                        TestTag.TestData(name='Office')
            ]

            for this_test in test_data:
                print "** Testing {0} **".format(this_test.name)
                tag = self.recognition.create_tag(name=this_test.name)
                print 'created tag {name} {tag_id}'.format(name=tag['name'], tag_id=tag['watchlist_id'])
                self.assertIsNotNone(tag['tag_id'])

        def list_tags(self):
            print "List all the watchlists"

            tags = self.recognition.list_tags()

            self.assertIsNotNone(tags)

            for tag in tags:
                print '{0} has id {1}'.format(tag['name'], tag['tag_id'])

        def delete_tags(self):
            tags = self.recognition.list_tags()
            for tag in tags:
                print 'Going to delete {0}'.format(tag['tag_id'])
                deleted_id = self.recognition.delete_tag(tag['tag_id'])
                self.assertEqual(tag['tag_id'], deleted_id)
Beispiel #3
0
class TestWatchlist(unittest.TestCase):

        class TestData:
            def __init__(self, name):
                self.name = name
                self.verbose = True

        def setUp(self):
            self.recognition = Recognition()

        def create_watchlists(self):
            print "Creating some watchlists"

            test_data = [
                        TestWatchlist.TestData(name='Blacklist'),
                        TestWatchlist.TestData(name='Whitelist'),
                        TestWatchlist.TestData(name='Office')
            ]

            for this_test in test_data:
                print "** Testing {0} **".format(this_test.name)
                watchlist = self.recognition.create_watchlist(name=this_test.name)
                print 'created watchlist {name} {watchlist_id}'.format(name=watchlist['name'], watchlist_id=watchlist['watchlist_id'])
                self.assertIsNotNone(watchlist['watchlist_id'])

        def list_watchlists(self):
            print "List all the watchlists"

            watchlists = self.recognition.list_watchlists()

            self.assertIsNotNone(watchlists)

            for watchlist in watchlists:
                print '{0} has id {1}'.format(watchlist['name'], watchlist['watchlist_id'])

        def delete_watchlists(self):
            watchlists = self.recognition.list_watchlists()
            for watchlist in watchlists:
                print 'Going to delete {0}'.format(watchlist['watchlist_id'])
                deleted_id = self.recognition.delete_watchlist(watchlist['watchlist_id'])
                self.assertEqual(watchlist['watchlist_id'], deleted_id)
 def setUp(self):
     self.recognition = Recognition()
     self.face_log = FaceLog()
 def setUp(self):
     self.recognition = Recognition()
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)
Beispiel #7
0
parser.add_argument('--key-file', dest='key_file', help='use this file for your keys (otherwise defaults ~/.video)')
parser.add_argument('--name', dest='name', help='The subject name.')
parser.add_argument('--create-subject', dest='create_subject', action='store_true', help='Create subject from image.')
parser.add_argument('--delete-subjects', dest='delete_subjects', action='store_true', help='delete all subjects')
parser.add_argument('--delete-subject', dest='delete_subject', help='delete a subject with this id')
parser.add_argument('--add-sighting', dest='add_sighting', help='Add this sighting to a subject with an id')
parser.add_argument('--subject-id', dest='subject_id', help='A subject id')
parser.add_argument('--subjects', dest='subjects', action='store_true', help='List all subjects in database.')
parser.add_argument('--gender', dest='gender', default='Unknown', help='Gender of subject.')
parser.add_argument('--tag', dest='tag', default='Unknown', help='A tag name to give a subject.')
parser.add_argument('--verbose', dest='verbose', action='store_true', help='Be more verbose')
parser.add_argument('--download', dest='download', action='store_true', help='Download any results')
parser.set_defaults(download=False)
args = parser.parse_args()

recognition = Recognition(host=args.host, key_file=args.key_file, verbose=args.verbose)

# recognition on an image
if args.recognition and args.image:
    print 'Perform recognition on {}'.format(args.image)
    face_log_image = FaceLogImage(host=args.host, key_file=args.key_file, verbose=args.verbose)
    results = face_log_image.apply( image_file=args.image,
                                    download=args.download,
                                    recognition=True,
                                    min_size=80)

# recognition on a video
if args.recognition and args.video:
    print 'Perform recognition on {}'.format(args.video)
    face_log = FaceLog(host=args.host, key_file=args.key_file, verbose=args.verbose)
    results = face_log.apply( video_file=args.video,
Beispiel #8
0

parser = argparse.ArgumentParser(description='VideoAI command line tool.', epilog='Have fun using VideoAI.')
parser.add_argument('--host', dest='host', default='', help='The VideoAI host to use')
parser.add_argument('--key-file', dest='key_file', help='use this file for your keys (otherwise defaults ~/.video)')
parser.add_argument('--tags', dest='tags', action='store_true', help='List all the tags')
parser.add_argument('--tagged', dest='tagged', action='store_true', help='List all the tagged object')
parser.add_argument('--tag', dest='tag', default='Unknown', help='A tag name.')
parser.add_argument('--create', dest='create', action='store_true', help='Create a tag')
parser.add_argument('--colour', dest='colour', default='#95a5a6', help='Create a tag with this colour')
parser.add_argument('--delete', dest='delete', action='store_true', help='Delete a tag(s).')
parser.add_argument('--default', dest='default', action='store_true', help='Create a default set of tags for user')
parser.add_argument('--verbose', dest='verbose', action='store_true', help='Be more verbose')
args = parser.parse_args()

recognition = Recognition(host=args.host, key_file=args.key_file, verbose=args.verbose)

# List all tags
if args.tags:
    print "Listing all the tags"
    tags = recognition.list_tags()

# List tags
if args.tagged:
    print "Listing all the tags"
    tags = recognition.list_tagged(args.tag, args.object)

# Generic delete tag
elif args.delete:
    try:
        recognition.delete_tag(tag_name=args.tag, object_id=args.object)
Beispiel #9
0
 def setUp(self):
     self.recognition = Recognition()