Exemplo n.º 1
0
def callbackSee(client, userdata, message):
	print "Topic="+message.topic
	image = camera.takePicture()
	awsUtils.copyLocalFileToS3(image)
	print "Picture uploaded"
	labels = RekognitionApi.detectLabels(reko, image)
	RekognitionUtils.printLabelsInformation(labels)
	faces = RekognitionApi.detectFaces(reko, image)
	newImage, faceCounter = RekognitionUtils.generateOutputImage(image, faces)
	faceMessage, labelMessage = RekognitionUtils.generateMessages(faceCounter, labels)
	print "Face message: " + faceMessage
	print "Label message: " + labelMessage
	PollyApi.speak(polly, faceMessage)
    	PollyApi.speak(polly, labelMessage)
	if message.payload == "tweet":
		tweet.tweet(newImage, faceMessage)
		print "Tweet sent"
Exemplo n.º 2
0
def callbackRead(client, userdata, message):
    print "Topic=" + message.topic
    print "Message=" + message.payload
    image = camera.takePicture()
    awsUtils.copyLocalFileToS3(image)
    print "Picture uploaded"
    text = RekognitionApi.detectText(reko, image)
    print text

    if message.payload.startswith("read"):
        PollyApi.speak(polly, text)
    elif message.payload.startswith("translate"):
        src_language_code = ComprehendApi.detectLanguage(comprehend, text)
        dest_language = message.payload.split(' ')[1]
        dest_language_code = language_info[dest_language]['code']
        voice = language_info[dest_language]['voice']
        print src_language_code, dest_language_code, voice
        if src_language_code == 'en' or dest_language_code == 'en':
            text = TranslateApi.translateText(translate, text,
                                              src_language_code,
                                              dest_language_code)
        else:
            text = TranslateApi.translateText(translate, text,
                                              src_language_code, 'en')
            text = TranslateApi.translateText(translate, text, 'en',
                                              dest_language_code)
        print text
        PollyApi.speak(polly, text, voice=voice)
    elif message.payload.startswith("language"):
        language_code = ComprehendApi.detectLanguage(comprehend, text)
        language = language_name[language_code]
        print language_code, language
        text = "I believe this is " + language
        PollyApi.speak(polly, text)
    else:
        print "Wrong Command, Please Enter Again"
        return

    if message.payload.endswith("tweet"):
        tweet.tweet(image, text)
        print "Tweet sent"
Exemplo n.º 3
0
def callbackSee(client, userdata, message):
    print "Topic=" + message.topic
    print "Message=" + message.payload
    image = camera.takePicture()
    if message.payload.startswith("mxnet"):
        # Detect image with MXNet
        mxnetimage = inception.load_image(image)
        prob = inception.predict(mxnetimage, model)
        topN = inception.get_top_categories(prob, synsets)
        print topN
        speech = inception.get_top1_message(topN)
        print speech
        PollyApi.speak(polly, speech)
        if message.payload.endswith("tweet"):
            tweet.tweet(image, speech)
            print "Tweet sent"
    elif message.payload.startswith("reko"):
        # Detect image with Rekognition
        awsUtils.copyLocalFileToS3(image)
        print "Picture uploaded"
        labels = RekognitionApi.detectLabels(reko, image)
        RekognitionUtils.printLabelsInformation(labels)
        faces = RekognitionApi.detectFaces(reko, image)
        celebs = RekognitionApi.detectCelebrities(reko, image)
        newImage, faceCounter = RekognitionUtils.generateOutputImage(
            image, faces)
        faceMessage, labelMessage = RekognitionUtils.generateMessages(
            faceCounter, celebs, labels)
        print "Face message: " + faceMessage
        #print "Label message: " + labelMessage
        PollyApi.speak(polly, faceMessage)
        #PollyApi.speak(polly, labelMessage)
        if message.payload.endswith("tweet"):
            tweet.tweet(newImage, faceMessage)
            print "Tweet sent"
    else:
        print "Wrong Command, Please Enter Again"
Exemplo n.º 4
0
        'Output : reko_<targetImage> (local file), displaying a box around the matched face'
    )
    print('         face information (stdout)\n')


if (len(sys.argv) != 5):
    usage()
    sys.exit()

imageBucket = str(sys.argv[1])
sourceImage = str(sys.argv[2])
targetImage = str(sys.argv[3])
copyFiles = str(sys.argv[4])

if (copyFiles == 'copy'):
    awsUtils.copyLocalFileToS3(sourceImage, imageBucket)
    awsUtils.copyLocalFileToS3(targetImage, imageBucket)

targetInfo = utils.openLocalImage(targetImage)

reko = api.connectToRekognitionService()
matchList = api.compareFaces(reko, imageBucket, sourceImage, targetImage)
faceCounter = 0
for match in matchList:
    utils.printFaceMatchInformation(match)
    face = utils.getFaceFromFaceMatch(match)
    utils.drawLinesAroundFace(targetInfo, face)
    utils.drawLegendForFace(targetInfo, face, faceCounter)
    faceCounter = faceCounter + 1

utils.saveImage(targetImage, targetInfo)
Exemplo n.º 5
0
        'nocopy        : don\'t copy the image to S3 (it\'s already there)\n')
    print(
        'Output : reko_<image> (local file), displaying a box around each detected face'
    )
    print('         labels & face information (stdout)\n')


if (len(sys.argv) != 4):
    usage()
    sys.exit()

imageBucket = str(sys.argv[1])
image = str(sys.argv[2])

if (str(sys.argv[3]) == 'copy'):
    awsUtils.copyLocalFileToS3(image, imageBucket)

imageInfo = utils.openLocalImage(image)

reko = api.connectToRekognitionService()
polly = PollyApi.connectToPolly()

labels = api.detectLabels(reko,
                          imageBucket,
                          image,
                          maxLabels=10,
                          minConfidence=70.0)
utils.printLabelsInformation(labels)

faceList = api.detectFaces(reko, imageBucket, image)
faceCounter = 0