• marclafountain

    Is there any way to make photos.capture_image() trigger the front camera rather than the back camera that it seems to default to?

    posted in Pythonista read more
  • marclafountain

    Thanks @JonB. I finally got this working. Below is my full code. I think io.BytesIO() was what i was primarily missing. That said, if you have a better way of doing this, please feel free to share.

    #Prompt user to take a photo and save to variable
    import photos
    first_img = photos.capture_image()
    
    
    #Scale down photo size and save to new variable
    import PIL
    from PIL import Image
    basewidth = 600
    img = first_img
    wpercent = (basewidth / float(img.size[0]))
    hsize = int((float(img.size[1]) * float(wpercent)))
    img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
    
    
    #Convert photo to bytes snd save to new variable
    import io
    imgByteArr = io.BytesIO()
    img.save(imgByteArr, format='PNG')
    final_img = imgByteArr.getvalue()
    
    
    #Import AWS SDK and initalize client with needed credentials
    import boto3
    client = boto3.client('rekognition')
    
    
    #Send photo to AWS for analysis
    response = client.detect_faces(
        Image={
            'Bytes': final_img,
            },
        Attributes=[
            'ALL',
        ]
    )
    
    
    #Print response for AWS API
    print(response)
    

    posted in Pythonista read more
  • marclafountain

    Hi, all. I am very new to Pythonista and somewhat new to Python. So, apologies if this is a basic question. But, Googling and searching this forum has not helped.

    I'm trying to take a photo on my iPhone via Pythonista and pass it to the AWS Rekognition API for image analysis. (I'm using the AWS Python SDK.) Taking the photo works fine. But, when I try to pass the photo to the AWS Rekognition API, I get error messages saying that I am passing an image when str, bytes, or an os.PathLike object are required.

    I have tried searching for Python code to convert the image file to bytes, but I am never successful. I still get image object errors. And, attempts to covert an image to a bytearray generated error messages that an image object isn't iterable.

    Can anyone give me pointers on how to convert a photo taken by Pythonista to bytes? Or, is there a better solution here that I'm not considering?

    Here are four different code snippets I have tried when submitting to AWS:

    with open(img, 'rb') as image:
        response = client.detect_faces(
            Image={
                'Bytes': image.read(),
            },
            Attributes=[
            'ALL',
            ]
        )
    
    with open(img, 'rb') as image:
        response = client.detect_faces(
            Image={
                'Bytes': image,
            },
            Attributes=[
            'ALL',
            ]
        )
    
    response = client.detect_faces(
        Image={
            'Bytes': image.read(),
        },
        Attributes=[
            'ALL',
            ]
        )
    
    response = client.detect_faces(
        Image={
            'Bytes': image,
        },
        Attributes=[
            'ALL',
            ]
        )
    

    My attempts to convert images to bytes have been so fruitless that I don't really have useful code to share.

    Thanks for any help!

    Marc :-)

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!