Ejemplo n.º 1
0
 def test_constructor_sets_instrumentation_key(self):
     face = Client.face('key')
     vision = Client.vision('key')
     emotion = Client.emotion('key')
     self.assertIsNotNone(face)
     self.assertIsNotNone(vision)
     self.assertIsNotNone(emotion)
Ejemplo n.º 2
0
 def test_constructor_sets_instrumentation_key(self):
     face = Client.face('key')
     vision = Client.vision('key')
     emotion = Client.emotion('key')
     self.assertIsNotNone(face)
     self.assertIsNotNone(vision)
     self.assertIsNotNone(emotion)
Ejemplo n.º 3
0
def handle_uploaded_file(file):
    client = Client.emotion(settings.OXFORD_KEY)
    recognizeResult  = client.recognize({'stream': file})

    im = Image.open(file)
    draw = ImageDraw.Draw(im)
 
    happyscore = 0

    for emotionResult in recognizeResult:
        rect = emotionResult['faceRectangle']
        x = emotionResult['faceRectangle']['left']
        y = emotionResult['faceRectangle']['top']
        x1 = emotionResult['faceRectangle']['left'] + emotionResult['faceRectangle']['width']
        y1 = emotionResult['faceRectangle']['top'] + emotionResult['faceRectangle']['height']
 
        draw.rectangle([x,y,x1,y1])

        happiness = emotionResult['scores']["happiness"]
        sadness = emotionResult['scores']["sadness"]
 
        if (happiness > sadness):
            happyscore = happyscore + 1
        else:
            happyscore = happyscore - 1
        
    modified = TemporaryFile()
    im.save(modified,'JPEG')
    return modified, happyscore
Ejemplo n.º 4
0
def handle_uploaded_file(file):
    client = Client.emotion(settings.OXFORD_KEY)
    recognizeResult = client.recognize({"stream": file})

    im = Image.open(file)
    draw = ImageDraw.Draw(im)

    happyscore = 0

    for emotionResult in recognizeResult:
        rect = emotionResult["faceRectangle"]
        x = emotionResult["faceRectangle"]["left"]
        y = emotionResult["faceRectangle"]["top"]
        x1 = emotionResult["faceRectangle"]["left"] + emotionResult["faceRectangle"]["width"]
        y1 = emotionResult["faceRectangle"]["top"] + emotionResult["faceRectangle"]["height"]

        draw.rectangle([x, y, x1, y1])

        happiness = emotionResult["scores"]["happiness"]
        sadness = emotionResult["scores"]["sadness"]

        if happiness > sadness:
            happyscore = happyscore + 1
        else:
            happyscore = happyscore - 1

    modified = TemporaryFile()
    im.save(modified, "JPEG")
    return modified, happyscore
Ejemplo n.º 5
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.emotion(os.environ["OXFORD_EMOTION_API_KEY"])

        cls.localFilePrefix = os.path.join(rootDirectory, "tests", "images")

        # set common recognize options
        cls.recognizeOptions = {"faceRectangles": ""}
