使用视觉API函数进行数据框设计吗?

问题描述

我正在使用Google API函数提取表达式,它将检测图像中的所有面孔

def detect_faces_uri(uri):
    """Detects faces in the file located in Google Cloud Storage or the web."""
    from google.cloud import vision
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri

    response = client.face_detection(image=image)
    faces = response.face_annotations

    # Names of likelihood from google.cloud.vision.enums
    likelihood_name = ('UNKNOWN','VERY_UNLIKELY','UNLIKELY','POSSIBLE','LIKELY','VERY_LIKELY')
    print('Faces:')

    for face in faces:
        print('anger: {}'.format(likelihood_name[face.anger_likelihood]))
        print('joy: {}'.format(likelihood_name[face.joy_likelihood]))
        print('surprise: {}'.format(likelihood_name[face.surprise_likelihood]))

        vertices = (['({},{})'.format(vertex.x,vertex.y)
                    for vertex in face.bounding_poly.vertices])

        print('face bounds: {}'.format(','.join(vertices)))

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages,check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))

这是我得到的输出:

Faces:
anger: VERY_UNLIKELY
joy: VERY_LIKELY
surprise: VERY_UNLIKELY
face bounds: (1077,157),(2146,1399),(1077,1399)
anger: VERY_UNLIKELY
joy: VERY_UNLIKELY
surprise: VERY_UNLIKELY
face bounds: (144,1273),(793,1844),(144,1844)
anger: VERY_UNLIKELY
joy: VERY_UNLIKELY
surprise: VERY_UNLIKELY
face bounds: (785,167),(1100,534),(785,534)

我需要对多个图像使用此功能,并且想要获取一个数据帧,但是我不确定如何将其转换为数据帧输出……我需要这样的输出:

所需的输出:

URL                   Face      Anger     Joy       Surprised
abc.com               Face1     Likely    Unlikely   Unlikely
abc.com               Face2     Unlikely  Likely    Unlikely
.

有帮助吗?

解决方法

首先启动一个新的空数据框:

#include<iostream>

#include<string>
#include<typeinfo>

int main(){
    std::string str;
    std::cout<<sizeof(nullptr)<<std::endl;
    std::cout<<typeid(str).name();
    return 0;
}

然后在打印命令旁边添加新行:

df = pd.DataFrame() 

然后将新行添加到df:

newline= pd.DataFrame({"x":[vertex.x],"y":[vertex.y]}) 

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...