我想在检测到的物体周围用边界框和文字覆盖图片。 我希望重叠显示在同一张图片,相同窗口上被检测到时出现。 不幸的是,当我运行下面的代码时,使用两张不同的Windows 10照片打开了2张图片:-(
感谢您的帮助!
这是示例代码:
image=Image.open(stream)
#show image
image.show()
imgWidth, imgHeight = image.size
draw = ImageDraw.Draw(image)
for label in labelresponse['Labels']:
for instance in label['Instances']:
box = instance['BoundingBox']
left = imgWidth * box['Left']
top = imgHeight * box['Top']
width = imgWidth * box['Width']
height = imgHeight * box['Height']
points = ((left,top),(left + width, top),(left + width, top + height),(left , top + height),(left, top))
draw.line(points, fill='#00d400', width=2)
texttobewrittent = str(label['Name'])
draw.text((left,top),texttobewrittent, color=(255, 255, 0),font=font)
#Show image with BoundingBox and Labels
image.show()