Python Forum
save parameters an data from image to csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
save parameters an data from image to csv
#1
my code goes through photos from a folder and lists their parameters (age, emotion). I only need emotion.

  So all the photos I have in my folder should be sent for analysis. The results then need to be saved in a file (preferably csv) in which one column will be the emotion that has been recognized by people (i.e. file name) and the other emotion recognized by Face API.

e.g. In the case of a photo in folder j, joy4 will look like this:

j / joy4 joy happiness (since the system recognized happiness, see appendix)

This is my code

j / joy4 joy of happiness



import requests
import os
import time
import pprint
#import csv


BASE_URL = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'
headers = {
    'Ocp-Apim-Subscription-Key': 'cccf20b44cb9445a8a4239ce324acfed',
    'Content-Type': 'application/octet-stream'
}
parameters = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,emotion'
}

def post_image(img_data):
    response = requests.post(BASE_URL, params=parameters,
                             headers=headers, data=img_data)
    try:
        return response.json()
    except:
        return None



img_path = '' #nastavit cestu ku priecinku s fotkami (napr. a, b, c)

files = os.listdir(img_path)

for file in files:
    file = os.path.join(img_path,file)
    print(file)
    img_data = open(file, 'rb').read()
    print(post_image(img_data))
    # pprint.pformat(post_image(img_data))
    time.sleep(3)
İmage
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Image to Data nikki 1 1,519 Sep-26-2020, 04:59 PM
Last Post: Larz60+
  Automating to save generated data Robotguy 3 2,229 Aug-12-2020, 03:32 PM
Last Post: Robotguy
  save my sensor data from the bme680 into a json or csv file Plastefuchs84 1 3,106 Aug-23-2019, 03:04 AM
Last Post: Plastefuchs84
  How to change the resolution of an image and save multiple plots. pianistseb 1 2,356 Dec-11-2018, 07:45 PM
Last Post: micseydel
  save video frames into pandas data-frame tofi 0 2,650 Oct-18-2018, 07:02 PM
Last Post: tofi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020