Ejemplo n.º 6
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.emotion(os.environ['OXFORD_EMOTION_API_KEY'])

        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')

        # set common recognize options
        cls.recognizeOptions = {'faceRectangles': ''}
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = [];
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect({'path': os.path.join(cls.localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect({'path': os.path.join(cls.localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = []
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect(
            {'path': os.path.join(cls.localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect(
            {'path': os.path.join(cls.localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])
Ejemplo n.º 9
0
    def setUpClass(cls):
        # set up client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = [];
        localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect({'path': os.path.join(localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect({'path': os.path.join(localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])
        
        # create a person group
        cls.personGroupId = str(uuid.uuid4())
        cls.client.personGroup.create(cls.personGroupId, 'test-person-group')
Ejemplo n.º 10
0
    def setUpClass(cls):
        # set up client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = []
        localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect(
            {'path': os.path.join(localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect(
            {'path': os.path.join(localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])

        # create a person group
        cls.personGroupId = str(uuid.uuid4())
        cls.client.personGroup.create(cls.personGroupId, 'test-person-group')
Ejemplo n.º 11
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.vision(os.environ['OXFORD_VISION_API_KEY'])
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        cls.analyzeOptions = {
            'ImageType': True,
            'Color': True,
            'Faces': True,
            'Adult': True,
            'Categories': True
        }

        cls.thumbnailOptions = {
            'width': 100,
            'height': 100,
            'smartCropping': True
        }

        cls.ocrOptions = {'language': 'en', 'detectOrientation': True}
Ejemplo n.º 12
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = [];
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect({'path': os.path.join(cls.localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect({'path': os.path.join(cls.localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])

        # set common detect options
        cls.detectOptions = {
            'analyzesFaceLandmarks': True,
            'analyzesAge': True,
            'analyzesGender': True,
            'analyzesHeadPose': True
        }
Ejemplo n.º 13
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.face(os.environ['OXFORD_FACE_API_KEY'])

        # detect two faces
        cls.knownFaceIds = []
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        face1 = cls.client.detect(
            {'path': os.path.join(cls.localFilePrefix, 'face1.jpg')})
        face2 = cls.client.detect(
            {'path': os.path.join(cls.localFilePrefix, 'face2.jpg')})
        cls.knownFaceIds.append(face1[0]['faceId'])
        cls.knownFaceIds.append(face2[0]['faceId'])

        # set common detect options
        cls.detectOptions = {
            'analyzesFaceLandmarks': True,
            'analyzesAge': True,
            'analyzesGender': True,
            'analyzesHeadPose': True
        }
Ejemplo n.º 14
0
    def setUpClass(cls):
        # set up self.client for tests
        cls.client = Client.vision(os.environ['OXFORD_VISION_API_KEY'])
        cls.localFilePrefix = os.path.join(rootDirectory, 'tests', 'images')
        cls.analyzeOptions = {
            'ImageType': True,
            'Color': True,
            'Faces': True,
            'Adult': True,
            'Categories': True
        }

        cls.thumbnailOptions = {
            'width': 100,
            'height': 100,
            'smartCropping': True
        }

        cls.ocrOptions = {
            'language': 'en',
            'detectOrientation': True
        }
Ejemplo n.º 15
0
''' This program should do two things:
1. Add all of the people from the db.json into Project Oxford's API
2. Train the mlb person group 
'''
from projectoxford.Client import Client
from projectoxford.Person import Person
from projectoxford.PersonGroup import PersonGroup
import json
import time

client = Client()
faceClient = client.face('9defe6b7bd8045eea6cccb8e4b8d5ddd')
personClient = Person('9defe6b7bd8045eea6cccb8e4b8d5ddd')


def getJSONfromDB(path):  # readDB :: String -> JSON
    ''' Gets the JSON from the file at the inputted path and returns it as a string'''
    json_data = open(path).read()

    with open(path) as data_file:
        data = json.load(data_file)

    return data
    #pprint.PrettyPrinter(indent=4).pprint(data)


def addPerson(name, url,
              personGroup):  # addPerson :: String -> String -> String -> ()
    ''' Creates a person based in an inputted name and image url before adding it to the inputted personGroup in Project Oxford's API'''
    # Detect face from image
    result = faceClient.detect({'url': url})
Ejemplo n.º 16
0
 def test_face_return_throws_for_bad_request(self):
     client = Client.face('key')
     self.assertRaises(Exception, client.detect, {'url': 'http://bing.com'});
Ejemplo n.º 17
0
# This is the user running the bot
userName = '******'

# Define subreddit to troll
sub = 'whoisdat'

#####


# Define user agent
user_agent = 'User-Agent: windows:WhoDat:v0.0.1 (by /u/' + userName + ')'
# Create initial praw object
r = praw.Reddit(user_agent)
subreddit = r.get_subreddit('whoisdat')
# Configure Project Oxford API
client = Client()
faceClient = client.face(sys.argv[1]) # The API key is retrieved from the first command line argument
# This will hold all submissions that have been dealt with
submissions = []

def getAppropriateComment(result): # JSON -> JSON
    ''' Returns the appropriate comment to post given a result from Project Oxford'''
    # Name, debut date, draft date, position
    print "response \n\n"
    print result
    if result[0]['candidates'] == []:
        comment = "I couldn't figure out who this is. Sorry!"
        return comment
    else:
        conf = result[0]['candidates'][0]['confidence']
        person = faceClient.person.get('mlb', result[0]['candidates'][0]['personId'])
Ejemplo n.º 18
0
from projectoxford.Client import Client

#Face ID
faceClient = Client().face('9defe6b7bd8045eea6cccb8e4b8d5ddd')

personGroup = 'mlb'
cano = 'http://mlb.mlb.com/mlb/images/players/head_shot/429664.jpg'
canoswing = 'http://cdn.rsvlts.com/wp-content/uploads/2013/08/Robinson-Cano.jpg'
arod = 'http://cdn.blackenterprise.com/wp-content/blogs.dir/1/files/2013/04/Alex-Rodriguez-major-league-highest-salaried-players-black-enterprise.jpg'
pedro = 'http://i278.photobucket.com/albums/kk100/sillysyclone/Memorabilia_and_Sports_Cards/JorgeBonifacioandMe.jpg'

# detect faces in a second photo
detectResults = faceClient.detect({'url': pedro})
faceIds = []
for result in detectResults:
    faceIds.append(result['faceId'])

# identify any known faces from the second photo
identifyResults = faceClient.identify(personGroup, faceIds)
for result in identifyResults:
    for candidate in result['candidates']:
        confidence = candidate['confidence']
        personData = faceClient.person.get(personGroup, candidate['personId'])
        name = personData['name']
        print('identified {0} with {1}% confidence'.format(name, str(float(confidence) * 100)))

# READ BEFORE UNCOMMENTING
# removes the example person group from your subscription
# faceClient.personGroup.delete(personGroup)
Ejemplo n.º 19
0
# This is the user running the bot
userName = '******'

# Define subreddit to troll
sub = 'whoisdat'

#####

# Define user agent
user_agent = 'User-Agent: windows:WhoDat:v0.0.1 (by /u/' + userName + ')'
# Create initial praw object
r = praw.Reddit(user_agent)
subreddit = r.get_subreddit('whoisdat')
# Configure Project Oxford API
client = Client()
faceClient = client.face(
    sys.argv[1]
)  # The API key is retrieved from the first command line argument
# This will hold all submissions that have been dealt with
submissions = []


def getAppropriateComment(result):  # JSON -> JSON
    ''' Returns the appropriate comment to post given a result from Project Oxford'''
    # Name, debut date, draft date, position
    print "response \n\n"
    print result
    if result[0]['candidates'] == []:
        comment = "I couldn't figure out who this is. Sorry!"
        return comment
Ejemplo n.º 20
0
 def test_face_return_throws_for_bad_request(self):
     client = Client.face('key')
     self.assertRaises(Exception, client.detect, {'url': 'http://bing.com'})