• inzel

    @cvp I get what you are asking. Sorry for the confusion...

    I have a script that uses the photos module to capture an image. I then use BytesIO to save the output as JPEG then base64 encoded so I can send it to an api. I want to figure out a way to make sure the resolution of the captured photo isnt above a certain size before I send it to the api to cut down on the filesize. I am hoping this will help with uploading the image on slower networks since it doesnt need to be that large. Since the photo is a PIL image when captured can I set it then or change it with the Images module? I have been trying to research this but am still not the greatest at code haha

    Hopefully that makes sense?

    Thanks again for the help,

    Colin

    posted in Pythonista read more
  • inzel

    Resizing would be fine as well actually. I was originally wondering if there is a way to set the size of the image when you save it but resizing afterwards would be fine too.

    Does that make sense?

    Thanks!

    posted in Pythonista read more
  • inzel

    Hello everyone,

    I am working with some facial recognition api’s and am wondering if there is a way for me to set a specific image size when using the photos module. I have been searching the docs and the forums but Im not having any luck.

    Any ideas?

    Thank you in advance,

    Colin

    posted in Pythonista read more
  • inzel

    I dont quite understand. Can you please explain the change to me?

    Edit: It does work making that change but I dont understand why its now needed. Thats what Im interested in learning about

    posted in Pythonista read more
  • inzel

    I tested itg on my phone and am getting the same results. No idea what changed here

    posted in Pythonista read more
  • inzel

    Hey JonB!

    Yes I have done that. Its really odd as this was working. Could it be because I went to the iPadOS beta?

    posted in Pythonista read more
  • inzel

    @Vincekok Thank you!

    posted in Pythonista read more
  • inzel

    I just came back to this project and I get an error!

    r = requests.post(url, data=json.dumps(values), headers = headers)

    Object of type 'bytes' is not JSON serializable

    I havent made any changes so I cant imagine why this is suddenly happening.

    Any thoughts?

    posted in Pythonista read more
  • inzel

    Is there a way to install Pythonista’s photo module in other Python environments? I cant find it with pip.

    Thanks,

    Inzel

    posted in Pythonista read more
  • inzel

    I decided to clean it up a bit and use some functions. I havent added my comments yet but here is a fully working solution:

    import photos
    import requests
    import io
    import base64
    import json
    
    img = photos.capture_image()
    
    def getPhoto():
        with io.BytesIO() as output:
            img.save(output, 'JPEG')
            contents = output.getvalue()
            image = base64.b64encode(contents)  
        return image
    
    def enrollPhoto():
        subject_id = raw_input("Hello, What is your name: ? ")
        print("Thank you " + subject_id + "." + " Analyzing...")
        image = getPhoto()
        url = "https://api.kairos.com/enroll"
        values = {
            'image': image,
            'subject_id': subject_id,
            'gallery_name': subject_id
        }
        headers = {
            'Content-Type': 'application/json',
            'app_id': '***********',
            'app_key': '****************************'
        }   
        r = requests.post(url, data=json.dumps(values), headers = headers)
        parsed_json = json.loads(r.content)
        attr = parsed_json['images'][0]['attributes']
        img.show()
        print(json.dumps(attr, indent=2))
    
    enrollPhoto()
    

    Just need to put in your actual app_id and app_key. Should work right away. My next step will be getting a simple interface built and then comparing the pic of the user to existing pics of the same user to determine whether or not they gain access. Something like that anyways. Turned out to be a fun endeavor!

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!