要使用Amazon Rekognition的“检测人脸”功能并且不返回所有属性,你可以使用以下代码示例:
import boto3
def detect_faces(image):
client = boto3.client('rekognition')
response = client.detect_faces(
Image={
'Bytes': image
},
Attributes=['DEFAULT'] # 只返回默认属性,不返回所有属性
)
return response['FaceDetails']
# 读取图像文件
with open('image.jpg', 'rb') as image_file:
image = image_file.read()
# 进行人脸检测
faces = detect_faces(image)
# 打印检测到的人脸数量
print('检测到的人脸数量: ' + str(len(faces)))
在上面的代码中,我们首先导入boto3库,并通过boto3.client('rekognition')创建一个Amazon Rekognition客户端。
然后,我们定义了一个detect_faces函数,它接受一个图像字节数组作为输入,并使用client.detect_faces方法来检测人脸。在Attributes参数中,我们设置为['DEFAULT'],这表示只返回默认属性,不返回所有属性。
最后,我们读取图像文件,并调用detect_faces函数来进行人脸检测。返回的结果是一个人脸属性列表,我们可以使用len()函数来获取检测到的人脸数量,然后进行打印。
请注意,为了运行上面的代码示例,你需要安装boto3库,并且已经配置了AWS凭证。
上一篇:Amazon Redshift:使用FROM关键字的用法未定义:从table_name删除。
下一篇:Amazon Rekognition detect_labels 不返回 Instances 或 Parents。