def caption_image():
    ret = capture.image_capture_and_save(False)
    if (ret == True):
        print("Image Captured")
        image_path = './data/capture/capture.jpg'
        image_caption, confidence = img_captioning(image_path)
        print("Caption Generated : ", image_caption)
        print("Confidence : ", confidence)
        if(confidence > 0.50):
            voice(image_caption)
        else:
            voice("I didn't get the image")
            print("I didn't get the image")
    else:
        raise Exception('Image Capture Failed')
示例#2
0
def emotion_recognition():
    people_name_in_image, faces_detected_database, no_of_strangers, stranger_database, friends_database = find_who_are_in_picture(
        face_list_id)
    i = 1
    j = 1
    emotion_database = []
    emotion_detected = []
    strangers_emotion_database = []
    strangers_emotion_detected = []
    confidence = []
    stranger_confidence = []
    say = ""
    for data in friends_database:
        emotion_database.append(data['faceAttributes']['emotion'])
    print(emotion_database)
    for data in stranger_database:
        strangers_emotion_database.append(data['faceAttributes']['emotion'])
    print(strangers_emotion_database)
    for emotion in emotion_database:
        values = list(emotion.values())
        keys = list(emotion.keys())
        what_emotion = keys[values.index(max(values))]
        emotion_detected.append(what_emotion)
        confidence.append(emotion[what_emotion])
    print(emotion_detected)
    print(confidence)
    for emotion in strangers_emotion_database:
        values = list(emotion.values())
        keys = list(emotion.keys())
        what_emotion = keys[values.index(max(values))]
        strangers_emotion_detected.append(what_emotion)
        stranger_confidence.append(emotion[what_emotion])
    print(emotion_detected)
    print(confidence)
    if not people_name_in_image:
        say = "I see none of your friends."
    else:
        for idx, value in enumerate(people_name_in_image):
            if (j < len(people_name_in_image)):
                say = say + str(value) + "'s emotion is " + str(
                    emotion_detected[idx]) + " with a probability of " + str(
                        confidence[idx]) + ", "
            else:
                if (len(people_name_in_image)):
                    say = say + str(value) + "'s emotion is " + str(
                        emotion_detected[idx]
                    ) + " with a probability of " + str(confidence[idx]) + ", "
                else:
                    say = say + "and " + str(value) + "'s emotion is " + str(
                        emotion_detected[idx]
                    ) + " with a probability of " + str(confidence[idx]) + ", "
            j = j + 1
    if not no_of_strangers:
        say = say + ""
    else:
        if (no_of_strangers > 1):
            say = say + "I see some strangers. "
        else:
            say = say + "I see a stranger. "
        for idx, value in enumerate(stranger_database):
            if (i < no_of_strangers):
                say = say + "Stranger " + str(i) + "'s emotion is " + str(
                    strangers_emotion_detected[idx]
                ) + " with a probability of " + str(
                    stranger_confidence[idx]) + ", "
            else:
                say = say + "and Stranger " + str(i) + "'s emotion is " + str(
                    strangers_emotion_detected[idx]
                ) + " with a probability of " + str(stranger_confidence[idx])
            i = i + 1

    print(say)
    voice(say)
示例#3
0
def face_recognition():
    people_name_in_image, faces_detected_database, no_of_strangers, stranger_database, _ = find_who_are_in_picture(
        face_list_id)
    print(people_name_in_image)
    no_of_known_faces = len(people_name_in_image)
    say = ""
    if ((no_of_known_faces == 0) & (no_of_strangers == 0)):
        say = "I don't recognize anyone in front of you"
        print(say)
        voice(say)
    if ((no_of_known_faces != 0) & (no_of_strangers != 0)):
        say = "I see "
        i = 1
        for people in people_name_in_image:
            if (i < len(people_name_in_image)):
                say = say + str(people) + ", "
            else:
                if (len(people_name_in_image) == 1):
                    say = say + str(people)
                else:
                    say = say + " and " + str(people)
            i = i + 1

        if (no_of_strangers == 1):
            say = say + " and " + str(no_of_strangers) + " stranger. "
            say = say + "Stranger is "
            for stranger in stranger_database:
                age, gender = get_stranger_age_and_gender(stranger)
                say = say + str(gender) + ", of age " + str(age) + ". "
        else:
            say = say + "and " + str(no_of_strangers) + " strangers. "
            k = 1
            for stranger in stranger_database:
                say = say + "Stranger " + str(k) + " is "
                age, gender = get_stranger_age_and_gender(stranger)
                say = say + str(gender) + ", of age " + str(age) + ". "
                k = k + 1
        print(say)
        voice(say)

    if ((no_of_known_faces == 0) & (no_of_strangers != 0)):
        say = "I see "
        if (no_of_strangers == 1):
            say = say + "and " + str(no_of_strangers) + " stranger. "
            say = say + "Stranger is "
            for stranger in stranger_database:
                age, gender = get_stranger_age_and_gender(stranger)
                say = say + str(gender) + ", of age " + str(age) + ". "
        else:
            say = say + "and " + str(no_of_strangers) + " strangers. "
            c = 1
            for stranger in stranger_database:
                say = say + "Stranger " + str(k) + " is "
                age, gender = get_stranger_age_and_gender(stranger)
                say = say + str(gender) + ", of age " + str(age) + ". "
                c = c + 1
        print(say)
        voice(say)
    if ((no_of_known_faces != 0) & (no_of_strangers == 0)):
        say = "I see "
        t = 1
        for people in people_name_in_image:
            if (t < len(people_name_in_image)):
                say = say + str(people) + ", "
            else:
                if (len(people_name_in_image) == 1):
                    say = say + str(people)
                else:
                    say = say + " and " + str(people)
            t = t + 1
        print(say)
        voice(say)
示例#4
0
def ocr():
    analysis = ocr_decoding()
    sentence = ocr_output(analysis)
    voice(sentence)