def faceDetect(imgurl):

    imgbytes = image_helpers.get_image_from_url(imgurl)

    exp = client.detect_faces(Image={'Bytes': imgbytes}, Attributes=['ALL'])

    numfaces = len(exp['FaceDetails'])

    for facedeets in exp['FaceDetails']:

        # construct a printf (almost) style format string for printing the info
        fmtstr = '{gender} age {lowage}-{highage},'

        # mustache and beard detection
        if facedeets['Mustache']['Value'] and facedeets['Beard']['Value']:
            fmtstr += ' with beard and mustache,'
        elif facedeets['Mustache']['Value']:
            fmtstr += ' with mustache,'
        elif facedeets['Beard']['Value']:
            fmtstr += ' with beard,'

        # sunglasses/eyeglasses detection
        if facedeets['Sunglasses']['Value']:
            fmtstr += ' wearing sunglasses,'
        elif facedeets['Eyeglasses']['Value']:
            fmtstr += ' wearing glasses,'

        fmtstr += ' looks {emotion}'

        return (fmtstr.format(
            gender=facedeets['Gender']['Value'],
            lowage=facedeets['AgeRange']['Low'],
            highage=facedeets['AgeRange']['High'],
            emotion=facedeets['Emotions'][0]['Type'].lower()), numfaces)
Пример #2
0
def on_new_camera_image(evt, **kwargs):
    global processing
    global takePicture
    global detected
    if takePicture:
        if not processing:
            print('takepicture is true')
            if detected:
                print('Taking a picture of it...')
                processing = True            
                #print('Invoke OpenWhisk at ...')
                #print(datetime.datetime.now().time())
                #print(kwargs['image'].image_number)
                pilImage = kwargs['image'].raw_image
                pilImage.save("pictures/fromcozmo.jpg", "JPEG")  
                time.sleep(2)
                print('Waiting for image...')
                if upload_file('pictures/fromcozmo.jpg','ctec280'):
                    print('File uploaded successfully!') 
                # now identify image
                # grab the image from URL
                client = boto3.client('rekognition')
                imgurl = 'https://s3.amazonaws.com/ctec280/pictures/fromcozmo.jpg'
                imgbytes = image_helpers.get_image_from_url(imgurl)
                print('Sending to AWS Rekognition...')
                rekresp = client.detect_labels(Image={'Bytes': imgbytes},MinConfidence=75)
                print('Here are the results from Rekognition:')
                #pprint(rekresp)
                pprint(rekresp['Labels'])
Пример #3
0
def celeb(imgurl):
    img = image_helpers.get_image_from_url(imgurl)

    exp = client.recognize_celebrities(Image={'Bytes': img})

    try:
        Name = exp['CelebrityFaces'][0]['Name']
        Confidence = exp['CelebrityFaces'][0]['MatchConfidence']
        return "Found Celebrity is " + Name + " with confidence: " + str(
            Confidence) + " percent!"
    except:
        return ""
def faceCompare(imgtargetbytes):
    client = boto3.client('rekognition')

    # bucket = 'bucket-name'
    sourceFile = 'https://blog.njsnet.co/content/images/2017/02/trumprecognition.png'
    #targetFile = 'image/102824056.jpg'
    #targetFile = 'image/IMG_20160402_155147.jpg'
    # grab the image from local
    imgsourcebytes = image_helpers.get_image_from_url(sourceFile)
    #imgtargetbytes = image_helpers.get_image_from_url(targetFile)

    response = client.compare_faces(SimilarityThreshold=70,
                                    SourceImage={'Bytes': imgsourcebytes},
                                    TargetImage={'Bytes': imgtargetbytes})

    # for faceMatch in response['FaceMatches']:
    #     position = faceMatch['Face']['BoundingBox']
    #     confidence = str(faceMatch['Face']['Confidence'])
    #     print('The face at ' +
    #           str(position['Left']) + ' ' +
    #           str(position['Top']) +
    #           ' matches with ' + confidence + '% confidence')

    for faceMatch in response['FaceMatches']:
        if faceMatch == "":
            pprint("The face does not match")
        else:
            pprint("The face matches")
            pprint(faceMatch['Similarity'])
            pprint(faceMatch['Face']['BoundingBox'])
            img = Image.open(BytesIO(imgtargetbytes))
            (img_width, img_height) = img.size
            draw = ImageDraw.Draw(img)
            draw.rectangle(face_detect_draw.bbox_to_coords(
                faceMatch['Face']['BoundingBox'], img_width, img_height),
                           outline=(0, 200, 0))
            del draw
            img.show()
Пример #5
0
import boto3
from pprint import pprint
import image_helpers

client = boto3.client('rekognition')

imgurl = "https://thefertilechickonline.com/wp-content/uploads/2017/12/mengroup.jpg"
imgbytes = image_helpers.get_image_from_url(imgurl)

rekesp = client.detect_faces(Image={'Bytes': imgbytes}, Attributes=['ALL'])
pprint(rekesp)
print(len(rekesp['FaceDetails']))
def get_labels(imgurl):
    img = image_helpers.get_image_from_url(imgurl)

    exp = client.detect_labels(Image={'Bytes': imgbytes}, MinConfidence=50)
    return (exp['Labels'])
Пример #7
0
import boto3
import image_helpers

client = boto3.client('rekognition')

# Dummy image for testing
imgUrl = 'https://www.newreleasetoday.com/images/article_images/art_img_2608.jpg'

imgBytes = image_helpers.get_image_from_url(imgUrl)

result = client.detect_labels(Image={'Bytes': imgBytes})

print(result)