如何将Amazon AWS人脸检测返回的边界框的坐标转换为开放的Cv坐标?当亚马逊的aws只是返回边界框坐标,而不是带有围绕其面部的框的图像时。
{u'BoundingBox': {u'Height': 0.45597776770591736,
u'Left': 0.16144350171089172,
u'Top': 0.21130676567554474,
u'Width': 0.5840455889701843},}
假设这些是图像的边界框坐标。 亚马逊aws可以在脸部周围画框吗? 如果是,我在哪里可以获取python代码?
答案 0 :(得分:0)
下载已识别的图像,然后使用opencv执行以下操作
widtho = 717 #width of the given image
heighto = 562 #height of the given image
counter = 0
facecount = 1
s3 = boto3.resource('s3')
bucket = s3.Bucket('rek')
if __name__ == "__main__":
#Choosing the file in s3 bucket
photo = 'sl.jpg'
bucket = 'rek'
#Intilization of rekognition and performing detect_faces
client = boto3.client('rekognition', region_name='eu-west-1')
response = client.detect_faces(
Image={'S3Object': {'Bucket': bucket, 'Name': photo}}, Attributes=['ALL'])
print('Detected faces for ' + photo)
print('The faces are detected and labled from left to right')
for faceDetail in response['FaceDetails']:
print('Face Detected= ', i)
#To mark a bounding box of the image using coordinates
print('Bounding Box')
bboxlen = len(faceDetail['BoundingBox'])
print(bboxlen)
width = faceDetail['BoundingBox'].get('Width')
height = faceDetail['BoundingBox'].get('Height')
left = faceDetail['BoundingBox'].get('Left')
top = faceDetail['BoundingBox'].get('Top')
w = int(width * widtho)
h = int(height * heighto)
x = int(left * widtho)
y = int(top * heighto)
imagere = cv2.imread('imagename.jpg')#the image to append rects of all faces
cv2.rectangle(imagere, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imwrite('imagename.jpg', imagere)
facecount = facecount + 1
abc[:] = []